每个顶点的HLSL片段着色器颜色不同?

时间:2016-03-15 11:06:54

标签: shader hlsl fragment-shader

我可以为这个着色器的每个顶点实例制作不同的颜色吗?我是否必须将实例发送到o.output到frag颜色?这是运行 Graphics.DrawProcedural(MeshTopology.LineStrip)的HLSL的Unity3d实现;

        #pragma fragment frag
        #include "UnityCG.cginc"

                StructuredBuffer<float3> buf_Points;
                StructuredBuffer<float3> buf_Positions;

                struct ps_input {
                    float4 pos : SV_POSITION;
                };

                ps_input vert (uint id : SV_VertexID, uint inst : SV_InstanceID)
                {
                    ps_input o;
                    float3 worldPos = buf_Points[id] + buf_Positions[inst];
                    o.pos = mul (UNITY_MATRIX_VP, float4(worldPos,1.0f));
                    return o;
                }

                float4 frag (ps_input i) : COLOR
                {
                    return float4(1,0,0,1); 
                }

                ENDCG

1 个答案:

答案 0 :(得分:0)

我解决了,这是类似的东西:

1