Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 3ed8511

Browse files
committed
Formatting
1 parent 0716ce0 commit 3ed8511

File tree

2 files changed

+56
-57
lines changed

2 files changed

+56
-57
lines changed
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
31
using UnityEngine;
42

5-
public class ExampleWheelController : MonoBehaviour {
3+
public class ExampleWheelController : MonoBehaviour
4+
{
5+
public float acceleration;
6+
public Renderer motionVectorRenderer; // Reference to the custom motion vector renderer
67

7-
private Rigidbody rb;
8-
public float acceleration;
9-
public Renderer motionVectorRenderer; //Reference to the custom motion vector renderer
8+
Rigidbody m_Rigidbody;
109

11-
static class Uniforms
10+
static class Uniforms
1211
{
1312
internal static readonly int _MotionAmount = Shader.PropertyToID("_MotionAmount");
1413
}
1514

15+
void Start()
16+
{
17+
m_Rigidbody = GetComponent<Rigidbody>(); // Get reference to rigidbody
18+
m_Rigidbody.maxAngularVelocity = 100; // Set max velocity for rigidbody
19+
}
20+
21+
void Update()
22+
{
23+
if (Input.GetKey (KeyCode.UpArrow)) // Rotate forward
24+
m_Rigidbody.AddRelativeTorque(new Vector3(-1 * acceleration, 0, 0), ForceMode.Acceleration); // Add forward torque to mesh
25+
else if (Input.GetKey (KeyCode.DownArrow)) // Rotate backward
26+
m_Rigidbody.AddRelativeTorque(new Vector3(1 * acceleration, 0, 0), ForceMode.Acceleration); // Add backward torque to mesh
27+
28+
float m = -m_Rigidbody.angularVelocity.x / 100; // Calculate multiplier for motion vector texture
1629

17-
void Start ()
18-
{
19-
rb = GetComponent<Rigidbody> (); //Get reference to rigidbody
20-
rb.maxAngularVelocity = 100; //Set max velocity for rigidbody
21-
}
22-
23-
void Update ()
24-
{
25-
if (Input.GetKey (KeyCode.UpArrow)) //Rotate forward
26-
rb.AddRelativeTorque (new Vector3 (-1 * acceleration, 0, 0), ForceMode.Acceleration); //Add forward torque to mesh
27-
else if (Input.GetKey (KeyCode.DownArrow)) //Rotate backward
28-
rb.AddRelativeTorque (new Vector3 (1 * acceleration, 0, 0), ForceMode.Acceleration); //Add backward torque to mesh
29-
float m = -rb.angularVelocity.x / 100; //Calculate multiplier for motion vector texture
30-
if(motionVectorRenderer) //If the custom motion vector texture renderer exists
31-
motionVectorRenderer.material.SetFloat (Uniforms._MotionAmount, Mathf.Clamp(m, -0.25f, 0.25f)); //Set the multiplier on the renderer's material
32-
}
30+
if (motionVectorRenderer) // If the custom motion vector texture renderer exists
31+
motionVectorRenderer.material.SetFloat(Uniforms._MotionAmount, Mathf.Clamp(m, -0.25f, 0.25f)); // Set the multiplier on the renderer's material
32+
}
3333
}
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Shader "Post Processing/Custom Motion Vector Texture"
1+
Shader "Post Processing/Custom Motion Vector Texture"
22
{
33
Properties
44
{
@@ -25,47 +25,46 @@
2525
float4 _MotionTex_ST;
2626
float _MotionAmount;
2727

28-
struct appdata
29-
{
30-
float4 vertex : POSITION;
31-
float2 uv : TEXCOORD0;
32-
float3 normal : NORMAL;
33-
float4 tangent : TANGENT;
28+
struct appdata
29+
{
30+
float4 vertex : POSITION;
31+
float2 uv : TEXCOORD0;
32+
float3 normal : NORMAL;
33+
float4 tangent : TANGENT;
34+
};
3435

35-
};
36+
struct v2f
37+
{
38+
float2 uv : TEXCOORD0;
39+
float4 vertex : SV_POSITION;
40+
float3 normal : NORMAL;
41+
float4 tangent : TANGENT;
42+
float4 transposedTangent : TEXCOORD1;
43+
};
3644

37-
struct v2f
38-
{
39-
float2 uv : TEXCOORD0;
40-
float4 vertex : SV_POSITION;
41-
float3 normal : NORMAL;
42-
float4 tangent : TANGENT;
43-
float4 transposedTangent : TEXCOORD1;
44-
};
45-
46-
v2f vert (appdata v)
47-
{
48-
v2f o;
49-
o.vertex = UnityObjectToClipPos(v.vertex);
50-
o.uv = TRANSFORM_TEX(v.uv, _MotionTex);
51-
o.normal = mul ((float3x3)UNITY_MATRIX_MVP, v.normal);
52-
o.normal = o.normal*0.5+0.5;
53-
o.tangent = mul (UNITY_MATRIX_MV, v.tangent);
54-
o.transposedTangent = (mul (UNITY_MATRIX_IT_MV, v.tangent))*0.5+0.5;
55-
return o;
56-
}
45+
v2f vert (appdata v)
46+
{
47+
v2f o;
48+
o.vertex = UnityObjectToClipPos(v.vertex);
49+
o.uv = TRANSFORM_TEX(v.uv, _MotionTex);
50+
o.normal = mul((float3x3)UNITY_MATRIX_MVP, v.normal);
51+
o.normal = o.normal * 0.5 + 0.5;
52+
o.tangent = mul(UNITY_MATRIX_MV, v.tangent);
53+
o.transposedTangent = (mul(UNITY_MATRIX_IT_MV, v.tangent)) * 0.5 + 0.5;
54+
return o;
55+
}
5756

5857
float4 FragMotionVectors(v2f i) : SV_Target
5958
{
60-
half4 c = tex2D(_MotionTex, i.uv);
61-
c.rg = (c.rg * 2 - 1) * _MotionAmount; //Using color texture so need to make 0.5 neutral
62-
half4 t1 = i.tangent * 0.005; //sides of tire
63-
half4 t2 = c * float4(i.transposedTangent.r*2, i.transposedTangent.g*2, 0, 1); //front of tire
64-
half4 t3 = lerp(t2, t1, c.b); //Lerp between front and side of tire
59+
half4 c = tex2D(_MotionTex, i.uv);
60+
c.rg = (c.rg * 2.0 - 1.0) * _MotionAmount; // Using color texture so need to make 0.5 neutral
61+
half4 t1 = i.tangent * 0.005; // Sides of tire
62+
half4 t2 = c * float4(i.transposedTangent.r * 2.0, i.transposedTangent.g * 2.0, 0.0, 1.0); // Front of tire
63+
half4 t3 = lerp(t2, t1, c.b); // Lerp between front and side of tire
6564
return t3 * _MotionAmount;
6665
}
6766

6867
ENDCG
6968
}
7069
}
71-
}
70+
}

0 commit comments

Comments
 (0)