From 59bae3418a90fc8a05c0a58df3f76a657a693672 Mon Sep 17 00:00:00 2001 From: Sebastian Lague Date: Mon, 9 Oct 2023 15:24:39 +0200 Subject: [PATCH] Add colour to shadowed particle shader --- Assets/Scenes/Test C (3D).unity | 4 +- .../Sim 3D/Display/Particle3DSurf.shader | 81 +++++++++++++++++++ ...shader.meta => Particle3DSurf.shader.meta} | 0 .../Sim 3D/Display/ParticleShaded3D.shader | 56 ------------- 4 files changed, 83 insertions(+), 58 deletions(-) create mode 100644 Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader rename Assets/Scripts/Sim 3D/Display/{ParticleShaded3D.shader.meta => Particle3DSurf.shader.meta} (100%) delete mode 100644 Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader diff --git a/Assets/Scenes/Test C (3D).unity b/Assets/Scenes/Test C (3D).unity index dd82456..bce116b 100644 --- a/Assets/Scenes/Test C (3D).unity +++ b/Assets/Scenes/Test C (3D).unity @@ -291,7 +291,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bdfe3008efbf29745879ab1d40574478, type: 3} m_Name: m_EditorClassIdentifier: - shader: {fileID: 4800000, guid: bebe529033c51cb4f99d667ea48fa0c7, type: 3} + shader: {fileID: 4800000, guid: 638bb1bdb9b8e374e8a5cbcd595e3973, type: 3} scale: 0.05 col: {r: 0.27803493, g: 0.49487686, b: 0.8301887, a: 1} colourMap: @@ -350,11 +350,11 @@ MonoBehaviour: m_EditorClassIdentifier: numParticlesPerAxis: 35 centre: {x: 0, y: -0.47, z: 0} + size: 3.7 initialVel: x: 0 y: 0 z: 0 - size: 3.7 jitterStrength: 0.035 showSpawnBounds: 1 debug_numParticles: 42875 diff --git a/Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader b/Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader new file mode 100644 index 0000000..4d4b0f7 --- /dev/null +++ b/Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader @@ -0,0 +1,81 @@ +Shader "Instanced/Particle3DSurf" { + Properties{ + _MainTex("Albedo (RGB)", 2D) = "white" {} + _Glossiness("Smoothness", Range(0,1)) = 0.5 + _Metallic("Metallic", Range(0,1)) = 0.0 + } + SubShader{ + Tags { "RenderType" = "Opaque" } + LOD 200 + + CGPROGRAM + #pragma surface surf Standard addshadow fullforwardshadows vertex:vert + #pragma multi_compile_instancing + #pragma instancing_options procedural:setup + + sampler2D _MainTex; + + struct Input { + float2 uv_MainTex; + float4 colour; + float3 worldPos; + }; + + + #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED + StructuredBuffer Positions; + StructuredBuffer Velocities; + #endif + + + + SamplerState linear_clamp_sampler; + float velocityMax; + + float scale; + float3 colour; + + sampler2D ColourMap; + + void vert(inout appdata_full v, out Input o) + { + UNITY_INITIALIZE_OUTPUT(Input, o); + o.uv_MainTex = v.texcoord.xy; + + #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED + float speed = length(Velocities[unity_InstanceID]); + float speedT = saturate(speed / velocityMax); + float colT = speedT; + o.colour = tex2Dlod(ColourMap, float4(colT, 0.5,0,0)); + #endif + } + + void setup() + { + #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED + float3 pos = Positions[unity_InstanceID]; + + unity_ObjectToWorld._11_21_31_41 = float4(scale, 0, 0, 0); + unity_ObjectToWorld._12_22_32_42 = float4(0, scale, 0, 0); + unity_ObjectToWorld._13_23_33_43 = float4(0, 0, scale, 0); + unity_ObjectToWorld._14_24_34_44 = float4(pos, 1); + unity_WorldToObject = unity_ObjectToWorld; + unity_WorldToObject._14_24_34 *= -1; + unity_WorldToObject._11_22_33 = 1.0f / unity_WorldToObject._11_22_33; + + #endif + } + + half _Glossiness; + half _Metallic; + + void surf(Input IN, inout SurfaceOutputStandard o) { + o.Albedo = IN.colour; + o.Metallic = 0; + o.Smoothness = 0; + o.Alpha = 1; + } + ENDCG + } + FallBack "Diffuse" +} \ No newline at end of file diff --git a/Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader.meta b/Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader.meta similarity index 100% rename from Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader.meta rename to Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader.meta diff --git a/Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader b/Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader deleted file mode 100644 index 753a3c7..0000000 --- a/Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader +++ /dev/null @@ -1,56 +0,0 @@ -Shader "Instanced/ParticleShaded3D" { - Properties { - _MainTex ("Albedo (RGB)", 2D) = "white" {} - _Glossiness ("Smoothness", Range(0,1)) = 0.5 - _Metallic ("Metallic", Range(0,1)) = 0.0 - } - SubShader { - Tags { "RenderType"="Opaque" } - LOD 200 - - CGPROGRAM - #pragma surface surf Standard addshadow fullforwardshadows - #pragma multi_compile_instancing - #pragma instancing_options procedural:setup - - sampler2D _MainTex; - - struct Input { - float2 uv_MainTex; - }; - - #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED - StructuredBuffer Positions; - #endif - - float scale; - float4 colour; - - void setup() - { - #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED - float3 pos = Positions[unity_InstanceID]; - - unity_ObjectToWorld._11_21_31_41 = float4(scale, 0, 0, 0); - unity_ObjectToWorld._12_22_32_42 = float4(0, scale, 0, 0); - unity_ObjectToWorld._13_23_33_43 = float4(0, 0, scale, 0); - unity_ObjectToWorld._14_24_34_44 = float4(pos, 1); - unity_WorldToObject = unity_ObjectToWorld; - unity_WorldToObject._14_24_34 *= -1; - unity_WorldToObject._11_22_33 = 1.0f / unity_WorldToObject._11_22_33; - #endif - } - - half _Glossiness; - half _Metallic; - - void surf (Input IN, inout SurfaceOutputStandard o) { - o.Albedo = colour; - o.Metallic = 0; - o.Smoothness = 0; - o.Alpha = 1; - } - ENDCG - } - FallBack "Diffuse" -} \ No newline at end of file