devNotes 9-15-16 Color Pickers UI Work

fdghdfghl

 

 


Shader "Argos_Compute/Merkaba_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, 250)) = 60
        }

            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
            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  size;
            //float  age;
            //float  normAge;
            //int    type;

        };

        StructuredBuffer<Particle>  particles;

        // Variables from the properties.
        float4 _LowColor;
        float4 _MidColor;
        float4 _HighColor;
        float _colorSwitch;
        float _LowMidThresh;
        float _MidHighThresh;

        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;
            float4 color            : COLOR;
            //float size : TEXCOORD0;
            //float age : TEXCOORD1;
            //float type : TEXCOORD2;
        };
        //--------------------------------------------------------------------------------
        struct PS_INPUT
        {
            float4 position         : SV_POSITION;
            float2 texcoords        : TEXCOORD0;
            float4 color            : COLOR;
            //float size : TEXCOORD1;
            //float age : TEXCOORD2;
            //float type : TEXCOORD3;
        };
        //--------------------------------------------------------------------------------
        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 = length(particles[input.vertexid].velocity);

            float lerpValue1 = clamp((speed / _colorSwitch)/_LowMidThresh, 0, 1);
            //output.color = lerp(_LowColor, _MidColor, lerpValue);
            
            color_mid = lerp(_LowColor, _MidColor, lerpValue1);
            float lerpValue2 = clamp((speed / _colorSwitch) / _MidHighThresh, 0, 1);
            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;
            //float4 pos = mul(UNITY_MATRIX_MVP, p[0].position);
            float scl = 20;
            
            float4 v[4];

            float3 A, B, C, D;
            float4 a, b, c, d;

            float3 E, F, G, H;
            float4 e, f, g, h;

            A = _particleSize*float3(0, 0.612, 0);
            B = _particleSize*float3(0.5, -0.204, -0.288);
            C = _particleSize*float3(0, -0.204, 0.578);
            D = _particleSize*float3(-0.5, -0.204, -0.288);

            E = _particleSize*float3(0, -0.612, 0);
            F = _particleSize*float3(-0.5, 0.204, 0.288);
            G = _particleSize*float3(0, 0.204, -0.578);
            H = _particleSize*float3(0.5, 0.204, 0.288);

            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);

            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]);

            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 = 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 = d;
            pIn.texcoords = float2(0.0f, 0.0f);
            pIn.color = col;
            triStream.Append(pIn);

            triStream.RestartStrip();

            pIn.position = a;
            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 = b;
            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 = d;
            pIn.texcoords = float2(0.0f, 0.0f);
            pIn.color = col;
            triStream.Append(pIn);

            triStream.RestartStrip();

            v[0] = pos + float4(E.x, E.y, E.z, 1);
            v[1] = pos + float4(F.x, F.y, F.z, 1);
            v[2] = pos + float4(G.x, G.y, G.z, 1);
            v[3] = pos + float4(H.x, H.y, H.z, 1);

            e = mul(UNITY_MATRIX_MVP, v[0]);
            f = mul(UNITY_MATRIX_MVP, v[1]);
            g = mul(UNITY_MATRIX_MVP, v[2]);
            h = mul(UNITY_MATRIX_MVP, v[3]);

            pIn.position = e;                          //a-e b-f c-g d-h
            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 = f;
            pIn.texcoords = float2(0.0f, 0.0f);
            pIn.color = col;
            triStream.Append(pIn);

            triStream.RestartStrip();

            pIn.position = e;                           //a-e b-f c-g d-h
            pIn.texcoords = float2(0.0f, 1.0f);
            pIn.color = col;
            triStream.Append(pIn);

            pIn.position = f;
            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();

            pIn.position = e;                           //a-e b-f c-g d-h
            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();

            pIn.position = f;                           //a-e b-f c-g d-h
            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
        }
    }
}

        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 = length(particles[input.vertexid].velocity);
            
            _LowMidThresh;
            _MidHighThresh;
            
            float lerpValue1 = clamp((speed / _colorSwitch)/_LowMidThresh, 0, 1);
            color_mid = lerp(_LowColor, _MidColor, lerpValue);
            float lerpValue2 = clamp((speed / _colorSwitch) / _MidHighThresh, 0, 1));
            output.color = lerp(color_mid, _HighColor, lerpValue);

            return output;
        }
        GS_INPUT VSMAIN(in VS_INPUT input)
        {
            GS_INPUT output;

            output.position.xyz = particles[input.vertexid].position;
            output.position.w = 1.0;
            float speed = length(particles[input.vertexid].velocity);
            float lerpValue = clamp(speed / _colorSwitch, 0, 1);
            output.color = lerp(_Color, _SpeedColor, lerpValue);

            //output.age = particles[input.vertexid].normAge;
            //output.size = particles[input.vertexid].size;
            //output.type = particles[input.vertexid].type;
            return output;
        }

 

fghnfhgn1