123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- Shader /*ase_name*/"Hidden/Templates/CustomRTUpdate"/*end*/
- {
- Properties
- {
- /*ase_props*/
- }
- SubShader
- {
- Tags { }
- /*ase_all_modules*/
- /*ase_pass*/
- Pass
- {
- Name "Custom RT Update"
- CGPROGRAM
- #include "UnityCustomRenderTexture.cginc"
- #pragma vertex ASECustomRenderTextureVertexShader
- #pragma fragment frag
- #pragma target 3.5
- /*ase_pragma*/
- struct ase_appdata_customrendertexture
- {
- uint vertexID : SV_VertexID;
- /*ase_vdata:*/
- };
- struct ase_v2f_customrendertexture
- {
- float4 vertex : SV_POSITION;
- float3 localTexcoord : TEXCOORD0; // Texcoord local to the update zone (== globalTexcoord if no partial update zone is specified)
- float3 globalTexcoord : TEXCOORD1; // Texcoord relative to the complete custom texture
- uint primitiveID : TEXCOORD2; // Index of the update zone (correspond to the index in the updateZones of the Custom Texture)
- float3 direction : TEXCOORD3; // For cube textures, direction of the pixel being rendered in the cubemap
- /*ase_interp(4,):sp=sp.xyzw;uv0=tc0;uv1=tc1;uv2=tc2;uv3=tc3*/
- };
- /*ase_globals*/
- ase_v2f_customrendertexture ASECustomRenderTextureVertexShader(ase_appdata_customrendertexture IN /*ase_vert_input*/ )
- {
- ase_v2f_customrendertexture OUT;
- /*ase_vert_code:IN=ase_appdata_customrendertexture;OUT=ase_v2f_customrendertexture*/
- #if UNITY_UV_STARTS_AT_TOP
- const float2 vertexPositions[6] =
- {
- { -1.0f, 1.0f },
- { -1.0f, -1.0f },
- { 1.0f, -1.0f },
- { 1.0f, 1.0f },
- { -1.0f, 1.0f },
- { 1.0f, -1.0f }
- };
- const float2 texCoords[6] =
- {
- { 0.0f, 0.0f },
- { 0.0f, 1.0f },
- { 1.0f, 1.0f },
- { 1.0f, 0.0f },
- { 0.0f, 0.0f },
- { 1.0f, 1.0f }
- };
- #else
- const float2 vertexPositions[6] =
- {
- { 1.0f, 1.0f },
- { -1.0f, -1.0f },
- { -1.0f, 1.0f },
- { -1.0f, -1.0f },
- { 1.0f, 1.0f },
- { 1.0f, -1.0f }
- };
- const float2 texCoords[6] =
- {
- { 1.0f, 1.0f },
- { 0.0f, 0.0f },
- { 0.0f, 1.0f },
- { 0.0f, 0.0f },
- { 1.0f, 1.0f },
- { 1.0f, 0.0f }
- };
- #endif
- uint primitiveID = IN.vertexID / 6;
- uint vertexID = IN.vertexID % 6;
- float3 updateZoneCenter = CustomRenderTextureCenters[primitiveID].xyz;
- float3 updateZoneSize = CustomRenderTextureSizesAndRotations[primitiveID].xyz;
- float rotation = CustomRenderTextureSizesAndRotations[primitiveID].w * UNITY_PI / 180.0f;
- #if !UNITY_UV_STARTS_AT_TOP
- rotation = -rotation;
- #endif
- // Normalize rect if needed
- if (CustomRenderTextureUpdateSpace > 0.0) // Pixel space
- {
- // Normalize xy because we need it in clip space.
- updateZoneCenter.xy /= _CustomRenderTextureInfo.xy;
- updateZoneSize.xy /= _CustomRenderTextureInfo.xy;
- }
- else // normalized space
- {
- // Un-normalize depth because we need actual slice index for culling
- updateZoneCenter.z *= _CustomRenderTextureInfo.z;
- updateZoneSize.z *= _CustomRenderTextureInfo.z;
- }
- // Compute rotation
- // Compute quad vertex position
- float2 clipSpaceCenter = updateZoneCenter.xy * 2.0 - 1.0;
- float2 pos = vertexPositions[vertexID] * updateZoneSize.xy;
- pos = CustomRenderTextureRotate2D(pos, rotation);
- pos.x += clipSpaceCenter.x;
- #if UNITY_UV_STARTS_AT_TOP
- pos.y += clipSpaceCenter.y;
- #else
- pos.y -= clipSpaceCenter.y;
- #endif
- // For 3D texture, cull quads outside of the update zone
- // This is neeeded in additional to the preliminary minSlice/maxSlice done on the CPU because update zones can be disjointed.
- // ie: slices [1..5] and [10..15] for two differents zones so we need to cull out slices 0 and [6..9]
- if (CustomRenderTextureIs3D > 0.0)
- {
- int minSlice = (int)(updateZoneCenter.z - updateZoneSize.z * 0.5);
- int maxSlice = minSlice + (int)updateZoneSize.z;
- if (_CustomRenderTexture3DSlice < minSlice || _CustomRenderTexture3DSlice >= maxSlice)
- {
- pos.xy = float2(1000.0, 1000.0); // Vertex outside of ncs
- }
- }
- OUT.vertex = float4(pos, 0.0, 1.0);
- OUT.primitiveID = asuint(CustomRenderTexturePrimitiveIDs[primitiveID]);
- OUT.localTexcoord = float3(texCoords[vertexID], CustomRenderTexture3DTexcoordW);
- OUT.globalTexcoord = float3(pos.xy * 0.5 + 0.5, CustomRenderTexture3DTexcoordW);
- #if UNITY_UV_STARTS_AT_TOP
- OUT.globalTexcoord.y = 1.0 - OUT.globalTexcoord.y;
- #endif
- OUT.direction = CustomRenderTextureComputeCubeDirection(OUT.globalTexcoord.xy);
- return OUT;
- }
- float4 frag(ase_v2f_customrendertexture IN /*ase_frag_input*/) : COLOR
- {
- float4 finalColor;
- /*ase_frag_code:IN=ase_v2f_customrendertexture*/
- finalColor = /*ase_frag_out:Frag Color;Float4*/float4(1,1,1,1)/*end*/;
- return finalColor;
- }
- ENDCG
- }
- }
- }
|