//—————-
Shader "Argos_Compute/CUBE_Lerp_Banned_Emitter"
{
Properties
{
_ParticleTexture("Diffuse Tex", 2D) = "white" {}
_LowColor("Low Color", Color) = (0, 1, 1,0.3)
_MidColor("Mid Color", Color) = (1, 0, 0, 0.3)
_HighColor("High Color", Color) = (0,0,1,0.3)
_LowMidThresh("LowMidThresh", Range(0,1)) = 0.3
_MidHighThresh("MidHighThresh", Range(0,1)) = 0.6
_colorSwitch("Switch", Range(0, 700)) = 60
_nPerc("nPerc", Range(0, 1)) = 0.05
_ARG_SrcMode("SrcMode", Float) = 0
_ARG_DstMode("DstMode", Float) = 0
}
SubShader
{
Pass
{
//Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency
//Blend One OneMinusSrcAlpha // Premultiplied transparency
//Blend One One // Additive
//Blend OneMinusDstColor One // Soft Additive
//Blend DstColor Zero // Multiplicative
//Blend DstColor SrcColor // 2x Multiplicative
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
//Blend SrcAlpha One
Blend[_ARG_SrcMode][_ARG_DstMode]
Cull Off
Lighting Off
ZWrite Off
Fog{ Color(0,0,0,0) }
CGPROGRAM
#pragma target 5.0
#pragma vertex VSMAIN
#pragma fragment PSMAIN
#pragma geometry GSMAIN
#include "UnityCG.cginc"
struct Particle
{
//int index;
float3 position;
float3 velocity;
float speed;
float3 dV_nTangent;
float dV_nTangent_Mag;
float3 width_nAxis;
};
StructuredBuffer<Particle> particles;
// Variables from the properties.
float4 _LowColor;
float4 _MidColor;
float4 _HighColor;
float _colorSwitch;
float _LowMidThresh;
float _MidHighThresh;
float _nPerc; //nPercent of _colorSwitch velocity
float _Length;
float _Width;
float _Height;
Texture2D _ParticleTexture;
SamplerState sampler_ParticleTexture;
Texture2D _Ramp1Texture;
SamplerState sampler_Ramp1Texture;
float3 _worldPos;
float _particleSize;
float maxAge;
float maxRad;
struct VS_INPUT
{
uint vertexid : SV_VertexID;
};
//--------------------------------------------------------------------------------
struct GS_INPUT
{
float4 position : SV_POSITION;
float3 dir_L : TEXCOORD0;
float3 dir_W : TEXCOORD1;
float3 dir_H : TEXCOORD2;
float4 color : COLOR;
};
//--------------------------------------------------------------------------------
struct PS_INPUT
{
float4 position : SV_POSITION;
float2 texcoords : TEXCOORD0;
float4 color : COLOR;
};
//--------------------------------------------------------------------------------
GS_INPUT VSMAIN(in VS_INPUT input)
{
GS_INPUT output;
float4 color_mid;
output.position.xyz = particles[input.vertexid].position;
output.position.w = 1.0;
float speed = particles[input.vertexid].speed;
float lerpValue1 = clamp((speed - _colorSwitch*(_LowMidThresh - _nPerc / 2)) / (_colorSwitch*_nPerc), 0, 1);
float lerpValue2 = clamp((speed - _colorSwitch*(_MidHighThresh - _nPerc / 2)) / (_colorSwitch*_nPerc), 0, 1);
float3 vRt;
float3 vUp;
float3 vIn;
vRt.x = 1; vRt.y = 0; vRt.z = 0;
vUp.x = 0; vUp.y = 1; vUp.z = 0;
vIn.x = 0; vIn.y = 0; vIn.z = 1;
output.dir_L.xyz = lerp(vIn, normalize(particles[input.vertexid].velocity), lerpValue1);
output.dir_W.xyz = lerp(vRt, particles[input.vertexid].width_nAxis, lerpValue1);
output.dir_H.xyz = lerp(vIn, particles[input.vertexid].dV_nTangent, lerpValue1);
color_mid = lerp(_LowColor, _MidColor, lerpValue1);
output.color = lerp(color_mid, _HighColor, lerpValue2);
return output;
}
// Dimensions
// Length of tetrahedron edge : a.
// The height of an regular tetrahedron :
// h = sqrt(2 / 3) * a;
// The radius of circumsphere :
// R = sqrt(3 / 8) * a;
// The height of the incenter O or
// the radius of the insphere :
// r = 1 / 3 * R or r = 1 / sqrt(24) * a;
// The radius of midsphere(tangent to edges) :
// rm = 1 / sqrt(8) * a;
// The angle between two faces : ~70, 53 (yellow)
// Angle(C, MAB, D) = degrees(atan(2 * sqrt(2)));
// The angle between an edge and a face : ~54, 74 (green)
// Angle(0, A, D) = degrees(atan(sqrt(2)));
// The angle vertex - center - vertex: ~109.471 (violet)
// Angle(A, 0, D) = degrees(acos(-1 / 3));
//void make_face(float3 a, float3 b, float3 c)
//{
// float3 face_normal = normalize(cross(c - a, c - b));
// EmitVertex();
// gl_Position = mvpMatrix * vec4(b, 1.0);
// color = face_color;
// EmitVertex();
// gl_Position = mvpMatrix * vec4(c, 1.0);
// color = face_color;
// EmitVertex();
// EndPrimitive();
//}
//--------------------------------------------------------------------------------
[maxvertexcount(24)]
void GSMAIN(point GS_INPUT p[1], inout TriangleStream<PS_INPUT> triStream)
{
PS_INPUT pIn;
float4 pos = p[0].position*2;//TODO FIND OUT WHY *2
pos.w = 1;
float4 col = p[0].color;
float3 Len = p[0].dir_L*_Length;
float3 Wid = p[0].dir_W*_Width;
float3 Hgt = p[0].dir_H*_Height;
float4 v[8];
float3 A, B, C, D, E, F, G, H;
float4 a, b, c, d, e, f, g, h;
A = _particleSize*( Wid + Hgt + Len);
B = _particleSize*(-Wid + Hgt + Len);
C = _particleSize*( Wid + Hgt - Len);
D = _particleSize*(-Wid + Hgt - Len);
E = _particleSize*( Wid -Hgt + Len);
F = _particleSize*(-Wid -Hgt + Len);
G = _particleSize*( Wid -Hgt - Len);
H = _particleSize*(-Wid -Hgt - Len);
v[0] = pos + float4(A.x, A.y, A.z, 1);
v[1] = pos + float4(B.x, B.y, B.z, 1);
v[2] = pos + float4(C.x, C.y, C.z, 1);
v[3] = pos + float4(D.x, D.y, D.z, 1);
v[4] = pos + float4(E.x, E.y, E.z, 1);
v[5] = pos + float4(F.x, F.y, F.z, 1);
v[6] = pos + float4(G.x, G.y, G.z, 1);
v[7] = pos + float4(H.x, H.y, H.z, 1);
a = mul(UNITY_MATRIX_MVP, v[0]);
b = mul(UNITY_MATRIX_MVP, v[1]);
c = mul(UNITY_MATRIX_MVP, v[2]);
d = mul(UNITY_MATRIX_MVP, v[3]);
e = mul(UNITY_MATRIX_MVP, v[4]);
f = mul(UNITY_MATRIX_MVP, v[5]);
g = mul(UNITY_MATRIX_MVP, v[6]);
h = mul(UNITY_MATRIX_MVP, v[7]);//DO NORMALS NEXT
//TOP
pIn.position = a;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = c;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = b;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = c;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = d;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = b;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
//Bot
pIn.position = f;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = g;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = e;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = f;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = h;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = g;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
/////////
//Front
pIn.position = e;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = c;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = a;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = e;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = g;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = c;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
//Back
pIn.position = f;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = b;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = d;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = f;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = d;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = h;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
/////////
//RIGHT
pIn.position = a;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = b;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = e;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = e;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = b;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = f;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
//Left
pIn.position = h;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = d;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = c;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
pIn.position = c;
pIn.texcoords = float2(0.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = g;
pIn.texcoords = float2(1.0f, 1.0f);
pIn.color = col;
triStream.Append(pIn);
pIn.position = h;
pIn.texcoords = float2(0.0f, 0.0f);
pIn.color = col;
triStream.Append(pIn);
triStream.RestartStrip();
//ref
//pIn.size = p[0].size;
//pIn.age = p[0].age;
//pIn.type = p[0].type;
}
//--------------------------------------------------------------------------------
float4 PSMAIN(in PS_INPUT input) : COLOR
{
float4 col = input.color;
float4 color = _ParticleTexture.Sample(sampler_ParticleTexture, input.texcoords);
color *= col;
return color;
}
//--------------------------------------------------------------------------------
ENDCG
}
}
}

