1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| Shader "HHF/Tutorial/PlanarReflection" { Properties { _BaseColor("Base Color",color) = (1,1,1,1) _DistortMap("DistortMap",2D) ="white"{} _Distort("Distort",range(0,0.05)) = 0.2 }
SubShader { Tags { "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" } Blend SrcAlpha OneMinusSrcAlpha
Pass { HLSLPROGRAM #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float4 positionCS : SV_POSITION; float2 uv : TEXCOORD0; };
CBUFFER_START(UnityPerMaterial) half4 _BaseColor; half4 _DistortMap_ST; half _Distort; CBUFFER_END TEXTURE2D (_ReflectionRT);SAMPLER(sampler_ReflectionRT); TEXTURE2D (_DistortMap);SAMPLER(sampler_DistortMap);
v2f vert(appdata v) { v2f o = (v2f)0;
o.positionCS = TransformObjectToHClip(v.vertex.xyz); o.uv = v.uv * _DistortMap_ST.xy + _DistortMap_ST.zw+_Time.x; return o; }
half4 frag(v2f i) : SV_Target { half4 c; float2 screenUV = i.positionCS.xy / _ScaledScreenParams.xy; half4 distortMap = SAMPLE_TEXTURE2D(_DistortMap, sampler_DistortMap, i.uv)*2-1; screenUV = lerp(screenUV.xy, distortMap.xy, _Distort); half4 baseMap = SAMPLE_TEXTURE2D(_ReflectionRT, sampler_ReflectionRT, screenUV);
c = baseMap * _BaseColor; return c; } ENDHLSL } }
SubShader { Tags { "Queue"="Transparent" } Blend SrcAlpha OneMinusSrcAlpha Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma shader_feature _CALCMODE_MANUAL _CALCMODE_BUILD
#include "UnityCG.cginc"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float4 positionCS : SV_POSITION; float2 uv : TEXCOORD0; };
half4 _BaseColor; sampler2D _ReflectionRT; half4 _ReflectionRT_ST; sampler2D _DistortMap; half4 _DistortMap_ST; half _Distort;
v2f vert(appdata v) { v2f o = (v2f)0;
o.positionCS = UnityObjectToClipPos(v.vertex.xyz); o.uv = v.uv * _DistortMap_ST.xy + _DistortMap_ST.zw+_Time.x; return o; }
half4 frag(v2f i) : SV_Target { half4 c; float2 screenUV = i.positionCS.xy / _ScreenParams.xy; half4 distortMap = tex2D(_DistortMap, i.uv) * 2 - 1; screenUV = lerp(screenUV, distortMap, _Distort); half4 baseMap = tex2D(_ReflectionRT, screenUV);
c = baseMap * _BaseColor; return c; } ENDCG } } }
|