.idea
Assets
AmplifyShaderEditor
Plugins
Editor
EditorResources
GUISkins
Nodes
Previews
ShaderFunctions
ShaderLibrary
Shaders
Templates
CustomRT
CustomRTInit.shader
CustomRTInit.shader.meta
CustomRTUpdate.shader
CustomRTUpdate.shader.meta
Legacy
UI
URP
CustomRT.meta
HDRP 10x.unitypackage.meta
HDRP 12x.unitypackage.meta
HDRP 14x.unitypackage.meta
HDRP 15x.unitypackage.meta
HDRP 16x.unitypackage.meta
HDRP 17x.unitypackage.meta
Legacy.meta
UI.meta
URP 10x.unitypackage.meta
URP 12x.unitypackage.meta
URP 14x.unitypackage.meta
URP 15x.unitypackage.meta
URP 16x.unitypackage.meta
URP 17x.unitypackage.meta
URP.meta
Textures
UI
GUISkins.meta
Nodes.meta
Previews.meta
ShaderFunctions.meta
ShaderLibrary.meta
Shaders.meta
Templates.meta
Textures.meta
UI.meta
Editor.meta
EditorResources.meta
AmplifyShaderEditor.asmdef
AmplifyShaderEditor.asmdef.meta
ChangeLog.txt
ChangeLog.txt.meta
Plugins.meta
Readme.txt
Readme.txt.meta
GeneratedMaterials
MindPowerSdk
MindPowerSdk.Tests
Resources
Sandbox
Scenes
Scripts
StreamingAssets
TestAssets
WaterWorks
AmplifyShaderEditor.meta
GeneratedMaterials.meta
MindPowerSdk.Tests.meta
MindPowerSdk.meta
New Material 1.mat
New Material 1.mat.meta
New Material.mat
New Material.mat.meta
New Terrain Layer.terrainlayer
New Terrain Layer.terrainlayer.meta
New Terrain Material 1.mat
New Terrain Material 1.mat.meta
New Terrain Material.mat
New Terrain Material.mat.meta
New Universal Render Pipeline Asset.asset
New Universal Render Pipeline Asset.asset.meta
New Universal Render Pipeline Asset_Renderer.asset
New Universal Render Pipeline Asset_Renderer.asset.meta
Prefabs.meta
Resources.meta
Sandbox.meta
Scenes.meta
Scripts.meta
StreamingAssets.meta
TerrainUVBlendShader 1.shader
TerrainUVBlendShader 1.shader.meta
TerrainUVBlendShader.shader
TerrainUVBlendShader.shader.meta
TestAssets.meta
TestTerrainShader 1.shader
TestTerrainShader 1.shader.meta
TestTerrainShader.shader
TestTerrainShader.shader.meta
UniversalRenderPipelineGlobalSettings.asset
UniversalRenderPipelineGlobalSettings.asset.meta
Unlit_NewUnlitTerrainShader.mat
Unlit_NewUnlitTerrainShader.mat.meta
WaterWorks.meta
total_seamless.tga
total_seamless.tga.meta
Packages
ProjectSettings
UserSettings
.gitattributes
.gitignore
README.md
160 lines
4.9 KiB
GLSL
160 lines
4.9 KiB
GLSL
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
|
|
}
|
|
}
|
|
}
|