Hey folks…
I’m playing with the structured buffer shaders. Cool stuff, but I can’t get something to work…
Here is a simple shader that draws multiple squares at different positions.
Shader "Custom/TestShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
}
SubShader {
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
StructuredBuffer<float> buffer;
float4 _Color;
struct ps_input {
float4 pos : SV_POSITION;
float4 col : COLOR0;
};
ps_input vert(uint id : SV_VertexID, uint inst : SV_InstanceID) {
ps_input o;
float3 worldPos = float3(buffer[inst],buffer[inst],0);
[branch] switch (id) {
case 0: worldPos = worldPos + float3(-0.5,-0.5,0); break;
case 1: worldPos = worldPos + float3(-0.5,0.5,0); break;
case 2: worldPos = worldPos + float3(0.5,-0.5,0); break;
case 3: worldPos = worldPos + float3(-0.5,0.5,0); break;
case 4: worldPos = worldPos + float3(0.5,0.5,0); break;
case 5: worldPos = worldPos + float3(0.5,-0.5,0); break;
};
o.pos = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0f));
o.col = _Color;
return o;
}
// Pixel function returns a solid color for each point.
float4 frag(ps_input i) : COLOR{
return i.col;
}
ENDCG
}
}
FallBack Off
}
If I place an (semi-transparent)object in front of this squares, the squares are always visible at its full color.
Squares don’t get dimmed. I have my Render Queues set correctly.
Does anybody have any suggestions?
Thanks…