Skip to content

Commit

Permalink
added arcing shader and some debug logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Cunningham committed Jan 30, 2016
1 parent dc78284 commit db2b184
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 9 deletions.
138 changes: 138 additions & 0 deletions Assets/Materials/ArcMat.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: ArcMat
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
data:
first:
name: _SrcBlend
second: 1
data:
first:
name: _DstBlend
second: 0
data:
first:
name: _Cutoff
second: 0.5
data:
first:
name: _Parallax
second: 0.02
data:
first:
name: _ZWrite
second: 1
data:
first:
name: _Glossiness
second: 0.5
data:
first:
name: _BumpScale
second: 1
data:
first:
name: _OcclusionStrength
second: 1
data:
first:
name: _DetailNormalMapScale
second: 1
data:
first:
name: _UVSec
second: 0
data:
first:
name: _Mode
second: 0
data:
first:
name: _Metallic
second: 0
m_Colors:
data:
first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
data:
first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
8 changes: 8 additions & 0 deletions Assets/Materials/ArcMat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions Assets/Scripts/ArcViz.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
using UnityEngine;

[ExecuteInEditMode]
[RequireComponent(typeof(LineRenderer))]
public class ArcViz : MonoBehaviour {
private LineRenderer _renderer;

[Range(0f, 100f)]
[Header("Debug Vars:")] [Range(0f, 100f)]
[SerializeField] private float _power = 30f;
[SerializeField] private bool _debug;

[Header("Settings:")]
[Range(0.01f, 1f)]
[SerializeField] private float _timeStep = 0.5f;
[SerializeField] private float _maxTime = 10f;

public float TimeStep {
get { return _timeStep; }
set { _timeStep = value; }
}

public float MaxTime {
get { return _maxTime; }
set { _maxTime = value; }
}

private void Awake() {
_renderer = GetComponent<LineRenderer>();
}

private void Update() {
PlotTrajectory(Vector3.zero, transform.forward * _power, _timeStep, _maxTime);
if (_debug)
DrawTrajectory(transform.position, transform.forward, _power);
}

public Vector3 PlotTrajectoryAtTime(Vector3 start, Vector3 startVelocity, float time) {
private Vector3 PlotTrajectoryAtTime(Vector3 start, Vector3 startVelocity, float time) {
return start + startVelocity * time + Physics.gravity * time * time * 0.5f;
}

public void PlotTrajectory(Vector3 start, Vector3 StartVelocity, float timeStep, float maxTime) {
private void PlotTrajectory(Vector3 start, Vector3 StartVelocity, float timeStep, float maxTime) {
var length = Mathf.RoundToInt(maxTime / timeStep);
_renderer.SetVertexCount(length + 1);

Expand All @@ -32,15 +47,19 @@ public void PlotTrajectory(Vector3 start, Vector3 StartVelocity, float timeStep,
float t = timeStep * i;
if (t > maxTime)
break;

var pos = PlotTrajectoryAtTime(start, StartVelocity, t);

if (Physics.Linecast(prev, pos))
break;

Debug.DrawLine(prev, pos, Color.red);
_renderer.SetPosition(i, pos);
prev = pos;
}
}

public void DrawTrajectory(Vector3 start, Vector3 startVelocity, float power) {
_renderer.enabled = true;
PlotTrajectory(start, startVelocity * power, TimeStep, MaxTime);
}

public void ClearTrajectory() {
_renderer.enabled = false;
}
}
9 changes: 9 additions & 0 deletions Assets/Shaders.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db2b184

Please sign in to comment.