|
|
|
|
|
|
|
|
|
|
#include "VertMesh.hlsl" |
|
|
|
|
|
|
|
float3 RemoveScale(float3 val) |
|
|
|
{ |
|
|
|
return normalize(val / length(val)); |
|
|
|
} |
|
|
|
|
|
|
|
VaryingsMeshType Transform(AttributesMesh input) |
|
|
|
{ |
|
|
|
VaryingsMeshType output; |
|
|
|
|
|
|
|
UNITY_SETUP_INSTANCE_ID(input) |
|
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output); |
|
|
|
|
|
|
|
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|
|
|
positionWS = GetCameraRelativePositionWS(positionWS); |
|
|
|
output.positionCS = TransformWorldToHClip(positionWS); |
|
|
|
|
|
|
|
float3x3 decalRotation; |
|
|
|
decalRotation[0] = RemoveScale(float3(UNITY_MATRIX_M[0][0], UNITY_MATRIX_M[0][1], UNITY_MATRIX_M[0][2])); |
|
|
|
decalRotation[2] = RemoveScale(float3(UNITY_MATRIX_M[1][0], UNITY_MATRIX_M[1][1], UNITY_MATRIX_M[1][2])); |
|
|
|
decalRotation[1] = RemoveScale(float3(UNITY_MATRIX_M[2][0], UNITY_MATRIX_M[2][1], UNITY_MATRIX_M[2][2])); |
|
|
|
|
|
|
|
decalRotation = transpose(decalRotation); |
|
|
|
|
|
|
|
output.positionWS = decalRotation[0]; |
|
|
|
output.normalWS = decalRotation[1]; |
|
|
|
output.tangentWS = float4(decalRotation[2], 0.0); |
|
|
|
|
|
|
|
return output; |
|
|
|
} |
|
|
|
varyingsType.vmesh = Transform(inputMesh); |
|
|
|
varyingsType.vmesh = VertMesh(inputMesh); |
|
|
|
return PackVaryingsType(varyingsType); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DecalSurfaceData surfaceData; |
|
|
|
float3x3 decalToWorld = (float3x3)UNITY_ACCESS_INSTANCED_PROP(matrix, normalToWorld); |
|
|
|
// using the interpolators directly, because UnpackVaryingsMeshToFragInputs does some tangent space manipulations |
|
|
|
// decalToWorld[0] = packedInput.vmesh.interpolators0; |
|
|
|
// decalToWorld[1] = packedInput.vmesh.interpolators1; |
|
|
|
// decalToWorld[2] = packedInput.vmesh.interpolators2.xyz; |
|
|
|
|
|
|
|
GetSurfaceData(positionDS.xz, decalToWorld, surfaceData); |
|
|
|
|
|
|
|
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer); |