Skip to content

Commit

Permalink
Static color option, parameter editing improvevents
Browse files Browse the repository at this point in the history
  • Loading branch information
lukis101 committed Jul 27, 2018
1 parent 7232dba commit 6ee985f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
16 changes: 8 additions & 8 deletions sh_PCloud_Main.shader
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Properties
{
[NoScaleOffset]
_Buffer ("Buffer", 2D) = "gray" {}
_Rst ("Reset", Int) = 0
_Str ("Strength", Range(-5.0, 5.0)) = 1.0000
[Toggle] _Rst ("Reset", Float) = 0
_Drag ("Drag", Range( 0.0, 3.0)) = 0.5
_Nstr ("Noise", Range( 0.0, 1.0)) = 0.5
_Fdecay_l ("Force decay: linear", Range( 0.0, 1.0)) = 0.15
_Fdecay_q ("Force decay: quadratic", Range( 0.0, 1.0)) = 0.25
[Header(Manipulation force)]
_Str ("Strength", Range(-5.0, 5.0)) = 1.0000
_Fdecay_l ("Decay: linear", Range( 0.0, 1.0)) = 0.15
_Fdecay_q ("Decay: quadratic", Range( 0.0, 1.0)) = 0.25
}
SubShader
{
Expand Down Expand Up @@ -37,8 +38,7 @@ SubShader

Texture2D<float4> _Buffer;

int _Rst;
int _Stage;
float _Rst;
float _Str;
float _Drag;
float _Nstr;
Expand Down Expand Up @@ -80,8 +80,8 @@ SubShader
if (i.uv.x < 0.5)
return EncodeColor(float4(manips[0].x+i.uv.x*WIDTH*2-WIDTH/2,
manips[0].y+i.uv.y*WIDTH-WIDTH/2, manips[0].z, 0));
else // no velocity
return EncodeColor(float4(0,0,0,0));
else // a bit of velocity for angle-based color mode
return EncodeColor(float4(-0.01,0.001,0,0));
}

// TODO: interleave pos+velocity: data locality and no need to use resolution constant
Expand Down
27 changes: 19 additions & 8 deletions sh_PCloud_Mesh.shader
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Properties
_Buffer ("Particle buffer", 2D) = "gray" {}
[NoScaleOffset] // TODO: support this
_MainTex ("Particle texture", 2D) = "white" {}
_Size ("Size", Range(0., 1.)) = 0.1
_Segments ("Mesh divisions", Range(1., 32.)) = 1.0
_Factor ("Subdivisions", Range(1., 64.)) = 4.0
_Glow ("Glow", Range(0., 1.7)) = 1.0
_Size ("Size", Range(0., 1.)) = 0.3
[Header(Mesh and texture setup)]
[IntRange] _Segments ("Mesh divisions", Range(1, 32)) = 1
[IntRange] _Factor ("Subdivisions", Range(1, 64)) = 4
[Header(Particle colors)]
[KeywordEnum(Angle, Static)]
_ColMode ("Color mode", Float) = 0
_SColor ("Static Color", Color) = (1.,1.,1.,1.)
_Brightness ("Brightness", Range(0., 1.7)) = 1.0
}
SubShader
{
Expand All @@ -29,6 +34,7 @@ SubShader
#pragma domain doma
#pragma geometry geom
#pragma fragment frag
#pragma multi_compile _COLMODE_ANGLE _COLMODE_STATIC

#include "UnityCG.cginc"
#include "PCloud_Util.cginc"
Expand All @@ -39,7 +45,8 @@ SubShader
uniform float _Size;
uniform float _Segments;
uniform float _Factor;
uniform float _Glow;
uniform float _Brightness;
uniform float4 _SColor;

struct vs_in
{
Expand Down Expand Up @@ -68,7 +75,7 @@ SubShader

struct PatchConstData
{
float edges[4] : SV_TessFactor;
float edges[4] : SV_TessFactor;
float inside[2] : SV_InsideTessFactor;
};

Expand Down Expand Up @@ -145,14 +152,18 @@ SubShader
float3 wpos = state_pos.xyz;

// Coloring
#ifdef _COLMODE_ANGLE
static const float PI = 3.14159265f;
float angle_xy = (atan2(state_vel.x, state_vel.z)+PI)/(2*PI);
float angle_yz = (atan2(state_vel.y, state_vel.z)+PI)/(2*PI);
float angsum = angle_xy+angle_yz;
if (angsum > 1.0) angsum -= 1.0;
o.col = float4(HUEtoRGB(angsum), 1); // TODO
o.col = float4(HUEtoRGB(angsum), 1);
// (Optional)Reduce color strengh - lessens saturation from additive blending with high particle density
o.col = normalize(o.col); // Should probably do simple mult for performance...
#elif _COLMODE_STATIC
o.col = _SColor;
#endif

// Generate billboard triangle
float3 right = UNITY_MATRIX_V._m00_m01_m02;
Expand Down Expand Up @@ -187,7 +198,7 @@ SubShader
{
fixed4 tex = _MainTex.SampleLevel(sampler_MainTex, i.uv, 0);
fixed4 colored = i.col*tex;
return fixed4(colored.rgb*(colored.a*_Glow), colored.a);
return fixed4(colored.rgb*(colored.a*_Brightness), colored.a);
}
ENDCG
}
Expand Down

0 comments on commit 6ee985f

Please sign in to comment.