2424 $splice(PassKeywords)
2525 $splice(GraphKeywords)
2626
27+ // --------------------------------------------------
2728 // Defines
29+
30+ // Lighting Material only (will not affect unlit)
2831 $DisableDecals: #define _DISABLE_DECALS 1
2932 $DisableSSR: #define _DISABLE_SSR 1
3033 $DisableSSRTransparent: #define _DISABLE_SSR_TRANSPARENT 1
34+ $BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
35+
36+ // Precomputed velocity is used for alembic
3137 $AddPrecomputedVelocity: #define _ADD_PRECOMPUTED_VELOCITY
3238 $TransparentWritesMotionVec: #define _TRANSPARENT_WRITES_MOTION_VEC 1
3339 $DepthOffset: #define _DEPTHOFFSET_ON 1
34- $BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
40+
41+ // Attribute
3542 $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL
3643 $AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT
3744 $AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
6572 #endif
6673 #endif
6774
75+ #ifndef SHADER_UNLIT
6876 // We need isFontFace when using double sided
6977 #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
7078 #define VARYINGS_NEED_CULLFACE
7179 #endif
80+ #endif
7281
7382 // Translate transparent motion vector define
7483 #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
8392 // Includes
8493 $splice(PreGraphIncludes)
8594
86- // Used by SceneSelectionPass
95+ // Properties used by SceneSelectionPass
8796 #ifdef SCENESELECTIONPASS
8897 int _ObjectId;
8998 int _PassValue;
256265
257266 void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
258267 {
268+ #ifndef SHADER_UNLIT
259269 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
260270 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
261271 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
270280 #endif
271281
272282 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
283+ #endif // SHADER_UNLIT
273284
274285 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
275286 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
@@ -287,13 +298,29 @@ Pass
287298 $DepthOffset: ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
288299 #endif
289300
301+ #ifndef SHADER_UNLIT
290302 float3 bentNormalWS;
291303 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
292304
293305 // Builtin Data
294306 // For back lighting we use the oposite vertex normal
295307 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
296308
309+ #else
310+ BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
311+
312+ ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
313+ builtinData.opacity = surfaceDescription.Alpha;
314+
315+ #if defined(DEBUG_DISPLAY)
316+ // Light Layers are currently not used for the Unlit shader (because it is not lit)
317+ // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
318+ // display in the light layers visualization mode, therefore we need the renderingLayers
319+ builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
320+ #endif
321+
322+ #endif // SHADER_UNLIT
323+
297324 #ifdef _ALPHATEST_ON
298325 // Used for sharpening by alpha to mask
299326 $DoAlphaTest: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
@@ -302,12 +329,28 @@ Pass
302329 $DoAlphaTestShadow: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThresholdShadow;
303330 #endif
304331
305- // override sampleBakedGI:
332+ // override sampleBakedGI - not used by Unlit
306333 $LightingGI: builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
307334 $BackLightingGI: builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
308335
309336 $SurfaceDescription.Emission: builtinData.emissiveColor = surfaceDescription.Emission;
310337
338+ #ifndef SHADER_UNLIT
339+ // TODO: need to implement for shader graph raytracing
340+ /*
341+ // Raytracing specific code to remove Emissive color from the pass to avoid double contribution
342+ // To avoid to have double lighting (once from the light source and once from the light itself)
343+ #if SHADERPASS == SHADERPASS_RAYTRACING_INDIRECT || SHADERPASS == SHADERPASS_RAYTRACING_GBUFFER
344+ builtinData.emissiveColor *= _IncludeIndirectLighting;
345+ #elif SHADERPASS == SHADERPASS_RAYTRACING_FORWARD || SHADERPASS == SHADERPASS_PATH_TRACING
346+ if (rayCone.spreadAngle < 0.0)
347+ {
348+ builtinData.emissiveColor *= _IncludeIndirectLighting;
349+ }
350+ #endif
351+ */
352+ #endif // SHADER_UNLIT
353+
311354 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
312355 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
313356 // This is a limitation of the current MRT approach.
@@ -321,7 +364,12 @@ Pass
321364 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
322365 #endif
323366
367+ #ifndef SHADER_UNLIT
368+ // PostInitBuiltinData call ApplyDebugToBuiltinData
324369 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
370+ #else
371+ ApplyDebugToBuiltinData(builtinData);
372+ #endif
325373
326374 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
327375 }
0 commit comments