summaryrefslogtreecommitdiffstats
path: root/impostor.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'impostor.cginc')
-rwxr-xr-ximpostor.cginc33
1 files changed, 12 insertions, 21 deletions
diff --git a/impostor.cginc b/impostor.cginc
index fe08b67..14fee5b 100755
--- a/impostor.cginc
+++ b/impostor.cginc
@@ -89,24 +89,22 @@ ImpostorSample SampleImpostorCell(float2 cell, float2 uvInCell, float invGridRes
return s;
}
-float2 ImpostorParallaxOffset(float3 planeX, float3 planeY, float3 planeN, float3 pivotToCamOS, float encodedDepth, float rcpObjScale, float objRadiusScaled, float objNearScaled) {
+float2 ImpostorParallaxOffset(float3 planeX, float3 planeY, float3 planeN, float3 pivotToCamOS, float encodedDepth) {
float2 camXY = float2(dot(pivotToCamOS, planeX), dot(pivotToCamOS, planeY));
float camZ = dot(pivotToCamOS, planeN);
camZ = (abs(camZ) < 1e-4) ? (camZ < 0 ? -1e-4 : 1e-4) : camZ;
float worldSpaceDepth = lerp(_Impostors_Near_Clip, _Impostors_Far_Clip, encodedDepth);
- float depth01 = (worldSpaceDepth - objNearScaled) * objRadiusScaled;
+ float depth01 = (worldSpaceDepth - _Impostors_Near_Clip) / (2.0 * _Impostors_Sphere_Radius);
float height = 0.5 - depth01;
return (camXY / camZ) * height;
}
-float3 ReconstructObjectOffset(float3 planeX, float3 planeY, float3 planeN, float2 uv, float encodedDepth, float rcpObjScale, float objRadius, float objNear) {
- float objFar = _Impostors_Far_Clip * rcpObjScale;
-
- float2 offsetXY = (0.5 - uv) * (2.0 * objRadius);
- float objectSpaceDepth = lerp(objNear, objFar, encodedDepth);
- float offsetZ = (objRadius + objNear) - objectSpaceDepth;
+float3 ReconstructObjectOffset(float3 planeX, float3 planeY, float3 planeN, float2 uv, float encodedDepth) {
+ float2 offsetXY = (0.5 - uv) * (2.0 * _Impostors_Sphere_Radius);
+ float worldSpaceDepth = lerp(_Impostors_Near_Clip, _Impostors_Far_Clip, encodedDepth);
+ float offsetZ = (_Impostors_Sphere_Radius + _Impostors_Near_Clip) - worldSpaceDepth;
return offsetXY.x * planeX + offsetXY.y * planeY + offsetZ * planeN;
}
@@ -212,21 +210,14 @@ ImpostorResult impostor_frag(float3 worldPos) {
return result;
}
- // Pre-compute scale values once for both parallax and reconstruction
- float objScale = max(2.0 * _Impostors_Sphere_Radius, 1e-4);
- float rcpObjScale = rcp(objScale);
- float objRadius = _Impostors_Sphere_Radius * rcpObjScale;
- float objRadiusScaled = rcp(2.0 * objRadius);
- float objNearScaled = _Impostors_Near_Clip * rcpObjScale;
-
float2 parallaxOffset0 = 0, parallaxOffset1 = 0, parallaxOffset2 = 0;
bool needsParallaxResample = false;
[branch]
if (parallaxStrength > 0.001) {
- parallaxOffset0 = ImpostorParallaxOffset(planeX0, planeY0, planeN0, pivotToCamOS, depthBlended, rcpObjScale, objRadiusScaled, objNearScaled) * parallaxStrength;
- parallaxOffset1 = ImpostorParallaxOffset(planeX1, planeY1, planeN1, pivotToCamOS, depthBlended, rcpObjScale, objRadiusScaled, objNearScaled) * parallaxStrength;
- parallaxOffset2 = ImpostorParallaxOffset(planeX2, planeY2, planeN2, pivotToCamOS, depthBlended, rcpObjScale, objRadiusScaled, objNearScaled) * parallaxStrength;
+ parallaxOffset0 = ImpostorParallaxOffset(planeX0, planeY0, planeN0, pivotToCamOS, depthBlended) * parallaxStrength;
+ parallaxOffset1 = ImpostorParallaxOffset(planeX1, planeY1, planeN1, pivotToCamOS, depthBlended) * parallaxStrength;
+ parallaxOffset2 = ImpostorParallaxOffset(planeX2, planeY2, planeN2, pivotToCamOS, depthBlended) * parallaxStrength;
float maxOffsetSq = max(max(dot(parallaxOffset0, parallaxOffset0), dot(parallaxOffset1, parallaxOffset1)), dot(parallaxOffset2, parallaxOffset2));
needsParallaxResample = maxOffsetSq > 0.00005;
@@ -275,9 +266,9 @@ ImpostorResult impostor_frag(float3 worldPos) {
result.smoothness = blended.metallicGloss.g;
#if defined(_IMPOSTORS_DEPTH)
- float3 offset0 = ReconstructObjectOffset(planeX0, planeY0, planeN0, finalUv0, depth0, rcpObjScale, objRadius, objNearScaled);
- float3 offset1 = ReconstructObjectOffset(planeX1, planeY1, planeN1, finalUv1, depth1, rcpObjScale, objRadius, objNearScaled);
- float3 offset2 = ReconstructObjectOffset(planeX2, planeY2, planeN2, finalUv2, depth2, rcpObjScale, objRadius, objNearScaled);
+ float3 offset0 = ReconstructObjectOffset(planeX0, planeY0, planeN0, finalUv0, depth0);
+ float3 offset1 = ReconstructObjectOffset(planeX1, planeY1, planeN1, finalUv1, depth1);
+ float3 offset2 = ReconstructObjectOffset(planeX2, planeY2, planeN2, finalUv2, depth2);
result.objPos = offset0 * bw.x + offset1 * bw.y + offset2 * bw.z;
#endif