├── BakeryHDRP.hlsl ├── BakeryHDRP_Forward.hlsl ├── BakeryHDRP_GBuffer.hlsl ├── BakeryLitHDRP.shader └── README.md /BakeryHDRP.hlsl: -------------------------------------------------------------------------------- 1 | #ifndef BAKERY_INCLUDED 2 | #define BAKERY_INCLUDED 3 | 4 | float bakeryLightmapMode; 5 | //float2 bakeryLightmapSize; 6 | #define BAKERYMODE_DEFAULT 0 7 | #define BAKERYMODE_VERTEXLM 1.0f 8 | #define BAKERYMODE_RNM 2.0f 9 | #define BAKERYMODE_SH 3.0f 10 | 11 | #if defined(BAKERY_RNM) && defined(BAKERY_LMSPEC) 12 | #define BAKERY_RNMSPEC 13 | #endif 14 | 15 | #ifndef BAKERY_VERTEXLM 16 | #undef BAKERY_VERTEXLMDIR 17 | #undef BAKERY_VERTEXLMSH 18 | #undef BAKERY_VERTEXLMMASK 19 | #endif 20 | 21 | #define lumaConv float3(0.2125f, 0.7154f, 0.0721f) 22 | 23 | #if defined(BAKERY_SH) || defined(BAKERY_VERTEXLMSH) 24 | float shEvaluateDiffuseL1Geomerics(float L0, float3 L1, float3 n) 25 | { 26 | // average energy 27 | float R0 = L0; 28 | 29 | // avg direction of incoming light 30 | float3 R1 = 0.5f * L1; 31 | 32 | // directional brightness 33 | float lenR1 = length(R1); 34 | 35 | // linear angle between normal and direction 0-1 36 | //float q = 0.5f * (1.0f + dot(R1 / lenR1, n)); 37 | //float q = dot(R1 / lenR1, n) * 0.5 + 0.5; 38 | float q = dot(normalize(R1), n) * 0.5 + 0.5; 39 | 40 | // power for q 41 | // lerps from 1 (linear) to 3 (cubic) based on directionality 42 | float p = 1.0f + 2.0f * lenR1 / R0; 43 | 44 | // dynamic range constant 45 | // should vary between 4 (highly directional) and 0 (ambient) 46 | float a = (1.0f - lenR1 / R0) / (1.0f + lenR1 / R0); 47 | 48 | return R0 * (a + (1.0f - a) * (p + 1.0f) * pow(q, p)); 49 | } 50 | #endif 51 | 52 | #ifdef BAKERY_VERTEXLM 53 | float4 unpack4NFloats(float src) { 54 | //return fmod(float4(src / 262144.0, src / 4096.0, src / 64.0, src), 64.0)/64.0; 55 | return frac(float4(src / (262144.0*64), src / (4096.0*64), src / (64.0*64), src)); 56 | } 57 | float3 unpack3NFloats(float src) { 58 | float r = frac(src); 59 | float g = frac(src * 256.0); 60 | float b = frac(src * 65536.0); 61 | return float3(r, g, b); 62 | } 63 | #if defined(BAKERY_VERTEXLMDIR) 64 | void BakeryVertexLMDirection(inout float3 diffuseColor, inout float3 specularColor, float3 lightDirection, float3 vertexNormalWorld, float3 normalWorld, float3 viewDir, float smoothness) 65 | { 66 | float3 dominantDir = Unity_SafeNormalize(lightDirection); 67 | half halfLambert = dot(normalWorld, dominantDir) * 0.5 + 0.5; 68 | half flatNormalHalfLambert = dot(vertexNormalWorld, dominantDir) * 0.5 + 0.5; 69 | 70 | #ifdef BAKERY_LMSPEC 71 | half3 halfDir = Unity_SafeNormalize(normalize(dominantDir) - viewDir); 72 | half nh = saturate(dot(normalWorld, halfDir)); 73 | half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness); 74 | half roughness = PerceptualRoughnessToRoughness(perceptualRoughness); 75 | half spec = GGXTerm(nh, roughness); 76 | diffuseColor = spec * diffuseColor; 77 | #endif 78 | 79 | diffuseColor *= halfLambert / max(1e-4h, flatNormalHalfLambert); 80 | } 81 | #elif defined(BAKERY_VERTEXLMSH) 82 | void BakeryVertexLMSH(inout float3 diffuseColor, inout float3 specularColor, float3 shL1x, float3 shL1y, float3 shL1z, float3 normalWorld, float3 viewDir, float smoothness) 83 | { 84 | float3 L0 = diffuseColor; 85 | float3 nL1x = shL1x; 86 | float3 nL1y = shL1y; 87 | float3 nL1z = shL1z; 88 | float3 L1x = nL1x * L0 * 2; 89 | float3 L1y = nL1y * L0 * 2; 90 | float3 L1z = nL1z * L0 * 2; 91 | 92 | float3 sh; 93 | sh.r = shEvaluateDiffuseL1Geomerics(L0.r, float3(L1x.r, L1y.r, L1z.r), normalWorld); 94 | sh.g = shEvaluateDiffuseL1Geomerics(L0.g, float3(L1x.g, L1y.g, L1z.g), normalWorld); 95 | sh.b = shEvaluateDiffuseL1Geomerics(L0.b, float3(L1x.b, L1y.b, L1z.b), normalWorld); 96 | 97 | diffuseColor = sh; 98 | 99 | #ifdef BAKERY_LMSPEC 100 | float3 dominantDir = float3(dot(nL1x, lumaConv), dot(nL1y, lumaConv), dot(nL1z, lumaConv)); 101 | float focus = saturate(length(dominantDir)); 102 | half3 halfDir = Unity_SafeNormalize(normalize(dominantDir) - viewDir); 103 | half nh = saturate(dot(normalWorld, halfDir)); 104 | half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness );//* sqrt(focus)); 105 | half roughness = PerceptualRoughnessToRoughness(perceptualRoughness); 106 | half spec = GGXTerm(nh, roughness); 107 | specularColor = spec * sh; 108 | #endif 109 | } 110 | #endif 111 | #endif 112 | 113 | #ifdef BAKERY_BICUBIC 114 | float BakeryBicubic_w0(float a) 115 | { 116 | return (1.0f/6.0f)*(a*(a*(-a + 3.0f) - 3.0f) + 1.0f); 117 | } 118 | 119 | float BakeryBicubic_w1(float a) 120 | { 121 | return (1.0f/6.0f)*(a*a*(3.0f*a - 6.0f) + 4.0f); 122 | } 123 | 124 | float BakeryBicubic_w2(float a) 125 | { 126 | return (1.0f/6.0f)*(a*(a*(-3.0f*a + 3.0f) + 3.0f) + 1.0f); 127 | } 128 | 129 | float BakeryBicubic_w3(float a) 130 | { 131 | return (1.0f/6.0f)*(a*a*a); 132 | } 133 | 134 | float BakeryBicubic_g0(float a) 135 | { 136 | return BakeryBicubic_w0(a) + BakeryBicubic_w1(a); 137 | } 138 | 139 | float BakeryBicubic_g1(float a) 140 | { 141 | return BakeryBicubic_w2(a) + BakeryBicubic_w3(a); 142 | } 143 | 144 | float BakeryBicubic_h0(float a) 145 | { 146 | return -1.0f + BakeryBicubic_w1(a) / (BakeryBicubic_w0(a) + BakeryBicubic_w1(a)) + 0.5f; 147 | } 148 | 149 | float BakeryBicubic_h1(float a) 150 | { 151 | return 1.0f + BakeryBicubic_w3(a) / (BakeryBicubic_w2(a) + BakeryBicubic_w3(a)) + 0.5f; 152 | } 153 | #endif 154 | 155 | #if defined(BAKERY_RNM) || defined(BAKERY_SH) 156 | sampler2D _RNM0, _RNM1, _RNM2; 157 | float4 _RNM0_TexelSize; 158 | #endif 159 | 160 | // Decodes HDR textures 161 | // handles dLDR, RGBM formats 162 | inline half3 DecodeHDR (half4 data, half4 decodeInstructions) 163 | { 164 | // Take into account texture alpha if decodeInstructions.w is true(the alpha value affects the RGB channels) 165 | half alpha = decodeInstructions.w * (data.a - 1.0) + 1.0; 166 | 167 | // If Linear mode is not supported we can skip exponent part 168 | #if defined(UNITY_COLORSPACE_GAMMA) 169 | return (decodeInstructions.x * alpha) * data.rgb; 170 | #else 171 | # if defined(UNITY_USE_NATIVE_HDR) 172 | return decodeInstructions.x * data.rgb; // Multiplier for future HDRI relative to absolute conversion. 173 | # else 174 | return (decodeInstructions.x * pow(alpha, decodeInstructions.y)) * data.rgb; 175 | # endif 176 | #endif 177 | } 178 | 179 | // Decodes HDR textures 180 | // handles dLDR, RGBM formats 181 | // Called by DecodeLightmap when UNITY_NO_RGBM is not defined. 182 | inline half3 DecodeLightmapRGBM (half4 data, half4 decodeInstructions) 183 | { 184 | // If Linear mode is not supported we can skip exponent part 185 | #if defined(UNITY_COLORSPACE_GAMMA) 186 | # if defined(UNITY_FORCE_LINEAR_READ_FOR_RGBM) 187 | return (decodeInstructions.x * data.a) * sqrt(data.rgb); 188 | # else 189 | return (decodeInstructions.x * data.a) * data.rgb; 190 | # endif 191 | #else 192 | return (decodeInstructions.x * pow(data.a, decodeInstructions.y)) * data.rgb; 193 | #endif 194 | } 195 | 196 | // Decodes doubleLDR encoded lightmaps. 197 | inline half3 DecodeLightmapDoubleLDR( float4 color, half4 decodeInstructions) 198 | { 199 | // decodeInstructions.x contains 2.0 when gamma color space is used or pow(2.0, 2.2) = 4.59 when linear color space is used on mobile platforms 200 | return decodeInstructions.x * color.rgb; 201 | } 202 | 203 | inline half3 DecodeLightmap( float4 color) 204 | { 205 | #ifdef UNITY_LIGHTMAP_FULL_HDR 206 | bool useRGBMLightmap = false; 207 | float4 decodeInstructions = float4(0.0, 0.0, 0.0, 0.0); // Never used but needed for the interface since it supports gamma lightmaps 208 | #else 209 | bool useRGBMLightmap = true; 210 | #if defined(UNITY_LIGHTMAP_RGBM_ENCODING) 211 | float4 decodeInstructions = float4(34.493242, 2.2, 0.0, 0.0); // range^2.2 = 5^2.2, gamma = 2.2 212 | #else 213 | float4 decodeInstructions = float4(2.0, 2.2, 0.0, 0.0); // range = 2.0^2.2 = 4.59 214 | #endif 215 | #endif 216 | 217 | #if defined(UNITY_LIGHTMAP_DLDR_ENCODING) 218 | return DecodeLightmapDoubleLDR(color, decodeInstructions); 219 | #elif defined(UNITY_LIGHTMAP_RGBM_ENCODING) 220 | return DecodeLightmapRGBM(color, decodeInstructions); 221 | #else //defined(UNITY_LIGHTMAP_FULL_HDR) 222 | return color.rgb; 223 | #endif 224 | } 225 | 226 | #ifdef BAKERY_BICUBIC 227 | // Bicubic 228 | float4 BakeryTex2D(sampler2D tex, float2 uv, float4 texelSize) 229 | { 230 | float x = uv.x * texelSize.z; 231 | float y = uv.y * texelSize.z; 232 | 233 | x -= 0.5f; 234 | y -= 0.5f; 235 | 236 | float px = floor(x); 237 | float py = floor(y); 238 | 239 | float fx = x - px; 240 | float fy = y - py; 241 | 242 | float g0x = BakeryBicubic_g0(fx); 243 | float g1x = BakeryBicubic_g1(fx); 244 | float h0x = BakeryBicubic_h0(fx); 245 | float h1x = BakeryBicubic_h1(fx); 246 | float h0y = BakeryBicubic_h0(fy); 247 | float h1y = BakeryBicubic_h1(fy); 248 | 249 | return BakeryBicubic_g0(fy) * ( g0x * tex2D(tex, (float2(px + h0x, py + h0y) * texelSize.x)) + 250 | g1x * tex2D(tex, (float2(px + h1x, py + h0y) * texelSize.x))) + 251 | 252 | BakeryBicubic_g1(fy) * ( g0x * tex2D(tex, (float2(px + h0x, py + h1y) * texelSize.x)) + 253 | g1x * tex2D(tex, (float2(px + h1x, py + h1y) * texelSize.x))); 254 | } 255 | float4 BakeryTex2D(Texture2D tex, SamplerState s, float2 uv, float4 texelSize) 256 | { 257 | float x = uv.x * texelSize.z; 258 | float y = uv.y * texelSize.z; 259 | 260 | x -= 0.5f; 261 | y -= 0.5f; 262 | 263 | float px = floor(x); 264 | float py = floor(y); 265 | 266 | float fx = x - px; 267 | float fy = y - py; 268 | 269 | float g0x = BakeryBicubic_g0(fx); 270 | float g1x = BakeryBicubic_g1(fx); 271 | float h0x = BakeryBicubic_h0(fx); 272 | float h1x = BakeryBicubic_h1(fx); 273 | float h0y = BakeryBicubic_h0(fy); 274 | float h1y = BakeryBicubic_h1(fy); 275 | 276 | return BakeryBicubic_g0(fy) * ( g0x * tex.Sample(s, (float2(px + h0x, py + h0y) * texelSize.x)) + 277 | g1x * tex.Sample(s, (float2(px + h1x, py + h0y) * texelSize.x))) + 278 | 279 | BakeryBicubic_g1(fy) * ( g0x * tex.Sample(s, (float2(px + h0x, py + h1y) * texelSize.x)) + 280 | g1x * tex.Sample(s, (float2(px + h1x, py + h1y) * texelSize.x))); 281 | } 282 | #else 283 | // Bilinear 284 | float4 BakeryTex2D(sampler2D tex, float2 uv, float4 texelSize) 285 | { 286 | return tex2D(tex, uv); 287 | } 288 | float4 BakeryTex2D(Texture2D tex, SamplerState s, float2 uv, float4 texelSize) 289 | { 290 | return tex.Sample(s, uv); 291 | } 292 | #endif 293 | 294 | #ifdef DIRLIGHTMAP_COMBINED 295 | #ifdef BAKERY_LMSPEC 296 | float BakeryDirectionalLightmapSpecular(float2 lmUV, float3 normalWorld, float3 viewDir, float smoothness) 297 | { 298 | float3 dominantDir = UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd, unity_Lightmap, lmUV).xyz * 2 - 1; 299 | half3 halfDir = Unity_SafeNormalize(normalize(dominantDir) - viewDir); 300 | half nh = saturate(dot(normalWorld, halfDir)); 301 | half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness); 302 | half roughness = PerceptualRoughnessToRoughness(perceptualRoughness); 303 | half spec = GGXTerm(nh, roughness); 304 | return spec; 305 | } 306 | #endif 307 | #endif 308 | 309 | #ifdef BAKERY_RNM 310 | void BakeryRNM(inout float3 diffuseColor, inout float3 specularColor, float2 lmUV, float3 normalMap, float smoothness, float3 viewDirT) 311 | { 312 | const float3 rnmBasis0 = float3(0.816496580927726f, 0, 0.5773502691896258f); 313 | const float3 rnmBasis1 = float3(-0.4082482904638631f, 0.7071067811865475f, 0.5773502691896258f); 314 | const float3 rnmBasis2 = float3(-0.4082482904638631f, -0.7071067811865475f, 0.5773502691896258f); 315 | 316 | float3 rnm0 = c(BakeryTex2D(_RNM0, lmUV, _RNM0_TexelSize)); 317 | float3 rnm1 = DecodeLightmap(BakeryTex2D(_RNM1, lmUV, _RNM0_TexelSize)); 318 | float3 rnm2 = DecodeLightmap(BakeryTex2D(_RNM2, lmUV, _RNM0_TexelSize)); 319 | 320 | #ifdef BAKERY_SSBUMP 321 | diffuseColor = normalMap.x * rnm0 322 | + normalMap.z * rnm1 323 | + normalMap.y * rnm2; 324 | #else 325 | diffuseColor = saturate(dot(rnmBasis0, normalMap)) * rnm0 326 | + saturate(dot(rnmBasis1, normalMap)) * rnm1 327 | + saturate(dot(rnmBasis2, normalMap)) * rnm2; 328 | #endif 329 | 330 | #ifdef BAKERY_LMSPEC 331 | float3 dominantDirT = rnmBasis0 * dot(rnm0, lumaConv) + 332 | rnmBasis1 * dot(rnm1, lumaConv) + 333 | rnmBasis2 * dot(rnm2, lumaConv); 334 | 335 | float3 dominantDirTN = NormalizePerPixelNormal(dominantDirT); 336 | float3 specColor = saturate(dot(rnmBasis0, dominantDirTN)) * rnm0 + 337 | saturate(dot(rnmBasis1, dominantDirTN)) * rnm1 + 338 | saturate(dot(rnmBasis2, dominantDirTN)) * rnm2; 339 | 340 | half3 halfDir = Unity_SafeNormalize(dominantDirTN - viewDirT); 341 | half nh = saturate(dot(normalMap, halfDir)); 342 | half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness); 343 | half roughness = PerceptualRoughnessToRoughness(perceptualRoughness); 344 | half spec = GGXTerm(nh, roughness); 345 | specularColor = spec * specColor; 346 | #endif 347 | } 348 | #endif 349 | 350 | #ifdef BAKERY_SH 351 | void BakerySH(inout float3 diffuseColor, inout float3 specularColor, float2 lmUV, float3 normalWorld, float3 viewDir, float smoothness) 352 | { 353 | float3 L0 = DecodeLightmap(BakeryTex2D(unity_Lightmap, samplerunity_Lightmap, lmUV, _RNM0_TexelSize)); 354 | float3 nL1x = BakeryTex2D(_RNM0, lmUV, _RNM0_TexelSize) * 2 - 1; 355 | float3 nL1y = BakeryTex2D(_RNM1, lmUV, _RNM0_TexelSize) * 2 - 1; 356 | float3 nL1z = BakeryTex2D(_RNM2, lmUV, _RNM0_TexelSize) * 2 - 1; 357 | float3 L1x = nL1x * L0 * 2; 358 | float3 L1y = nL1y * L0 * 2; 359 | float3 L1z = nL1z * L0 * 2; 360 | 361 | float3 sh; 362 | //sh.r = shEvaluateDiffuseL1Geomerics(L0.r, float3(L1x.r, L1y.r, L1z.r), normalWorld); 363 | //sh.g = shEvaluateDiffuseL1Geomerics(L0.g, float3(L1x.g, L1y.g, L1z.g), normalWorld); 364 | //sh.b = shEvaluateDiffuseL1Geomerics(L0.b, float3(L1x.b, L1y.b, L1z.b), normalWorld); 365 | 366 | float lumaL0 = dot(L0, lumaConv); 367 | float lumaL1x = dot(L1x, lumaConv); 368 | float lumaL1y = dot(L1y, lumaConv); 369 | float lumaL1z = dot(L1z, lumaConv); 370 | float lumaSH = shEvaluateDiffuseL1Geomerics(lumaL0, float3(lumaL1x, lumaL1y, lumaL1z), normalWorld); 371 | 372 | sh = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; 373 | float regularLumaSH = dot(sh, lumaConv); 374 | //sh *= regularLumaSH < 0.001 ? 1 : (lumaSH / regularLumaSH); 375 | sh *= lerp(1, lumaSH / regularLumaSH, saturate(regularLumaSH*16)); 376 | 377 | diffuseColor = max(sh,0.0); 378 | 379 | #ifdef BAKERY_LMSPEC 380 | float3 dominantDir = float3(dot(nL1x, lumaConv), dot(nL1y, lumaConv), dot(nL1z, lumaConv)); 381 | float focus = saturate(length(dominantDir)); 382 | half3 halfDir = Unity_SafeNormalize(normalize(dominantDir) - viewDir); 383 | half nh = saturate(dot(normalWorld, halfDir)); 384 | half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness );//* sqrt(focus)); 385 | half roughness = PerceptualRoughnessToRoughness(perceptualRoughness); 386 | half spec = GGXTerm(nh, roughness); 387 | 388 | //sh.r = shEvaluateDiffuseL1Geomerics(L0.r, float3(L1x.r, L1y.r, L1z.r), dominantDir); 389 | //sh.g = shEvaluateDiffuseL1Geomerics(L0.g, float3(L1x.g, L1y.g, L1z.g), dominantDir); 390 | //sh.b = shEvaluateDiffuseL1Geomerics(L0.b, float3(L1x.b, L1y.b, L1z.b), dominantDir); 391 | 392 | specularColor = spec * sh; 393 | #endif 394 | } 395 | #endif 396 | 397 | #endif 398 | -------------------------------------------------------------------------------- /BakeryHDRP_Forward.hlsl: -------------------------------------------------------------------------------- 1 | #if SHADERPASS != SHADERPASS_FORWARD 2 | #error SHADERPASS_is_not_correctly_define 3 | #endif 4 | 5 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl" 6 | #include "BakeryHDRP.hlsl" 7 | 8 | PackedVaryingsType Vert(AttributesMesh inputMesh) 9 | { 10 | VaryingsType varyingsType; 11 | varyingsType.vmesh = VertMesh(inputMesh); 12 | return PackVaryingsType(varyingsType); 13 | } 14 | 15 | #ifdef TESSELLATION_ON 16 | 17 | PackedVaryingsToPS VertTesselation(VaryingsToDS input) 18 | { 19 | VaryingsToPS output; 20 | output.vmesh = VertMeshTesselation(input.vmesh); 21 | return PackVaryingsToPS(output); 22 | } 23 | 24 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl" 25 | 26 | #endif // TESSELLATION_ON 27 | 28 | void Frag(PackedVaryingsToPS packedInput, 29 | #ifdef OUTPUT_SPLIT_LIGHTING 30 | out float4 outColor : SV_Target0, // outSpecularLighting 31 | out float4 outDiffuseLighting : SV_Target1, 32 | OUTPUT_SSSBUFFER(outSSSBuffer) 33 | #else 34 | out float4 outColor : SV_Target0 35 | #endif 36 | #ifdef _DEPTHOFFSET_ON 37 | , out float outputDepth : SV_Depth 38 | #endif 39 | ) 40 | { 41 | FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh); 42 | 43 | uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); 44 | #if defined(UNITY_SINGLE_PASS_STEREO) 45 | tileIndex.x -= unity_StereoEyeIndex * _NumTileClusteredX; 46 | #endif 47 | 48 | // input.positionSS is SV_Position 49 | PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); 50 | 51 | #ifdef VARYINGS_NEED_POSITION_WS 52 | float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); 53 | #else 54 | // Unused 55 | float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0 56 | #endif 57 | 58 | SurfaceData surfaceData; 59 | BuiltinData builtinData; 60 | GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData); 61 | 62 | BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); 63 | 64 | PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); 65 | 66 | outColor = float4(0.0, 0.0, 0.0, 0.0); 67 | 68 | // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. 69 | #ifdef DEBUG_DISPLAY 70 | // Init in debug display mode to quiet warning 71 | #ifdef OUTPUT_SPLIT_LIGHTING 72 | outDiffuseLighting = 0; 73 | ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); 74 | #endif 75 | 76 | // Same code in ShaderPassForwardUnlit.shader 77 | if (_DebugViewMaterial != 0) 78 | { 79 | float3 result = float3(1.0, 0.0, 1.0); 80 | 81 | bool needLinearToSRGB = false; 82 | 83 | GetPropertiesDataDebug(_DebugViewMaterial, result, needLinearToSRGB); 84 | GetVaryingsDataDebug(_DebugViewMaterial, input, result, needLinearToSRGB); 85 | GetBuiltinDataDebug(_DebugViewMaterial, builtinData, result, needLinearToSRGB); 86 | GetSurfaceDataDebug(_DebugViewMaterial, surfaceData, result, needLinearToSRGB); 87 | GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB); 88 | 89 | // TEMP! 90 | // For now, the final blit in the backbuffer performs an sRGB write 91 | // So in the meantime we apply the inverse transform to linear data to compensate. 92 | if (!needLinearToSRGB) 93 | result = SRGBToLinear(max(0, result)); 94 | 95 | outColor = float4(result, 1.0); 96 | } 97 | else 98 | #endif 99 | { 100 | #ifdef _SURFACE_TYPE_TRANSPARENT 101 | uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; 102 | #else 103 | uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; 104 | #endif 105 | float3 diffuseLighting; 106 | float3 specularLighting; 107 | 108 | #ifdef BAKERY_SH 109 | if (bakeryLightmapMode == BAKERYMODE_SH) 110 | { 111 | float3 indirectSpecular = 0; 112 | BakerySH(builtinData.bakeDiffuseLighting, indirectSpecular, input.texCoord1 * unity_LightmapST.xy + unity_LightmapST.zw, surfaceData.normalWS, 0, 0); 113 | builtinData.bakeDiffuseLighting = max(builtinData.bakeDiffuseLighting * surfaceData.baseColor, 0); 114 | } 115 | #endif 116 | 117 | LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting); 118 | 119 | #ifdef OUTPUT_SPLIT_LIGHTING 120 | if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) 121 | { 122 | outColor = float4(specularLighting, 1.0); 123 | outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); 124 | } 125 | else 126 | { 127 | outColor = float4(diffuseLighting + specularLighting, 1.0); 128 | outDiffuseLighting = 0; 129 | } 130 | ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); 131 | #else 132 | outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); 133 | outColor = EvaluateAtmosphericScattering(posInput, V, outColor); 134 | #endif 135 | } 136 | 137 | #ifdef _DEPTHOFFSET_ON 138 | outputDepth = posInput.deviceDepth; 139 | #endif 140 | } 141 | -------------------------------------------------------------------------------- /BakeryHDRP_GBuffer.hlsl: -------------------------------------------------------------------------------- 1 | #if SHADERPASS != SHADERPASS_GBUFFER 2 | #error SHADERPASS_is_not_correctly_define 3 | #endif 4 | 5 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl" 6 | #include "BakeryHDRP.hlsl" 7 | 8 | PackedVaryingsType Vert(AttributesMesh inputMesh) 9 | { 10 | VaryingsType varyingsType; 11 | varyingsType.vmesh = VertMesh(inputMesh); 12 | return PackVaryingsType(varyingsType); 13 | } 14 | 15 | #ifdef TESSELLATION_ON 16 | 17 | PackedVaryingsToPS VertTesselation(VaryingsToDS input) 18 | { 19 | VaryingsToPS output; 20 | output.vmesh = VertMeshTesselation(input.vmesh); 21 | return PackVaryingsToPS(output); 22 | } 23 | 24 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl" 25 | 26 | #endif // TESSELLATION_ON 27 | 28 | void Frag( PackedVaryingsToPS packedInput, 29 | OUTPUT_GBUFFER(outGBuffer) 30 | #ifdef _DEPTHOFFSET_ON 31 | , out float outputDepth : SV_Depth 32 | #endif 33 | ) 34 | { 35 | FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh); 36 | 37 | // input.positionSS is SV_Position 38 | PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); 39 | 40 | #ifdef VARYINGS_NEED_POSITION_WS 41 | float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); 42 | #else 43 | // Unused 44 | float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0 45 | #endif 46 | 47 | SurfaceData surfaceData; 48 | BuiltinData builtinData; 49 | GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData); 50 | 51 | #ifdef BAKERY_SH 52 | if (bakeryLightmapMode == BAKERYMODE_SH) 53 | { 54 | float3 indirectSpecular = 0; 55 | BakerySH(builtinData.bakeDiffuseLighting, indirectSpecular, input.texCoord1 * unity_LightmapST.xy + unity_LightmapST.zw, surfaceData.normalWS, 0, 0); 56 | builtinData.bakeDiffuseLighting = max(builtinData.bakeDiffuseLighting * surfaceData.baseColor, 0); 57 | builtinData.backBakeDiffuseLighting = builtinData.bakeDiffuseLighting; 58 | } 59 | #endif 60 | 61 | ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); 62 | 63 | #ifdef _DEPTHOFFSET_ON 64 | outputDepth = posInput.deviceDepth; 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /BakeryLitHDRP.shader: -------------------------------------------------------------------------------- 1 | Shader "HDRenderPipeline/Bakery Lit" 2 | { 3 | Properties 4 | { 5 | // Versioning of material to help for upgrading 6 | [HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2 7 | 8 | // Following set of parameters represent the parameters node inside the MaterialGraph. 9 | // They are use to fill a SurfaceData. With a MaterialGraph this should not exist. 10 | 11 | // Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear 12 | _BaseColor("BaseColor", Color) = (1,1,1,1) 13 | _BaseColorMap("BaseColorMap", 2D) = "white" {} 14 | [HideInInspector] _BaseColorMap_MipInfo("_BaseColorMap_MipInfo", Vector) = (0, 0, 0, 0) 15 | 16 | _Metallic("_Metallic", Range(0.0, 1.0)) = 0 17 | _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 18 | _MaskMap("MaskMap", 2D) = "white" {} 19 | _SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0 20 | _SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0 21 | _AORemapMin("AORemapMin", Float) = 0.0 22 | _AORemapMax("AORemapMax", Float) = 1.0 23 | 24 | _NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map 25 | _NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value 26 | _NormalScale("_NormalScale", Range(0.0, 8.0)) = 1 27 | 28 | _BentNormalMap("_BentNormalMap", 2D) = "bump" {} 29 | _BentNormalMapOS("_BentNormalMapOS", 2D) = "white" {} 30 | 31 | _HeightMap("HeightMap", 2D) = "black" {} 32 | // Caution: Default value of _HeightAmplitude must be (_HeightMax - _HeightMin) * 0.01 33 | // Those two properties are computed from the ones exposed in the UI and depends on the displaement mode so they are separate because we don't want to lose information upon displacement mode change. 34 | [HideInInspector] _HeightAmplitude("Height Amplitude", Float) = 0.02 // In world units. This will be computed in the UI. 35 | [HideInInspector] _HeightCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space 36 | 37 | [Enum(MinMax, 0, Amplitude, 1)] _HeightMapParametrization("Heightmap Parametrization", Int) = 0 38 | // These parameters are for vertex displacement/Tessellation 39 | _HeightOffset("Height Offset", Float) = 0 40 | // MinMax mode 41 | _HeightMin("Heightmap Min", Float) = -1 42 | _HeightMax("Heightmap Max", Float) = 1 43 | // Amplitude mode 44 | _HeightTessAmplitude("Amplitude", Float) = 2.0 // in Centimeters 45 | _HeightTessCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space 46 | 47 | // These parameters are for pixel displacement 48 | _HeightPoMAmplitude("Height Amplitude", Float) = 2.0 // In centimeters 49 | 50 | _DetailMap("DetailMap", 2D) = "black" {} 51 | _DetailAlbedoScale("_DetailAlbedoScale", Range(0.0, 2.0)) = 1 52 | _DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1 53 | _DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1 54 | 55 | _TangentMap("TangentMap", 2D) = "bump" {} 56 | _TangentMapOS("TangentMapOS", 2D) = "white" {} 57 | _Anisotropy("Anisotropy", Range(-1.0, 1.0)) = 0 58 | _AnisotropyMap("AnisotropyMap", 2D) = "white" {} 59 | 60 | _SubsurfaceMask("Subsurface Radius", Range(0.0, 1.0)) = 1.0 61 | _SubsurfaceMaskMap("Subsurface Radius Map", 2D) = "white" {} 62 | _Thickness("Thickness", Range(0.0, 1.0)) = 1.0 63 | _ThicknessMap("Thickness Map", 2D) = "white" {} 64 | _ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0) 65 | 66 | _IridescenceThickness("Iridescence Thickness", Range(0.0, 1.0)) = 1.0 67 | _IridescenceThicknessMap("Iridescence Thickness Map", 2D) = "white" {} 68 | _IridescenceThicknessRemap("Iridescence Thickness Remap", Vector) = (0, 1, 0, 0) 69 | _IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0 70 | _IridescenceMaskMap("Iridescence Mask Map", 2D) = "white" {} 71 | 72 | _CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0 73 | _CoatMaskMap("CoatMaskMap", 2D) = "white" {} 74 | 75 | [ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0 76 | _SpecularColor("SpecularColor", Color) = (1, 1, 1, 1) 77 | _SpecularColorMap("SpecularColorMap", 2D) = "white" {} 78 | 79 | // Following options are for the GUI inspector and different from the input parameters above 80 | // These option below will cause different compilation flag. 81 | [ToggleUI] _EnableSpecularOcclusion("Enable specular occlusion", Float) = 0.0 82 | 83 | [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) 84 | // Used only to serialize the LDR and HDR emissive color in the material UI, 85 | // in the shader only the _EmissiveColor should be used 86 | [HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0) 87 | _EmissiveColorMap("EmissiveColorMap", 2D) = "white" {} 88 | [ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0 89 | [HideInInspector] _EmissiveIntensityUnit("Emissive Mode", Int) = 0 90 | [ToggleUI] _UseEmissiveIntensity("Use Emissive Intensity", Int) = 0 91 | _EmissiveIntensity("Emissive Intensity", Float) = 1 92 | _EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0 93 | 94 | _DistortionVectorMap("DistortionVectorMap", 2D) = "black" {} 95 | [ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0 96 | [ToggleUI] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 1.0 97 | [Enum(Add, 0, Multiply, 1, Replace, 2)] _DistortionBlendMode("Distortion Blend Mode", Int) = 0 98 | [HideInInspector] _DistortionSrcBlend("Distortion Blend Src", Int) = 0 99 | [HideInInspector] _DistortionDstBlend("Distortion Blend Dst", Int) = 0 100 | [HideInInspector] _DistortionBlurSrcBlend("Distortion Blur Blend Src", Int) = 0 101 | [HideInInspector] _DistortionBlurDstBlend("Distortion Blur Blend Dst", Int) = 0 102 | [HideInInspector] _DistortionBlurBlendMode("Distortion Blur Blend Mode", Int) = 0 103 | _DistortionScale("Distortion Scale", Float) = 1 104 | _DistortionVectorScale("Distortion Vector Scale", Float) = 2 105 | _DistortionVectorBias("Distortion Vector Bias", Float) = -1 106 | _DistortionBlurScale("Distortion Blur Scale", Float) = 1 107 | _DistortionBlurRemapMin("DistortionBlurRemapMin", Float) = 0.0 108 | _DistortionBlurRemapMax("DistortionBlurRemapMax", Float) = 1.0 109 | 110 | 111 | [ToggleUI] _UseShadowThreshold("_UseShadowThreshold", Float) = 0.0 112 | [ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 113 | _AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 114 | _AlphaCutoffShadow("_AlphaCutoffShadow", Range(0.0, 1.0)) = 0.5 115 | _AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5 116 | _AlphaCutoffPostpass("_AlphaCutoffPostpass", Range(0.0, 1.0)) = 0.5 117 | [ToggleUI] _TransparentDepthPrepassEnable("_TransparentDepthPrepassEnable", Float) = 0.0 118 | [ToggleUI] _TransparentBackfaceEnable("_TransparentBackfaceEnable", Float) = 0.0 119 | [ToggleUI] _TransparentDepthPostpassEnable("_TransparentDepthPostpassEnable", Float) = 0.0 120 | _TransparentSortPriority("_TransparentSortPriority", Float) = 0 121 | 122 | // Transparency 123 | [Enum(None, 0, Box, 1, Sphere, 2)]_RefractionModel("Refraction Model", Int) = 0 124 | [Enum(Proxy, 1, HiZ, 2)]_SSRefractionProjectionModel("Refraction Projection Model", Int) = 0 125 | _Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0 126 | _ThicknessMultiplier("Thickness Multiplier", Float) = 1.0 127 | _TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0) 128 | _TransmittanceColorMap("TransmittanceColorMap", 2D) = "white" {} 129 | _ATDistance("Transmittance Absorption Distance", Float) = 1.0 130 | [ToggleUI] _TransparentWritingMotionVec("_TransparentWritingMotionVec", Float) = 0.0 131 | 132 | // Stencil state 133 | 134 | // Forward 135 | [HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting 136 | [HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 3 // StencilMask.Lighting 137 | // GBuffer 138 | [HideInInspector] _StencilRefGBuffer("_StencilRefGBuffer", Int) = 2 // StencilLightingUsage.RegularLighting 139 | [HideInInspector] _StencilWriteMaskGBuffer("_StencilWriteMaskGBuffer", Int) = 3 // StencilMask.Lighting 140 | // Depth prepass 141 | [HideInInspector] _StencilRefDepth("_StencilRefDepth", Int) = 0 // Nothing 142 | [HideInInspector] _StencilWriteMaskDepth("_StencilWriteMaskDepth", Int) = 32 // DoesntReceiveSSR 143 | // Motion vector pass 144 | [HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilBitMask.ObjectMotionVectors 145 | [HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilBitMask.ObjectMotionVectors 146 | // Distortion vector pass 147 | [HideInInspector] _StencilRefDistortionVec("_StencilRefDistortionVec", Int) = 64 // StencilBitMask.DistortionVectors 148 | [HideInInspector] _StencilWriteMaskDistortionVec("_StencilWriteMaskDistortionVec", Int) = 64 // StencilBitMask.DistortionVectors 149 | 150 | // Blending state 151 | [HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 152 | [HideInInspector] _BlendMode("__blendmode", Float) = 0.0 153 | [HideInInspector] _SrcBlend("__src", Float) = 1.0 154 | [HideInInspector] _DstBlend("__dst", Float) = 0.0 155 | [HideInInspector] _AlphaSrcBlend("__alphaSrc", Float) = 1.0 156 | [HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0 157 | [HideInInspector] _ZWrite("__zw", Float) = 1.0 158 | [HideInInspector] _CullMode("__cullmode", Float) = 2.0 159 | [HideInInspector] _CullModeForward("__cullmodeForward", Float) = 2.0 // This mode is dedicated to Forward to correctly handle backface then front face rendering thin transparent 160 | [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal 161 | [HideInInspector] _ZTestModeDistortion("_ZTestModeDistortion", Int) = 8 162 | [HideInInspector] _ZTestGBuffer("_ZTestGBuffer", Int) = 4 163 | 164 | [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 165 | [ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 166 | 167 | [ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0 168 | [Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 169 | [HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0) 170 | 171 | [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase("UV Set for base", Float) = 0 172 | _TexWorldScale("Scale to apply on world coordinate", Float) = 1.0 173 | [HideInInspector] _InvTilingScale("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Float) = 1 174 | [HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0) 175 | [Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 176 | 177 | // Following enum should be material feature flags (i.e bitfield), however due to Gbuffer encoding constrain many combination exclude each other 178 | // so we use this enum as "material ID" which can be interpreted as preset of bitfield of material feature 179 | // The only material feature flag that can be added in all cases is clear coat 180 | [Enum(Subsurface Scattering, 0, Standard, 1, Anisotropy, 2, Iridescence, 3, Specular Color, 4, Translucent, 5)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard 181 | [ToggleUI] _TransmissionEnable("_TransmissionEnable", Float) = 1.0 182 | 183 | [Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0 184 | [ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0 185 | [ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0 186 | [ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0 187 | 188 | [ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0 189 | _SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1 190 | _SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2 191 | 192 | [ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0 193 | 194 | _PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5 195 | _PPDMaxSamples("Max sample for POM", Range(1.0, 64.0)) = 15 196 | _PPDLodThreshold("Start lod to fade out the POM effect", Range(0.0, 16.0)) = 5 197 | _PPDPrimitiveLength("Primitive length for POM", Float) = 1 198 | _PPDPrimitiveWidth("Primitive width for POM", Float) = 1 199 | [HideInInspector] _InvPrimScale("Inverse primitive scale for non-planar POM", Vector) = (1, 1, 0, 0) 200 | 201 | [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail("UV Set for detail", Float) = 0 202 | [HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0) 203 | [ToggleUI] _LinkDetailsWithBase("LinkDetailsWithBase", Float) = 1.0 204 | 205 | [Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 206 | [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVEmissive("UV Set for emissive", Float) = 0 207 | _TexWorldScaleEmissive("Scale to apply on world coordinate", Float) = 1.0 208 | [HideInInspector] _UVMappingMaskEmissive("_UVMappingMaskEmissive", Color) = (1, 0, 0, 0) 209 | 210 | // Wind 211 | [ToggleUI] _EnableWind("Enable Wind", Float) = 0.0 212 | _InitialBend("Initial Bend", float) = 1.0 213 | _Stiffness("Stiffness", float) = 1.0 214 | _Drag("Drag", float) = 1.0 215 | _ShiverDrag("Shiver Drag", float) = 0.2 216 | _ShiverDirectionality("Shiver Directionality", Range(0.0, 1.0)) = 0.5 217 | 218 | // Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" 219 | // value that exist to identify if the GI emission need to be enabled. 220 | // In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. 221 | // TODO: Fix the code in legacy unity so we can customize the beahvior for GI 222 | _EmissionColor("Color", Color) = (1, 1, 1) 223 | 224 | // HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes. 225 | _MainTex("Albedo", 2D) = "white" {} 226 | _Color("Color", Color) = (1,1,1,1) 227 | _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 228 | 229 | [ToggleUI] _SupportDecals("Support Decals", Float) = 1.0 230 | [ToggleUI] _ReceivesSSR("Receives SSR", Float) = 1.0 231 | 232 | [HideInInspector] _DiffusionProfile("Obsolete, kept for migration purpose", Int) = 0 233 | [HideInInspector] _DiffusionProfileAsset("Diffusion Profile Asset", Vector) = (0, 0, 0, 0) 234 | [HideInInspector] _DiffusionProfileHash("Diffusion Profile Hash", Float) = 0 235 | 236 | //[Toggle(BAKERY_SH)] _BAKERY_SH ("Enable SH", Float) = 0 237 | } 238 | 239 | HLSLINCLUDE 240 | 241 | #pragma target 4.5 242 | #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch 243 | 244 | //------------------------------------------------------------------------------------- 245 | // Variant 246 | //------------------------------------------------------------------------------------- 247 | 248 | #pragma shader_feature _ALPHATEST_ON 249 | #pragma shader_feature _DEPTHOFFSET_ON 250 | #pragma shader_feature _DOUBLESIDED_ON 251 | #pragma shader_feature _ _VERTEX_DISPLACEMENT _PIXEL_DISPLACEMENT 252 | #pragma shader_feature _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE 253 | #pragma shader_feature _DISPLACEMENT_LOCK_TILING_SCALE 254 | #pragma shader_feature _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE 255 | #pragma shader_feature _VERTEX_WIND 256 | #pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE 257 | 258 | #pragma shader_feature _ _EMISSIVE_MAPPING_PLANAR _EMISSIVE_MAPPING_TRIPLANAR 259 | #pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR 260 | #pragma shader_feature _NORMALMAP_TANGENT_SPACE 261 | #pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3 262 | 263 | #pragma shader_feature _NORMALMAP 264 | #pragma shader_feature _MASKMAP 265 | #pragma shader_feature _BENTNORMALMAP 266 | #pragma shader_feature _EMISSIVE_COLOR_MAP 267 | #pragma shader_feature _ENABLESPECULAROCCLUSION 268 | #pragma shader_feature _HEIGHTMAP 269 | #pragma shader_feature _TANGENTMAP 270 | #pragma shader_feature _ANISOTROPYMAP 271 | #pragma shader_feature _DETAIL_MAP 272 | #pragma shader_feature _SUBSURFACE_MASK_MAP 273 | #pragma shader_feature _THICKNESSMAP 274 | #pragma shader_feature _IRIDESCENCE_THICKNESSMAP 275 | #pragma shader_feature _SPECULARCOLORMAP 276 | #pragma shader_feature _TRANSMITTANCECOLORMAP 277 | 278 | #pragma shader_feature _DISABLE_DECALS 279 | #pragma shader_feature _DISABLE_SSR 280 | #pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA 281 | 282 | // Keyword for transparent 283 | #pragma shader_feature _SURFACE_TYPE_TRANSPARENT 284 | #pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY 285 | #pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 286 | #pragma shader_feature _ENABLE_FOG_ON_TRANSPARENT 287 | 288 | // MaterialFeature are used as shader feature to allow compiler to optimize properly 289 | #pragma shader_feature _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 290 | #pragma shader_feature _MATERIAL_FEATURE_TRANSMISSION 291 | #pragma shader_feature _MATERIAL_FEATURE_ANISOTROPY 292 | #pragma shader_feature _MATERIAL_FEATURE_CLEAR_COAT 293 | #pragma shader_feature _MATERIAL_FEATURE_IRIDESCENCE 294 | #pragma shader_feature _MATERIAL_FEATURE_SPECULAR_COLOR 295 | 296 | //#pragma shader_feature BAKERY_SH 297 | #define BAKERY_SH 298 | 299 | // enable dithering LOD crossfade 300 | #pragma multi_compile _ LOD_FADE_CROSSFADE 301 | 302 | //enable GPU instancing support 303 | #pragma multi_compile_instancing 304 | #pragma instancing_options renderinglayer 305 | 306 | //------------------------------------------------------------------------------------- 307 | // Define 308 | //------------------------------------------------------------------------------------- 309 | 310 | // Use surface gradient normal mapping as it handle correctly triplanar normal mapping and multiple UVSet 311 | #define SURFACE_GRADIENT 312 | // This shader support vertex modification 313 | #define HAVE_VERTEX_MODIFICATION 314 | 315 | // If we use subsurface scattering, enable output split lighting (for forward pass) 316 | #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) 317 | #define OUTPUT_SPLIT_LIGHTING 318 | #endif 319 | 320 | //------------------------------------------------------------------------------------- 321 | // Include 322 | //------------------------------------------------------------------------------------- 323 | 324 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 325 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Wind.hlsl" 326 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" 327 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" 328 | // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 329 | 330 | //------------------------------------------------------------------------------------- 331 | // variable declaration 332 | //------------------------------------------------------------------------------------- 333 | 334 | // Can't include 'ShaderVariables.hlsl' here because of USE_LEGACY_UNITY_MATRIX_VARIABLES. :-( 335 | // Same story for 'Material.hlsl' (above) which includes 'AtmosphericScattering.hlsl' which includes 'ShaderVariables.hlsl'. 336 | // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 337 | // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.cs.hlsl" 338 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl" 339 | 340 | // TODO: 341 | // Currently, Lit.hlsl and LitData.hlsl are included for every pass. Split Lit.hlsl in two: 342 | // LitData.hlsl and LitShading.hlsl (merge into the existing LitData.hlsl). 343 | // LitData.hlsl should be responsible for preparing shading parameters. 344 | // LitShading.hlsl implements the light loop API. 345 | // LitData.hlsl is included here, LitShading.hlsl is included below for shading passes only. 346 | 347 | // All our shaders use same name for entry point 348 | #pragma vertex Vert 349 | #pragma fragment Frag 350 | 351 | ENDHLSL 352 | 353 | SubShader 354 | { 355 | // This tags allow to use the shader replacement features 356 | Tags{ "RenderPipeline"="HDRenderPipeline" "RenderType" = "HDLitShader" } 357 | 358 | Pass 359 | { 360 | Name "SceneSelectionPass" // Name is not used 361 | Tags { "LightMode" = "SceneSelectionPass" } 362 | 363 | Cull Off 364 | 365 | HLSLPROGRAM 366 | 367 | // Note: Require _ObjectId and _PassValue variables 368 | 369 | // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation 370 | #define SHADERPASS SHADERPASS_DEPTH_ONLY 371 | #define SCENESELECTIONPASS // This will drive the output of the scene selection shader 372 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 373 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 374 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 375 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" 376 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 377 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" 378 | 379 | ENDHLSL 380 | } 381 | 382 | // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass. 383 | Pass 384 | { 385 | Name "GBuffer" // Name is not used 386 | Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index 387 | 388 | Cull [_CullMode] 389 | ZTest [_ZTestGBuffer] 390 | 391 | Stencil 392 | { 393 | WriteMask [_StencilWriteMask] 394 | Ref [_StencilRef] 395 | Comp Always 396 | Pass Replace 397 | } 398 | 399 | HLSLPROGRAM 400 | 401 | #pragma multi_compile _ DEBUG_DISPLAY 402 | #pragma multi_compile _ LIGHTMAP_ON 403 | #pragma multi_compile _ DIRLIGHTMAP_COMBINED 404 | #pragma multi_compile _ DYNAMICLIGHTMAP_ON 405 | #pragma multi_compile _ SHADOWS_SHADOWMASK 406 | // Setup DECALS_OFF so the shader stripper can remove variants 407 | #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT 408 | #pragma multi_compile _ LIGHT_LAYERS 409 | 410 | #ifdef _ALPHATEST_ON 411 | // When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer 412 | #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST 413 | #endif 414 | 415 | #define SHADERPASS SHADERPASS_GBUFFER 416 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 417 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 418 | #ifdef DEBUG_DISPLAY 419 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" 420 | #endif 421 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 422 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 423 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 424 | 425 | //#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl" 426 | #include "BakeryHDRP_GBuffer.hlsl" 427 | 428 | ENDHLSL 429 | } 430 | 431 | // Extracts information for lightmapping, GI (emission, albedo, ...) 432 | // This pass it not used during regular rendering. 433 | Pass 434 | { 435 | Name "META" 436 | Tags{ "LightMode" = "Meta" } 437 | 438 | Cull Off 439 | 440 | HLSLPROGRAM 441 | 442 | // Lightmap memo 443 | // DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light, 444 | // both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON. 445 | 446 | #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT 447 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 448 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 449 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 450 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 451 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 452 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl" 453 | 454 | ENDHLSL 455 | } 456 | 457 | Pass 458 | { 459 | Name "ShadowCaster" 460 | Tags{ "LightMode" = "ShadowCaster" } 461 | 462 | Cull[_CullMode] 463 | 464 | ZClip [_ZClip] 465 | ZWrite On 466 | ZTest LEqual 467 | 468 | ColorMask 0 469 | 470 | HLSLPROGRAM 471 | 472 | #define SHADERPASS SHADERPASS_SHADOWS 473 | #define USE_LEGACY_UNITY_MATRIX_VARIABLES 474 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 475 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 476 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 477 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" 478 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 479 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" 480 | 481 | ENDHLSL 482 | } 483 | 484 | Pass 485 | { 486 | Name "DepthOnly" 487 | Tags{ "LightMode" = "DepthOnly" } 488 | 489 | Cull[_CullMode] 490 | 491 | // To be able to tag stencil with disableSSR information for forward 492 | Stencil 493 | { 494 | WriteMask [_StencilWriteMask] 495 | Ref [_StencilRef] 496 | Comp Always 497 | Pass Replace 498 | } 499 | 500 | ZWrite On 501 | 502 | HLSLPROGRAM 503 | 504 | // In deferred, depth only pass don't output anything. 505 | // In forward it output the normal buffer 506 | #pragma multi_compile _ WRITE_NORMAL_BUFFER 507 | #pragma multi_compile _ WRITE_MSAA_DEPTH 508 | 509 | #define SHADERPASS SHADERPASS_DEPTH_ONLY 510 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 511 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 512 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 513 | 514 | #ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator 515 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 516 | #else 517 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" 518 | #endif 519 | 520 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 521 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" 522 | 523 | ENDHLSL 524 | } 525 | 526 | Pass 527 | { 528 | Name "Motion Vectors" 529 | Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity) 530 | 531 | // If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity 532 | Stencil 533 | { 534 | WriteMask [_StencilWriteMaskMV] 535 | Ref [_StencilRefMV] 536 | Comp Always 537 | Pass Replace 538 | } 539 | 540 | Cull[_CullMode] 541 | 542 | ZWrite On 543 | 544 | HLSLPROGRAM 545 | #pragma multi_compile _ WRITE_NORMAL_BUFFER 546 | #pragma multi_compile _ WRITE_MSAA_DEPTH 547 | 548 | #define SHADERPASS SHADERPASS_MOTION_VECTORS 549 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 550 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 551 | #ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator 552 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 553 | #else 554 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitMotionVectorPass.hlsl" 555 | #endif 556 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 557 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl" 558 | 559 | #pragma vertex Vert 560 | #pragma fragment Frag 561 | 562 | ENDHLSL 563 | } 564 | 565 | Pass 566 | { 567 | Name "Distortion" // Name is not used 568 | Tags { "LightMode" = "DistortionVectors" } // This will be only for transparent object based on the RenderQueue index 569 | 570 | Blend [_DistortionSrcBlend] [_DistortionDstBlend], [_DistortionBlurSrcBlend] [_DistortionBlurDstBlend] 571 | BlendOp Add, [_DistortionBlurBlendOp] 572 | ZTest [_ZTestModeDistortion] 573 | ZWrite off 574 | Cull [_CullMode] 575 | 576 | HLSLPROGRAM 577 | 578 | #define SHADERPASS SHADERPASS_DISTORTION 579 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 580 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 581 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 582 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDistortionPass.hlsl" 583 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 584 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDistortion.hlsl" 585 | 586 | ENDHLSL 587 | } 588 | 589 | Pass 590 | { 591 | Name "TransparentDepthPrepass" 592 | Tags{ "LightMode" = "TransparentDepthPrepass" } 593 | 594 | Cull[_CullMode] 595 | ZWrite On 596 | ColorMask 0 597 | 598 | HLSLPROGRAM 599 | 600 | #define SHADERPASS SHADERPASS_DEPTH_ONLY 601 | #define CUTOFF_TRANSPARENT_DEPTH_PREPASS 602 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 603 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 604 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 605 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" 606 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 607 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" 608 | 609 | ENDHLSL 610 | } 611 | 612 | // Caution: Order is important: TransparentBackface, then Forward/ForwardOnly 613 | Pass 614 | { 615 | Name "TransparentBackface" 616 | Tags { "LightMode" = "TransparentBackface" } 617 | 618 | Blend [_SrcBlend] [_DstBlend] 619 | ZWrite [_ZWrite] 620 | Cull Front 621 | 622 | HLSLPROGRAM 623 | 624 | #pragma multi_compile _ DEBUG_DISPLAY 625 | #pragma multi_compile _ LIGHTMAP_ON 626 | #pragma multi_compile _ DIRLIGHTMAP_COMBINED 627 | #pragma multi_compile _ DYNAMICLIGHTMAP_ON 628 | #pragma multi_compile _ SHADOWS_SHADOWMASK 629 | // Setup DECALS_OFF so the shader stripper can remove variants 630 | #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT 631 | 632 | // Supported shadow modes per light type 633 | #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH 634 | 635 | // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Lighting/Forward.hlsl" 636 | //#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS 637 | #define LIGHTLOOP_TILE_PASS 638 | #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST 639 | 640 | #define SHADERPASS SHADERPASS_FORWARD 641 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 642 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 643 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" 644 | 645 | #ifdef DEBUG_DISPLAY 646 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" 647 | #endif 648 | 649 | // The light loop (or lighting architecture) is in charge to: 650 | // - Define light list 651 | // - Define the light loop 652 | // - Setup the constant/data 653 | // - Do the reflection hierarchy 654 | // - Provide sampling function for shadowmap, ies, cookie and reflection (depends on the specific use with the light loops like index array or atlas or single and texture format (cubemap/latlong)) 655 | 656 | #define HAS_LIGHTLOOP 657 | 658 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" 659 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 660 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" 661 | 662 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 663 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 664 | //#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl" 665 | #include "BakeryHDRP_Forward.hlsl" 666 | 667 | ENDHLSL 668 | } 669 | 670 | Pass 671 | { 672 | Name "Forward" // Name is not used 673 | Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index 674 | 675 | Stencil 676 | { 677 | WriteMask [_StencilWriteMask] 678 | Ref [_StencilRef] 679 | Comp Always 680 | Pass Replace 681 | } 682 | 683 | Blend [_SrcBlend] [_DstBlend] 684 | // In case of forward we want to have depth equal for opaque mesh 685 | ZTest [_ZTestDepthEqualForOpaque] 686 | ZWrite [_ZWrite] 687 | Cull [_CullModeForward] 688 | 689 | HLSLPROGRAM 690 | 691 | #pragma multi_compile _ DEBUG_DISPLAY 692 | #pragma multi_compile _ LIGHTMAP_ON 693 | #pragma multi_compile _ DIRLIGHTMAP_COMBINED 694 | #pragma multi_compile _ DYNAMICLIGHTMAP_ON 695 | #pragma multi_compile _ SHADOWS_SHADOWMASK 696 | // Setup DECALS_OFF so the shader stripper can remove variants 697 | #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT 698 | 699 | // Supported shadow modes per light type 700 | #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH 701 | 702 | // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Lighting/Forward.hlsl" 703 | //#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS 704 | #define LIGHTLOOP_TILE_PASS 705 | #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST 706 | 707 | #define SHADERPASS SHADERPASS_FORWARD 708 | // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) 709 | #ifndef _SURFACE_TYPE_TRANSPARENT 710 | #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST 711 | #endif 712 | 713 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 714 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" 715 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 716 | 717 | #ifdef DEBUG_DISPLAY 718 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" 719 | #endif 720 | 721 | // The light loop (or lighting architecture) is in charge to: 722 | // - Define light list 723 | // - Define the light loop 724 | // - Setup the constant/data 725 | // - Do the reflection hierarchy 726 | // - Provide sampling function for shadowmap, ies, cookie and reflection (depends on the specific use with the light loops like index array or atlas or single and texture format (cubemap/latlong)) 727 | 728 | #define HAS_LIGHTLOOP 729 | 730 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" 731 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 732 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" 733 | 734 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" 735 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 736 | //#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl" 737 | #include "BakeryHDRP_Forward.hlsl" 738 | 739 | ENDHLSL 740 | } 741 | 742 | Pass 743 | { 744 | Name "TransparentDepthPostpass" 745 | Tags { "LightMode" = "TransparentDepthPostpass" } 746 | 747 | Cull[_CullMode] 748 | ZWrite On 749 | ColorMask 0 750 | 751 | HLSLPROGRAM 752 | 753 | #define SHADERPASS SHADERPASS_DEPTH_ONLY 754 | #define CUTOFF_TRANSPARENT_DEPTH_POSTPASS 755 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 756 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" 757 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" 758 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" 759 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" 760 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" 761 | 762 | ENDHLSL 763 | } 764 | } 765 | 766 | CustomEditor "Experimental.Rendering.HDPipeline.LitGUI" 767 | } 768 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bakery-hdrp-shaders 2 | HDRP-compatible shaders for Bakery 3 | 4 | Currently tested against HDRP 5.13.0. 5 | 6 | This shader supports SH baking mode. No additional UI options are added, shader will automatically switch from regular lightmaps to SH if the object was baked with it. 7 | --------------------------------------------------------------------------------