Skip to content

Commit

Permalink
Add colour to shadowed particle shader
Browse files Browse the repository at this point in the history
  • Loading branch information
SebLague committed Oct 9, 2023
1 parent f9dd346 commit 59bae34
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Assets/Scenes/Test C (3D).unity
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions Assets/Scripts/Sim 3D/Display/Particle3DSurf.shader
Original file line number Diff line number Diff line change
@@ -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<float3> Positions;
StructuredBuffer<float3> 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"
}
56 changes: 0 additions & 56 deletions Assets/Scripts/Sim 3D/Display/ParticleShaded3D.shader

This file was deleted.

0 comments on commit 59bae34

Please sign in to comment.