|
|
|
|
|
|
VaryingsMeshType Transform(AttributesMesh input) |
|
|
|
{ |
|
|
|
VaryingsMeshType output; |
|
|
|
|
|
|
|
|
|
|
|
UNITY_SETUP_INSTANCE_ID(input) |
|
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output.positionWS = decalRotation[0]; |
|
|
|
output.normalWS = decalRotation[1]; |
|
|
|
output.tangentWS = float4(decalRotation[2], 0); |
|
|
|
output.tangentWS = float4(decalRotation[2], 0.0); |
|
|
|
|
|
|
|
return output; |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Frag( PackedVaryingsToPS packedInput, |
|
|
|
OUTPUT_DBUFFER(outDBuffer) |
|
|
|
OUTPUT_DBUFFER(outDBuffer) |
|
|
|
{ |
|
|
|
|
|
|
|
{ |
|
|
|
float d = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; |
|
|
|
UpdatePositionInput(d, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); |
|
|
|
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; |
|
|
|
UpdatePositionInput(depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); |
|
|
|
// Transform from world space to decal space (DS) to clip the decal. |
|
|
|
// For this we must use absolute position. |
|
|
|
// There is no lose of precision here as it doesn't involve the camera matrix |
|
|
|
float3 positionDS = mul(UNITY_MATRIX_I_M, float4(positionWS, 1.0f)).xyz; |
|
|
|
positionDS = positionDS * float3(1.0f, -1.0f, 1.0f) + float3(0.5f, 0.0f, 0.5f); |
|
|
|
clip(positionDS < 0 ? -1 : 1); |
|
|
|
clip(positionDS > 1 ? -1 : 1); |
|
|
|
float3 positionDS = mul(UNITY_MATRIX_I_M, float4(positionWS, 1.0)).xyz; |
|
|
|
positionDS = positionDS * float3(1.0, -1.0, 1.0) + float3(0.5, 0.0f, 0.5); |
|
|
|
clip(positionDS); // clip negative value |
|
|
|
clip(1.0 - positionDS); // Clip value above one |
|
|
|
|
|
|
|
DecalSurfaceData surfaceData; |
|
|
|
float3x3 decalToWorld; |
|
|
|