Pass { Tags{"LightMode" = "LightweightForward"} ${Tags} ${Blending} ${Culling} ${ZTest} ${ZWrite} HLSLPROGRAM // Required to compile gles 2.0 with standard srp library #pragma prefer_hlslcc gles #pragma target 3.0 // ------------------------------------- // Lightweight Pipeline keywords // We have no good approach exposed to skip shader variants, e.g, ideally we would like to skip _CASCADE for all puctual lights // Lightweight combines light classification and shadows keywords to reduce shader variants. // Lightweight shader library declares defines based on these keywords to avoid having to check them in the shaders // Core.hlsl defines _MAIN_LIGHT_DIRECTIONAL and _MAIN_LIGHT_SPOT (point lights can't be main light) // Shadow.hlsl defines _SHADOWS_ENABLED, _SHADOWS_SOFT, _SHADOWS_CASCADE, _SHADOWS_PERSPECTIVE #pragma multi_compile _ _MAIN_LIGHT_DIRECTIONAL_SHADOW _MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE _MAIN_LIGHT_DIRECTIONAL_SHADOW_SOFT _MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE_SOFT _MAIN_LIGHT_SPOT_SHADOW _MAIN_LIGHT_SPOT_SHADOW_SOFT #pragma multi_compile _ _MAIN_LIGHT_COOKIE #pragma multi_compile _ _ADDITIONAL_LIGHTS #pragma multi_compile _ _VERTEX_LIGHTS #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE // ------------------------------------- // Unity defined keywords #pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON #pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile _ DIRLIGHTMAP_COMBINED #pragma multi_compile_fog #pragma vertex vert #pragma fragment frag ${Defines} #include "LWRP/Shaders/LightweightShaderLibrary/Core.hlsl" #include "LWRP/Shaders/LightweightShaderLibrary/Lighting.hlsl" #include "CoreRP/ShaderLibrary/Color.hlsl" #include "ShaderGraphLibrary/Functions.hlsl" ${Graph} struct GraphVertexOutput { float4 clipPos : SV_POSITION; float4 lightmapUVOrVertexSH : TEXCOORD0; half4 fogFactorAndVertexLight : TEXCOORD1; // x: fogFactor, yzw: vertex light ${Interpolators} }; GraphVertexOutput vert (GraphVertexInput v) { v = PopulateVertexData(v); GraphVertexOutput o = (GraphVertexOutput)0; ${VertexShader} float3 lwWNormal = TransformObjectToWorldNormal(v.normal); float3 lwWorldPos = TransformObjectToWorld(v.vertex.xyz); float4 clipPos = TransformWorldToHClip(lwWorldPos); // We either sample GI from lightmap or SH. lightmap UV and vertex SH coefficients // are packed in lightmapUVOrVertexSH to save interpolator. // The following funcions initialize OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUVOrVertexSH); OUTPUT_SH(lwWNormal, o.lightmapUVOrVertexSH); half3 vertexLight = VertexLighting(lwWorldPos, lwWNormal); half fogFactor = ComputeFogFactor(clipPos.z); o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); o.clipPos = clipPos; return o; } half4 frag (GraphVertexOutput IN) : SV_Target { ${LocalPixelShader} SurfaceInputs surfaceInput = (SurfaceInputs)0; ${SurfaceInputs} SurfaceDescription surf = PopulateSurfaceData(surfaceInput); float3 Albedo = float3(0.5, 0.5, 0.5); float3 Specular = float3(0, 0, 0); float Metallic = 0; float3 Normal = float3(0, 0, 1); float3 Emission = 0; float Smoothness = 0.5; float Occlusion = 1; float Alpha = 1; float AlphaClipThreshold = 0; ${SurfaceOutputRemap} #if _NORMALMAP half3 normalWS = TangentToWorldNormal(Normal, WorldSpaceTangent, WorldSpaceBiTangent, WorldSpaceNormal); #else half3 normalWS = normalize(WorldSpaceNormal); #endif half3 indirectDiffuse = SampleGI(IN.lightmapUVOrVertexSH, normalWS); half4 color = LightweightFragmentPBR( WorldSpacePosition, normalWS, WorldSpaceViewDirection, indirectDiffuse, IN.fogFactorAndVertexLight.yzw, Albedo, Metallic, Specular, Smoothness, Occlusion, Emission, Alpha); // Computes fog factor per-vertex ApplyFog(color.rgb, IN.fogFactorAndVertexLight.x); #if _AlphaOut color.a = Alpha; #else color.a = 1; #endif #if _AlphaClip clip(Alpha - AlphaClipThreshold); #endif return color; } ENDHLSL }