Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ Pass
$splice(PassKeywords)
$splice(GraphKeywords)

// --------------------------------------------------
// Defines

// Lighting Material only (will not affect unlit)
$DisableDecals: #define _DISABLE_DECALS 1
$DisableSSR: #define _DISABLE_SSR 1
$DisableSSRTransparent: #define _DISABLE_SSR_TRANSPARENT 1
$BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1

// Precomputed velocity is used for alembic
$AddPrecomputedVelocity: #define _ADD_PRECOMPUTED_VELOCITY
$TransparentWritesMotionVec: #define _TRANSPARENT_WRITES_MOTION_VEC 1
$DepthOffset: #define _DEPTHOFFSET_ON 1
$BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1

// Attribute
$AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL
$AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
Expand Down Expand Up @@ -65,10 +72,12 @@ Pass
#endif
#endif

#ifndef SHADER_UNLIT
// We need isFontFace when using double sided
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
#define VARYINGS_NEED_CULLFACE
#endif
#endif

// Translate transparent motion vector define
#if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
Expand All @@ -83,7 +92,7 @@ Pass
// Includes
$splice(PreGraphIncludes)

// Used by SceneSelectionPass
// Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
Expand Down Expand Up @@ -256,6 +265,7 @@ Pass

void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
{
#ifndef SHADER_UNLIT
// Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
Expand All @@ -270,6 +280,7 @@ Pass
#endif

ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
#endif // SHADER_UNLIT

SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
Expand All @@ -287,13 +298,29 @@ Pass
$DepthOffset: ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
#endif

#ifndef SHADER_UNLIT
float3 bentNormalWS;
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);

// Builtin Data
// For back lighting we use the oposite vertex normal
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);

#else
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);

ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
builtinData.opacity = surfaceDescription.Alpha;

#if defined(DEBUG_DISPLAY)
// Light Layers are currently not used for the Unlit shader (because it is not lit)
// But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
// display in the light layers visualization mode, therefore we need the renderingLayers
builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
#endif

#endif // SHADER_UNLIT

#ifdef _ALPHATEST_ON
// Used for sharpening by alpha to mask
$DoAlphaTest: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
Expand All @@ -302,12 +329,28 @@ Pass
$DoAlphaTestShadow: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThresholdShadow;
#endif

// override sampleBakedGI:
// override sampleBakedGI - not used by Unlit
$LightingGI: builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
$BackLightingGI: builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;

$SurfaceDescription.Emission: builtinData.emissiveColor = surfaceDescription.Emission;

#ifndef SHADER_UNLIT
// TODO: need to implement for shader graph raytracing
/*
// Raytracing specific code to remove Emissive color from the pass to avoid double contribution
// To avoid to have double lighting (once from the light source and once from the light itself)
#if SHADERPASS == SHADERPASS_RAYTRACING_INDIRECT || SHADERPASS == SHADERPASS_RAYTRACING_GBUFFER
builtinData.emissiveColor *= _IncludeIndirectLighting;
#elif SHADERPASS == SHADERPASS_RAYTRACING_FORWARD || SHADERPASS == SHADERPASS_PATH_TRACING
if (rayCone.spreadAngle < 0.0)
{
builtinData.emissiveColor *= _IncludeIndirectLighting;
}
#endif
*/
#endif // SHADER_UNLIT

// Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
// We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
// This is a limitation of the current MRT approach.
Expand All @@ -321,7 +364,12 @@ Pass
builtinData.distortionBlur = surfaceDescription.DistortionBlur;
#endif

#ifndef SHADER_UNLIT
// PostInitBuiltinData call ApplyDebugToBuiltinData
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
#else
ApplyDebugToBuiltinData(builtinData);
#endif

RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData<HDUnlitD
public HDUnlitSubTarget() => displayName = "Unlit";

// Templates
protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template";
protected override string templateMaterialDirectory => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/ShaderGraph/Templates";
protected override string templateMaterialDirectory => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/";
protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Unlit;
protected override string renderType => HDRenderTypeTags.HDUnlitShader.ToString();
protected override string subTargetAssetGuid => "4516595d40fa52047a77940183dc8e74"; // HDUnlitSubTarget
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData)
{
// setup defaults -- these are used if the graph doesn't output a value
ZERO_INITIALIZE(SurfaceData, surfaceData);

// copy across graph values, if defined
$SurfaceDescription.BaseColor: surfaceData.color = surfaceDescription.BaseColor;

#if defined(DEBUG_DISPLAY)
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
// TODO
}
#endif

#if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT
HDShadowContext shadowContext = InitShadowContext();
float shadow;
float3 shadow3;
// We need to recompute some coordinate not computed by default for shadow matte
posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
float3 upWS = normalize(fragInputs.tangentToWorld[1]);
uint renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3);
shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0));

float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba;
float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha);

// Keep the nested lerp
// With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow
// And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker)
#ifdef _SURFACE_TYPE_TRANSPARENT
surfaceData.color = lerp(shadowColor.rgb * surfaceData.color, lerp(lerp(shadowColor.rgb, surfaceData.color, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.color, shadow), surfaceDescription.Alpha);
#else
surfaceData.color = lerp(lerp(shadowColor.rgb, surfaceData.color, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.color, shadow);
#endif
localAlpha = ApplyBlendMode(surfaceData.color, localAlpha).a;

surfaceDescription.Alpha = localAlpha;
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Setup a define to say we are an unlit shader
#define SHADER_UNLIT
$EnableShadowMatte: #define _ENABLE_SHADOW_MATTE

// Following Macro are only used by Unlit material
#if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT
#define LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
#define HAS_LIGHTLOOP
#endif
Loading