|
|
|
|
|
|
// To handle object scaling with PPD we need to multiply the view vector by the inverse scale. |
|
|
|
// Currently we extract the inverse scale directly by taking worldToObject matrix (instead of ObjectToWorld) |
|
|
|
float3 objectScale; |
|
|
|
float4x4 worldTransform = GetObjectToWorldMatrix(); |
|
|
|
float4x4 worldTransform = GetWorldToObjectMatrix(); |
|
|
|
objectScale.x = length(float3(worldTransform._m00, worldTransform._m01, worldTransform._m02)); |
|
|
|
objectScale.y = length(float3(worldTransform._m10, worldTransform._m11, worldTransform._m12)); |
|
|
|
objectScale.z = length(float3(worldTransform._m20, worldTransform._m21, worldTransform._m22)); |
|
|
|
|
|
|
|
|
|
|
float3x3 worldToTangent = input.worldToTangent; |
|
|
|
|
|
|
|
#ifdef _PER_PIXEL_DISPLACEMENT_OBJECT_SCALE |
|
|
|
//V *= objectScale; |
|
|
|
#endif |
|
|
|
|
|
|
|
viewDirTS *= 1.0 / objectScale; |
|
|
|
viewDirTS *= objectScale.xzy; // Switch from Y-up to Z-up |
|
|
|
|
|
|
|
int numSteps = (int)lerp(_PPDMaxSamples, _PPDMinSamples, viewDirTS.z); |
|
|
|
|
|
|
|
float2 offset = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirTS, maxHeight, ppdParam, height); |
|
|
|
int numSteps = (int)lerp(_PPDMaxSamples, _PPDMinSamples, saturate(viewDirTS.z)); |
|
|
|
float2 offset = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirTS, maxHeight, ppdParam, height); |
|
|
|
|
|
|
|
// Apply offset to all UVSet0 / planar |
|
|
|
layerTexCoord.base.uv += offset; |
|
|
|