|
| 1 | +Shader "Samples/InGameHints/SimpleLit" |
| 2 | +{ |
| 3 | + Properties |
| 4 | + { |
| 5 | + _Color ("Color", Color) = (1,1,1,1) |
| 6 | + _MainTex ("Albedo (RGB)", 2D) = "white" {} |
| 7 | + _Glossiness ("Smoothness", Range(0,1)) = 0.5 |
| 8 | + _Metallic ("Metallic", Range(0,1)) = 0.0 |
| 9 | + } |
| 10 | + |
| 11 | + SubShader |
| 12 | + { |
| 13 | + Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" "Queue"="Geometry" } |
| 14 | + |
| 15 | + Pass |
| 16 | + { |
| 17 | + Name "ForwardLit" |
| 18 | + Tags { "LightMode"="UniversalForward" } |
| 19 | + |
| 20 | + HLSLPROGRAM |
| 21 | + #pragma vertex vert |
| 22 | + #pragma fragment frag |
| 23 | + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE |
| 24 | + #pragma multi_compile _ _ADDITIONAL_LIGHTS |
| 25 | + #pragma multi_compile_fog |
| 26 | + |
| 27 | + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
| 28 | + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" |
| 29 | + |
| 30 | + TEXTURE2D(_MainTex); |
| 31 | + SAMPLER(sampler_MainTex); |
| 32 | + |
| 33 | + CBUFFER_START(UnityPerMaterial) |
| 34 | + float4 _MainTex_ST; |
| 35 | + half4 _Color; |
| 36 | + half _Glossiness; |
| 37 | + half _Metallic; |
| 38 | + CBUFFER_END |
| 39 | + |
| 40 | + struct Attributes |
| 41 | + { |
| 42 | + float4 positionOS : POSITION; |
| 43 | + float3 normalOS : NORMAL; |
| 44 | + float2 uv : TEXCOORD0; |
| 45 | + }; |
| 46 | + |
| 47 | + struct Varyings |
| 48 | + { |
| 49 | + float4 positionCS : SV_POSITION; |
| 50 | + float2 uv : TEXCOORD0; |
| 51 | + float3 normalWS : TEXCOORD1; |
| 52 | + float3 positionWS : TEXCOORD2; |
| 53 | + float fogFactor : TEXCOORD3; |
| 54 | + }; |
| 55 | + |
| 56 | + Varyings vert(Attributes input) |
| 57 | + { |
| 58 | + Varyings output; |
| 59 | + VertexPositionInputs posInputs = GetVertexPositionInputs(input.positionOS.xyz); |
| 60 | + output.positionCS = posInputs.positionCS; |
| 61 | + output.positionWS = posInputs.positionWS; |
| 62 | + output.normalWS = TransformObjectToWorldNormal(input.normalOS); |
| 63 | + output.uv = TRANSFORM_TEX(input.uv, _MainTex); |
| 64 | + output.fogFactor = ComputeFogFactor(posInputs.positionCS.z); |
| 65 | + return output; |
| 66 | + } |
| 67 | + |
| 68 | + half4 frag(Varyings input) : SV_Target |
| 69 | + { |
| 70 | + half4 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv) * _Color; |
| 71 | + |
| 72 | + InputData inputData = (InputData)0; |
| 73 | + inputData.positionWS = input.positionWS; |
| 74 | + inputData.normalWS = normalize(input.normalWS); |
| 75 | + inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS); |
| 76 | + |
| 77 | + SurfaceData surfaceData = (SurfaceData)0; |
| 78 | + surfaceData.albedo = albedo.rgb; |
| 79 | + surfaceData.alpha = albedo.a; |
| 80 | + surfaceData.metallic = _Metallic; |
| 81 | + surfaceData.smoothness = _Glossiness; |
| 82 | + surfaceData.occlusion = 1.0; |
| 83 | + |
| 84 | + half4 color = UniversalFragmentPBR(inputData, surfaceData); |
| 85 | + color.rgb = MixFog(color.rgb, input.fogFactor); |
| 86 | + return color; |
| 87 | + } |
| 88 | + ENDHLSL |
| 89 | + } |
| 90 | + |
| 91 | + Pass |
| 92 | + { |
| 93 | + Name "ShadowCaster" |
| 94 | + Tags { "LightMode"="ShadowCaster" } |
| 95 | + |
| 96 | + ZWrite On |
| 97 | + ZTest LEqual |
| 98 | + ColorMask 0 |
| 99 | + |
| 100 | + HLSLPROGRAM |
| 101 | + #pragma vertex ShadowVert |
| 102 | + #pragma fragment ShadowFrag |
| 103 | + #pragma multi_compile _ _CASTING_PUNCTUAL_LIGHT_SHADOW |
| 104 | + |
| 105 | + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
| 106 | + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" |
| 107 | + |
| 108 | + float3 _LightDirection; |
| 109 | + float3 _LightPosition; |
| 110 | + |
| 111 | + struct Attributes |
| 112 | + { |
| 113 | + float4 positionOS : POSITION; |
| 114 | + float3 normalOS : NORMAL; |
| 115 | + }; |
| 116 | + |
| 117 | + struct Varyings |
| 118 | + { |
| 119 | + float4 positionCS : SV_POSITION; |
| 120 | + }; |
| 121 | + |
| 122 | + Varyings ShadowVert(Attributes input) |
| 123 | + { |
| 124 | + Varyings output; |
| 125 | + float3 posWS = TransformObjectToWorld(input.positionOS.xyz); |
| 126 | + float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
| 127 | + |
| 128 | + #if _CASTING_PUNCTUAL_LIGHT_SHADOW |
| 129 | + float3 lightDir = normalize(_LightPosition - posWS); |
| 130 | + #else |
| 131 | + float3 lightDir = _LightDirection; |
| 132 | + #endif |
| 133 | + |
| 134 | + output.positionCS = TransformWorldToHClip(ApplyShadowBias(posWS, normalWS, lightDir)); |
| 135 | + #if UNITY_REVERSED_Z |
| 136 | + output.positionCS.z = min(output.positionCS.z, UNITY_NEAR_CLIP_VALUE); |
| 137 | + #else |
| 138 | + output.positionCS.z = max(output.positionCS.z, UNITY_NEAR_CLIP_VALUE); |
| 139 | + #endif |
| 140 | + return output; |
| 141 | + } |
| 142 | + |
| 143 | + half4 ShadowFrag(Varyings input) : SV_Target |
| 144 | + { |
| 145 | + return 0; |
| 146 | + } |
| 147 | + ENDHLSL |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + SubShader |
| 152 | + { |
| 153 | + Tags { "RenderType"="Opaque" } |
| 154 | + LOD 200 |
| 155 | + |
| 156 | + CGPROGRAM |
| 157 | + #pragma surface surf Standard fullforwardshadows |
| 158 | + #pragma target 3.0 |
| 159 | + |
| 160 | + sampler2D _MainTex; |
| 161 | + half _Glossiness; |
| 162 | + half _Metallic; |
| 163 | + fixed4 _Color; |
| 164 | + |
| 165 | + struct Input |
| 166 | + { |
| 167 | + float2 uv_MainTex; |
| 168 | + }; |
| 169 | + |
| 170 | + void surf(Input IN, inout SurfaceOutputStandard o) |
| 171 | + { |
| 172 | + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; |
| 173 | + o.Albedo = c.rgb; |
| 174 | + o.Metallic = _Metallic; |
| 175 | + o.Smoothness = _Glossiness; |
| 176 | + o.Alpha = c.a; |
| 177 | + } |
| 178 | + ENDCG |
| 179 | + } |
| 180 | + |
| 181 | + FallBack "Diffuse" |
| 182 | +} |
0 commit comments