Last active
February 20, 2025 07:35
-
-
Save pema99/8b385ae6cef2736f4dea2fd6d4ead01c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/ScreenVertPos" | |
{ | |
Properties | |
{ | |
[IntRange] _Width ("Texture Size (POT)", Range(0, 13)) = 7 | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma geometry geom | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 color : COLOR; | |
}; | |
uint _Width; | |
v2f vert (float4 vertex : POSITION) | |
{ | |
v2f o; | |
o.vertex = vertex; | |
o.color = 0; | |
return o; | |
} | |
[maxvertexcount(12)] | |
void geom(triangle v2f input[3], inout TriangleStream<v2f> triStream, uint triID : SV_PrimitiveId) | |
{ | |
float width = 1 << _Width; | |
float2 quadSize = float2(2.0 / width, 0); | |
for (uint i = 0; i < 3; i++) | |
{ | |
uint id = triID * 3 + i; | |
uint2 coord = uint2(id % width, id / width); | |
float3 pos = float3(((coord.xy / width) - 0.5) * 2.0, 0); | |
v2f o; | |
o.color = input[i].vertex; | |
o.vertex = float4(pos + quadSize.xxy, 1); | |
triStream.Append(o); | |
o.vertex = float4(pos + quadSize.yxy, 1); | |
triStream.Append(o); | |
o.vertex = float4(pos + quadSize.xyy, 1); | |
triStream.Append(o); | |
o.vertex = float4(pos + quadSize.yyy, 1); | |
triStream.Append(o); | |
triStream.RestartStrip(); | |
} | |
} | |
float4 frag (v2f i) : SV_Target | |
{ | |
return float4(i.color, 1.0); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment