Shader "Custom/InteriorReflectionShader" { Properties { _ReflectionIntensity ("Reflection Intensity", Range(0, 1)) = 1.0 } SubShader { Tags { "RenderType"="Opaque" } LOD 300 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" float _ReflectionIntensity; // Use built-in cubemap sampler (unity_SpecCube0) for reflection probe // UNITY_DECLARE_TEXCUBE(unity_SpecCube0); struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; float3 worldPos : TEXCOORD0; float3 worldNormal : TEXCOORD1; }; v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; o.worldNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal)); return o; } half3 ComputeBoxProjectedReflection(float3 worldPos, float3 worldNormal) { // Calculate direction from the object to the reflection probe position float3 probeToPixel = worldPos - unity_SpecCube0_ProbePosition; // Calculate inverse box scale manually float3 boxSize = unity_SpecCube0_BoxMax - unity_SpecCube0_BoxMin; float3 invBoxSize = 1.0 / boxSize; // Transform the position into the box projection space float3 localPos = probeToPixel * invBoxSize + 0.5; // Calculate reflection direction float3 reflectionDir = normalize(worldPos - _WorldSpaceCameraPos); // Sample the cubemap using the adjusted reflection direction return UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectionDir).rgb; } half4 frag (v2f i) : SV_Target { // Calculate reflection using box projection half3 reflectionColor = ComputeBoxProjectedReflection(i.worldPos, i.worldNormal); return half4(reflectionColor, 1.0); } ENDCG } } FallBack "Diffuse" }