【问题标题】:HLSL fragment shader different color for every vertex?HLSL片段着色器每个顶点的颜色不同?
【发布时间】:2016-03-15 19:45:43
【问题描述】:

我可以为这个着色器的每个顶点实例制作不同的颜色吗?我必须将实例发送到 o.output 到碎片颜色吗?这是运行 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

【问题讨论】:

    标签: shader hlsl fragment-shader


    【解决方案1】:

    我解决了,就是这样的:

            struct ps_input {
                float4 pos : SV_POSITION ;
                float4 col : COLOR;
            };
    
            ps_input vert (uint id : SV_VertexID, uint inst : SV_InstanceID)
            {
                 bla 
    
                o.pos = mul (UNITY_MATRIX_VP, float4(worldPos,1.0f));
                o.col = float4(sin(inst),0,0,1);
                return o;
            }
    
            float4 frag (ps_input i) : COLOR
            {
                return i.col;//float4(0.7f,.7f,.7f,1);
            }
    
            ENDCG
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      • 2017-09-19
      • 2021-01-02
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多