diff options
| -rw-r--r-- | impostor.cginc | 59 | ||||
| -rw-r--r-- | vertex_deformation.slang | 2 |
2 files changed, 6 insertions, 55 deletions
diff --git a/impostor.cginc b/impostor.cginc index f6c0d72..fb41b19 100644 --- a/impostor.cginc +++ b/impostor.cginc @@ -6,16 +6,13 @@ SamplerState bilinear_clamp_s; Texture2D _ImpostorAtlas; -Texture2D _ImpostorDepthAtlas; int _GridResolution; -float _SphereRadius; float _Cutoff; float3 _ImpostorMainCameraPos; #ifndef IMPOSTOR_SHADOW_PASS float4 _Color; float _DebugMode; -float _DebugDepth; #endif float2 HemiOctEncode(float3 N) { @@ -48,14 +45,6 @@ float4 SampleAtlas(float2 uv, float2 cell) { return _ImpostorAtlas.Sample(bilinear_clamp_s, (cell + uv) / _GridResolution); } -float SampleDepthAtlas(float2 uv, float2 cell) { - return _ImpostorDepthAtlas.Sample(bilinear_clamp_s, (cell + uv) / _GridResolution).r; -} - -// ============================================================================ -// Vertex/Fragment -// ============================================================================ - struct appdata { float4 vertex : POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID @@ -69,15 +58,10 @@ struct v2f { V2F_SHADOW_CASTER; #else float4 pos : SV_POSITION; - UNITY_FOG_COORDS(7) + UNITY_FOG_COORDS(3) #endif float2 uv : TEXCOORD1; float2 cell : TEXCOORD2; - // For depth reconstruction - float3 worldPos : TEXCOORD3; - float3 viewWS : TEXCOORD4; - float3 center : TEXCOORD5; - float radius : TEXCOORD6; UNITY_VERTEX_OUTPUT_STEREO }; @@ -121,59 +105,26 @@ v2f vert(appdata v) { o.uv = float2(1 - (dot(localOff, right) + 0.5), dot(localOff, up) + 0.5); o.cell = float2(cell); - // Pass data for depth reconstruction - float3 viewWS = normalize(camPos - center); - o.worldPos = worldPos; - o.viewWS = viewWS; - o.center = center; - o.radius = _SphereRadius * scale.x; - return o; } #ifdef IMPOSTOR_SHADOW_PASS -// Shadow pass - just alpha test, no depth output float4 frag(v2f i) : SV_Target { float4 col = SampleAtlas(i.uv, i.cell); clip(col.a - _Cutoff); SHADOW_CASTER_FRAGMENT(i) } #else -// Forward pass - with depth output -struct FragOutput { - float4 color : SV_Target; - float depth : SV_Depth; -}; - -FragOutput frag(v2f i) { - FragOutput o; - +float4 frag(v2f i) : SV_Target { float4 col = SampleAtlas(i.uv, i.cell); - float depth = SampleDepthAtlas(i.uv, i.cell); - - // Compute depth-corrected world position - // depth=0 means front of sphere (toward camera), depth=1 means back (away from camera) - float3 depthWorldPos = i.worldPos - i.viewWS * (2.0 * depth - 1.0) * i.radius; - // Convert to clip space depth - float4 clipPos = mul(UNITY_MATRIX_VP, float4(depthWorldPos, 1.0)); - o.depth = clipPos.z / clipPos.w; - - if (_DebugMode > 0.5) { - o.color = float4(i.uv, 0, 1); - return o; - } - if (_DebugDepth > 0.5) { - o.color = float4(depth.xxx, 1); - return o; - } + if (_DebugMode > 0.5) + return float4(i.uv, 0, 1); col *= _Color; clip(col.a - _Cutoff); - UNITY_APPLY_FOG(i.fogCoord, col); - o.color = col; - return o; + return col; } #endif diff --git a/vertex_deformation.slang b/vertex_deformation.slang index 6e916ed..1cb002f 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -385,7 +385,7 @@ public void sine_wave_undeform_normal(float3 xyz, inout float3 normal, [Differentiable] public float3 norm_conversion(float3 xyz, no_diff float input_k, no_diff float output_k, no_diff float t) { - float3 xyz_abs = abs(xyz)+1e-3f; + float3 xyz_abs = abs(xyz)+1e-4f; float lin = pow(pow(xyz_abs.x, input_k) + pow(xyz_abs.y, input_k) + pow(xyz_abs.z, input_k), 1.0f / input_k); float lout = pow(pow(xyz_abs.x, output_k) + pow(xyz_abs.y, output_k) + pow(xyz_abs.z, output_k), 1.0f / output_k); float scale = lerp(1.0f, lout / lin, t); |
