Preview_ReflectionProbe.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Shader "Hidden/IndirectSpecularLight"
  2. {
  3. Properties
  4. {
  5. _Skybox("_Skybox", CUBE) = "white" {}
  6. _A ("View Dir OS", 2D) = "white" {}
  7. _B ("Normal OS", 2D) = "white" {}
  8. _C ("LOD", 2D) = "white" {}
  9. }
  10. SubShader
  11. {
  12. Pass // not connected
  13. {
  14. CGPROGRAM
  15. #pragma vertex vert_img
  16. #pragma fragment frag
  17. #include "UnityCG.cginc"
  18. #include "Preview.cginc"
  19. #include "Lighting.cginc"
  20. #include "UnityPBSLighting.cginc"
  21. uniform samplerCUBE _Skybox;
  22. sampler2D _A;
  23. sampler2D _B;
  24. sampler2D _C;
  25. uint viewDirInput;
  26. uint normalInput;
  27. uint lodInput;
  28. float4 frag(v2f_img i) : SV_Target
  29. {
  30. float3 vertexPos = PreviewFragmentPositionOS( i.uv );
  31. float3 normal = PreviewFragmentNormalOS( i.uv );
  32. float3 worldNormal = UnityObjectToWorldNormal( normal );
  33. float3 worldViewDir = normalize( preview_WorldSpaceCameraPos - vertexPos );
  34. float lod = 0;
  35. float2 sphereUV = PreviewFragmentSphericalUV( i.uv );
  36. if ( viewDirInput != 0 )
  37. {
  38. float3 viewDirOS = tex2D( _A, sphereUV );
  39. worldViewDir = UnityObjectToWorldDir( viewDirOS );
  40. }
  41. if ( normalInput != 0 )
  42. {
  43. float3 normalOS = tex2D( _B, i.uv );
  44. worldNormal = UnityObjectToWorldNormal( normalOS );
  45. }
  46. if ( lodInput != 0 )
  47. {
  48. lod = tex2D( _C, i.uv );
  49. }
  50. float3 worldRefl = normalize( reflect( -worldViewDir, worldNormal ) );
  51. float3 sky = texCUBElod( _Skybox, float4( worldRefl, lod ) ).rgb;
  52. return float4( sky, 1 );
  53. }
  54. ENDCG
  55. }
  56. }
  57. }