yum-archive/2ner
A toon shader for Unity's BIRP.
git clone https://git.yummers.dev/yum-archive/2ner
ffb4b6b
master
1#ifndef __DECALS 2#define __DECALS 3 4#include "features.cginc" 5#include "globals.cginc" 6#include "math.cginc" 7#include "texture_utils.cginc" 8 9// Struct to hold all decal parameters 10struct DecalParams { 11 float4 color; 12 float opacity; 13 float angle; 14 float uv_channel; 15 float mip_bias; 16 float4 mainTex_ST; 17 int tiling_mode; 18 int alpha_blend_mode; 19 Texture2D mainTex; 20 bool sdf_invert; 21 float sdf_threshold; 22 float sdf_ssn_strength; 23 Texture2D mask; 24 Texture2D normalTex; 25 float normal_scale; 26 Texture2D metallicGlossMap; 27 float metallic_value; 28 float smoothness_value; 29 Texture2D domain_warping_noise; 30 float domain_warping_octaves; 31 float domain_warping_strength; 32 float domain_warping_scale; 33 float domain_warping_speed; 34 Texture2D cmyk_warping_planes_noise; 35 float cmyk_warping_planes_strength; 36 float cmyk_warping_planes_scale; 37 float cmyk_warping_planes_speed; 38 float3 emission_color; 39 float emission_strength; 40 float emissions_proximity_min_distance; 41 float emissions_proximity_max_distance; 42}; 43 44// Macro to initialize decal parameters 45#define INIT_DECAL_PARAMS(params, prefix) \ 46 params.color = prefix##Color; \ 47 params.opacity = prefix##Opacity; \ 48 params.angle = prefix##Angle; \ 49 params.uv_channel = prefix##UV_Channel; \ 50 params.mip_bias = prefix##Bias; \ 51 params.mainTex_ST = prefix##MainTex_ST; \ 52 params.tiling_mode = prefix##Tiling_Mode; \ 53 params.alpha_blend_mode = prefix##Alpha_Blend_Mode; \ 54 params.mainTex = prefix##MainTex; \ 55 params.sdf_invert = prefix##SDF_Invert; \ 56 params.sdf_threshold = prefix##SDF_Threshold; \ 57 params.sdf_ssn_strength = prefix##SDF_SSN_Strength; \ 58 params.mask = prefix##Mask; \ 59 params.normalTex = prefix##Normal; \ 60 params.normal_scale = prefix##Normal_Scale; \ 61 params.metallicGlossMap = prefix##MetallicGlossMap; \ 62 params.metallic_value = prefix##Metallic; \ 63 params.smoothness_value = prefix##Smoothness; \ 64 params.domain_warping_noise = prefix##Domain_Warping_Noise; \ 65 params.domain_warping_octaves = prefix##Domain_Warping_Octaves; \ 66 params.domain_warping_strength = prefix##Domain_Warping_Strength; \ 67 params.domain_warping_scale = prefix##Domain_Warping_Scale; \ 68 params.domain_warping_speed = prefix##Domain_Warping_Speed; \ 69 params.cmyk_warping_planes_noise = prefix##CMYK_Warping_Planes_Noise; \ 70 params.cmyk_warping_planes_strength = prefix##CMYK_Warping_Planes_Strength; \ 71 params.cmyk_warping_planes_scale = prefix##CMYK_Warping_Planes_Scale; \ 72 params.cmyk_warping_planes_speed = prefix##CMYK_Warping_Planes_Speed; \ 73 params.emission_color = prefix##Emission_Color; \ 74 params.emission_strength = prefix##Emission_Strength; \ 75 params.emissions_proximity_min_distance = prefix##Emissions_Proximity_Min_Distance; \ 76 params.emissions_proximity_max_distance = prefix##Emissions_Proximity_Max_Distance; 77 78float2 applyDomainWarping(DecalParams params, float2 uv) { 79 float2 warped_uv = uv; 80 float amplitude = 1.0; 81 float frequency = params.domain_warping_scale; 82 float2 total_offset = float2(0.0, 0.0); 83 84 float2 time_vec = float2(-0.83, 0.97) * _Time.y * params.domain_warping_speed; 85 86 [loop] 87 for (uint ii = 0; ii < (uint) params.domain_warping_octaves; ii++) { 88 float2 noise_uv = warped_uv * frequency + time_vec * frequency; 89 float2 noise_sample = params.domain_warping_noise.SampleLevel(linear_repeat_s, noise_uv, 0); 90 float2 noise_offset = (noise_sample.xy * 2.0 - 1.0); 91 total_offset += noise_offset * amplitude; 92 frequency *= 2.0; 93 amplitude *= 0.5; 94 } 95 96 warped_uv = uv + total_offset * params.domain_warping_strength; 97 return warped_uv; 98} 99 100float4 getDecalColor(DecalParams params, float2 uv) { 101 float4 sdf_sample = params.mainTex.SampleBias(trilinear_aniso4_repeat_s, uv, params.mip_bias); 102 float sd = sdf_sample.r; 103 sd = params.sdf_invert ? 1 - sd : sd; 104 // The fwidth+smoothstep anti-aliases the glyph outline. See 105 // "Noise is Beautiful" by Gustavson around page 34 for an 106 // explanation of this trick. 107 float step_wd = fwidth(sd) * 0.5; 108 sd = smoothstep(params.sdf_threshold - step_wd, params.sdf_threshold + step_wd, sd); 109 return params.color * sd; 110} 111 112float4 getCmykWarpingPlanesColor(DecalParams params, float2 uv) { 113 float4 noise = params.cmyk_warping_planes_noise.SampleLevel(linear_repeat_s, uv, 0); 114 115 float amplitude = params.cmyk_warping_planes_strength; 116 float frequency = params.cmyk_warping_planes_scale; 117 118 // Process pairs of planes in each loop. 119 float4 warped_uv[2] = {float4(uv, uv), float4(uv, uv)}; 120 [loop] 121 for (uint jj = 0; jj < 2; jj++) { 122 float2 speed_direction = float2( 123 jj % 2 == 0 ? 1 : -1, 124 jj / 2 == 0 ? 1 : -1); 125 float2 time_offset = speed_direction * _Time.y * params.cmyk_warping_planes_speed; 126 { 127 float2 noise_uv = warped_uv[jj] * frequency + time_offset; 128 float4 noise = params.cmyk_warping_planes_noise.SampleLevel(trilinear_repeat_s, noise_uv, 0); 129 noise = (noise * 2.0 - 1.0); 130 warped_uv[jj].xy += noise.xy * amplitude; 131 warped_uv[jj].zw += noise.zw * amplitude; 132 } 133 } 134 135 float4 decal_color0 = getDecalColor(params, warped_uv[0].xy); 136 float4 decal_color1 = getDecalColor(params, warped_uv[0].zw); 137 float4 decal_color2 = getDecalColor(params, warped_uv[1].xy); 138 float4 decal_color3 = getDecalColor(params, warped_uv[1].zw); 139 140 float4 plane_alphas = float4( 141 decal_color0.a, 142 decal_color1.a, 143 decal_color2.a, 144 decal_color3.a 145 ); 146 147 float4 final_cmyk = plane_alphas; 148 float3 final_rgb = saturate(cmykToRgb(final_cmyk)); 149 float eps = 1E-5; 150 final_rgb = lerp( 151 final_rgb, 152 params.color.rgb, 153 all(plane_alphas>eps) 154 ); 155 156 return float4(final_rgb, saturate(decal_color0.a + decal_color1.a + decal_color2.a + decal_color3.a)); 157} 158 159// Calculate normal vector from an SDF using screen-space derivatives. 160float3 calculateSdfSsn(DecalParams params, float2 decal_uv, float4 decal_albedo) { 161 float sdf_val = params.mainTex.SampleBias(trilinear_aniso4_repeat_s, decal_uv, params.mip_bias).r; 162 sdf_val = params.sdf_invert ? 1 - sdf_val : sdf_val; 163 164 float sdf_dx = ddx(sdf_val); 165 float sdf_dy = ddy(sdf_val); 166 167 float2 uv_dx = ddx(decal_uv); 168 float2 uv_dy = ddy(decal_uv); 169 170 float det = uv_dx.x * uv_dy.y - uv_dx.y * uv_dy.x; 171 float2 sdf_grad_uv; 172 sdf_grad_uv.x = (sdf_dx * uv_dy.y - sdf_dy * uv_dx.y) / det; 173 sdf_grad_uv.y = (sdf_dy * uv_dx.x - sdf_dx * uv_dy.x) / det; 174 175 float2 scaled_grad = sdf_grad_uv * params.sdf_ssn_strength * decal_albedo.a * params.opacity; 176 if (det == 0) { 177 scaled_grad.xy = 0; 178 } 179 180 return normalize(float3(-scaled_grad.xy, 1.0)); 181} 182 183// DS = decal stage 184#define DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 185 float2x2 decal_rot = float2x2( \ 186 cos(params.angle * TAU), -sin(params.angle * TAU), \ 187 sin(params.angle * TAU), cos(params.angle * TAU) \ 188 ); \ 189 \ 190 float2 raw_decal_uv = get_uv_by_channel(i, params.uv_channel); \ 191 float2 decal_uv = raw_decal_uv; \ 192 decal_uv = ((decal_uv - 0.5) - params.mainTex_ST.zw) * params.mainTex_ST.xy + 0.5; \ 193 decal_uv = mul(decal_rot, decal_uv - 0.5) + 0.5; \ 194 decal_uv = (params.tiling_mode == DECAL_TILING_MODE_CLAMP ? saturate(decal_uv) : decal_uv); 195 196#define DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 197 decal_uv = applyDomainWarping(params, decal_uv); 198 199#define DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 200 201#define DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 202 float4 decal_albedo = getCmykWarpingPlanesColor(params, decal_uv); 203 204#define DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 205 float4 decal_albedo = getDecalColor(params, decal_uv); 206 207#define DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 208 float4 decal_albedo; \ 209 { \ 210 decal_albedo = params.mainTex.SampleBias(trilinear_aniso4_repeat_s, decal_uv, params.mip_bias); \ 211 decal_albedo *= params.color; \ 212 } 213 214#define DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 215 { \ 216 float3 sdf_normal_ts = calculateSdfSsn(params, decal_uv, decal_albedo); \ 217 sdf_normal_ts.xy *= 1.0f - albedo.a; \ 218 sdf_normal_ts = normalize(sdf_normal_ts); \ 219 normal_tangent = blendNormalsHill12(normal_tangent, sdf_normal_ts); \ 220 } 221 222#define DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 223 { \ 224 float3 sdf_normal_ts = calculateSdfSsn(params, decal_uv, decal_albedo); \ 225 normal_tangent = normalize(lerp(normal_tangent, normalize(sdf_normal_ts), decal_albedo.a)); \ 226 } 227 228#define DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 229 { \ 230 float eps = 1e-4; \ 231 float2 uv_clamped = step(eps, decal_uv) * step(decal_uv, 1 - eps); \ 232 decal_albedo.a *= uv_clamped.x * uv_clamped.y; \ 233 } 234 235#define DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 236 237#define DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 238 float decal_mask = params.mask.SampleBias(trilinear_aniso4_repeat_s, raw_decal_uv, params.mip_bias); \ 239 decal_albedo.a *= decal_mask; 240 241#define DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 242 float decal_mask = 1; 243 244#define DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 245 float alpha_blend_amount = (1.0f - albedo.a) * decal_albedo.a; 246 247#define DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 248 decal_albedo.a = lerp(0, decal_albedo.a, params.opacity); \ 249 float alpha_blend_amount = (1.0f - albedo.a) * decal_albedo.a; \ 250 albedo = alphaBlend(albedo, decal_albedo); 251 252#define DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 253 decal_albedo.a = lerp(0, decal_albedo.a, params.opacity); \ 254 float alpha_blend_amount = (1.0f - albedo.a) * decal_albedo.a; \ 255 albedo = alphaBlend(decal_albedo, albedo); \ 256 decal_albedo.a = alpha_blend_amount; 257 258#define DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 259 albedo = lerp(albedo, decal_albedo, decal_mask * params.opacity); 260 261#define DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 262 albedo = lerp(albedo, decal_albedo * albedo, decal_mask * params.opacity); 263 264#define DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 265 emission += params.emission_color * params.emission_strength; 266 267#define DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 268 emission += albedo.rgb * params.emission_color * params.emission_strength; 269 270#define DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 271 272 273#define DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 274 float3 decal_normal = UnpackScaleNormal( \ 275 params.normalTex.SampleBias(trilinear_aniso4_repeat_s, decal_uv, params.mip_bias), \ 276 params.normal_scale * decal_albedo.a * params.opacity); \ 277 normal_tangent = blendNormalsHill12(normal_tangent, decal_normal); 278 //normal_tangent = lerp(normal_tangent, decal_normal, decal_albedo.a * params.opacity); 279 280#define DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 281 282#define DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 283 float4 metallic_gloss = params.metallicGlossMap.Sample(trilinear_repeat_s, decal_uv); \ 284 metallic = lerp(metallic, metallic_gloss.r * params.metallic_value, decal_albedo.a); \ 285 smoothness = lerp(smoothness, metallic_gloss.a * params.smoothness_value, decal_albedo.a); 286 287#define DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ 288 float4 metallic_gloss = params.metallicGlossMap.Sample(trilinear_repeat_s, decal_uv); \ 289 metallic = lerp(metallic, metallic_gloss.r * params.metallic_value, alpha_blend_amount); \ 290 smoothness = lerp(smoothness, metallic_gloss.a * params.smoothness_value, alpha_blend_amount); 291 292#define DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 293 294#define DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} 295 296void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, inout float metallic, inout float smoothness, inout float3 emission) { 297 DecalParams decal; 298 #if defined(_DECAL0) 299 { 300 INIT_DECAL_PARAMS(decal, _Decal0_); 301 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 302 #if defined(_DECAL0_DOMAIN_WARPING) 303 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 304 #else 305 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 306 #endif 307 #if defined(_DECAL0_SDF) && defined(_DECAL0_CMYK_WARPING_PLANES) 308 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 309 #elif defined(_DECAL0_SDF) 310 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 311 #else 312 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 313 #endif 314 #if defined(_DECAL0_TILING_MODE) 315 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 316 #else 317 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 318 #endif 319 #if defined(_DECAL0_MASK) 320 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 321 #else 322 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 323 #endif 324 325 #if defined(_DECAL0_REPLACE_ALPHA) 326 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 327 #endif 328 329 #if defined(_DECAL0_NORMAL) 330 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 331 #else 332 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 333 #endif 334 #if defined(_DECAL0_SDF_SSN) && !defined(_DECAL0_SDF_SSN_REPLACE) 335 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 336 #elif defined(_DECAL0_SDF_SSN) && defined(_DECAL0_SDF_SSN_REPLACE) 337 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 338 #else 339 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 340 #endif 341 342 #if defined(_DECAL0_SDF_SSN_ONLY) 343 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 344 #elif defined(_DECAL0_REPLACE_ALPHA) 345 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 346 #elif defined(_DECAL0_MULTIPLY) 347 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 348 #elif defined(_DECAL0_INVERT_BLEND_ORDER) 349 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 350 #else 351 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 352 #endif 353 354 #if defined(FORWARD_BASE_PASS) 355 float3 tmp_emission = 0; 356 #if defined(_DECAL0_EMISSIONS) && defined(_DECAL0_EMISSION_MODE_ADD_PRODUCT) 357 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 358 #elif defined(_DECAL0_EMISSIONS) 359 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 360 #else 361 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 362 #endif 363 #if defined(_DECAL0_EMISSIONS_PROXIMITY) 364 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 365 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 366 #endif 367 emission += tmp_emission; 368 #endif 369 370 #if defined(_DECAL0_REFLECTIONS) && !defined(_DECAL0_REFLECTIONS_ALPHA_BLEND) 371 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 372 #elif defined(_DECAL0_REFLECTIONS) && defined(_DECAL0_REFLECTIONS_ALPHA_BLEND) 373 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 374 #else 375 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 376 #endif 377 } 378 #endif // _DECAL0 379 #if defined(_DECAL1) 380 { 381 INIT_DECAL_PARAMS(decal, _Decal1_); 382 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 383 #if defined(_DECAL1_DOMAIN_WARPING) 384 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 385 #else 386 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 387 #endif 388 #if defined(_DECAL1_SDF) && defined(_DECAL1_CMYK_WARPING_PLANES) 389 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 390 #elif defined(_DECAL1_SDF) 391 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 392 #else 393 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 394 #endif 395 #if defined(_DECAL1_TILING_MODE) 396 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 397 #else 398 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 399 #endif 400 #if defined(_DECAL1_MASK) 401 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 402 #else 403 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 404 #endif 405 406 #if defined(_DECAL1_REPLACE_ALPHA) 407 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 408 #endif 409 410 #if defined(_DECAL1_NORMAL) 411 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 412 #else 413 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 414 #endif 415 #if defined(_DECAL1_SDF_SSN) && !defined(_DECAL1_SDF_SSN_REPLACE) 416 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 417 #elif defined(_DECAL1_SDF_SSN) && defined(_DECAL1_SDF_SSN_REPLACE) 418 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 419 #else 420 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 421 #endif 422 423 #if defined(_DECAL1_SDF_SSN_ONLY) 424 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 425 #elif defined(_DECAL1_REPLACE_ALPHA) 426 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 427 #elif defined(_DECAL1_MULTIPLY) 428 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 429 #elif defined(_DECAL1_INVERT_BLEND_ORDER) 430 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 431 #else 432 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 433 #endif 434 435 #if defined(FORWARD_BASE_PASS) 436 float3 tmp_emission = 0; 437 #if defined(_DECAL1_EMISSIONS) && defined(_DECAL1_EMISSION_MODE_ADD_PRODUCT) 438 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 439 #elif defined(_DECAL1_EMISSIONS) 440 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 441 #else 442 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 443 #endif 444 #if defined(_DECAL1_EMISSIONS_PROXIMITY) 445 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 446 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 447 #endif 448 emission += tmp_emission; 449 #endif 450 451 #if defined(_DECAL1_REFLECTIONS) && !defined(_DECAL1_REFLECTIONS_ALPHA_BLEND) 452 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 453 #elif defined(_DECAL1_REFLECTIONS) && defined(_DECAL1_REFLECTIONS_ALPHA_BLEND) 454 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 455 #else 456 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 457 #endif 458 } 459 #endif // _DECAL1 460 #if defined(_DECAL2) 461 { 462 INIT_DECAL_PARAMS(decal, _Decal2_); 463 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 464 #if defined(_DECAL2_DOMAIN_WARPING) 465 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 466 #else 467 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 468 #endif 469 #if defined(_DECAL2_SDF) && defined(_DECAL2_CMYK_WARPING_PLANES) 470 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 471 #elif defined(_DECAL2_SDF) 472 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 473 #else 474 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 475 #endif 476 #if defined(_DECAL2_TILING_MODE) 477 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 478 #else 479 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 480 #endif 481 #if defined(_DECAL2_MASK) 482 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 483 #else 484 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 485 #endif 486 487 #if defined(_DECAL2_REPLACE_ALPHA) 488 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 489 #endif 490 491 #if defined(_DECAL2_NORMAL) 492 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 493 #else 494 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 495 #endif 496 #if defined(_DECAL2_SDF_SSN) && !defined(_DECAL2_SDF_SSN_REPLACE) 497 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 498 #elif defined(_DECAL2_SDF_SSN) && defined(_DECAL2_SDF_SSN_REPLACE) 499 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 500 #else 501 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 502 #endif 503 504 #if defined(_DECAL2_SDF_SSN_ONLY) 505 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 506 #elif defined(_DECAL2_REPLACE_ALPHA) 507 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 508 #elif defined(_DECAL2_MULTIPLY) 509 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 510 #elif defined(_DECAL2_INVERT_BLEND_ORDER) 511 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 512 #else 513 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 514 #endif 515 516 #if defined(FORWARD_BASE_PASS) 517 float3 tmp_emission = 0; 518 #if defined(_DECAL2_EMISSIONS) && defined(_DECAL2_EMISSION_MODE_ADD_PRODUCT) 519 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 520 #elif defined(_DECAL2_EMISSIONS) 521 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 522 #else 523 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 524 #endif 525 #if defined(_DECAL2_EMISSIONS_PROXIMITY) 526 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 527 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 528 #endif 529 emission += tmp_emission; 530 #endif 531 532 #if defined(_DECAL2_REFLECTIONS) && !defined(_DECAL2_REFLECTIONS_ALPHA_BLEND) 533 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 534 #elif defined(_DECAL2_REFLECTIONS) && defined(_DECAL2_REFLECTIONS_ALPHA_BLEND) 535 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 536 #else 537 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 538 #endif 539 } 540 #endif // _DECAL2 541 #if defined(_DECAL3) 542 { 543 INIT_DECAL_PARAMS(decal, _Decal3_); 544 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 545 #if defined(_DECAL3_DOMAIN_WARPING) 546 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 547 #else 548 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 549 #endif 550 #if defined(_DECAL3_SDF) && defined(_DECAL3_CMYK_WARPING_PLANES) 551 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 552 #elif defined(_DECAL3_SDF) 553 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 554 #else 555 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 556 #endif 557 #if defined(_DECAL3_TILING_MODE) 558 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 559 #else 560 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 561 #endif 562 #if defined(_DECAL3_MASK) 563 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 564 #else 565 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 566 #endif 567 568 #if defined(_DECAL3_REPLACE_ALPHA) 569 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 570 #endif 571 572 #if defined(_DECAL3_NORMAL) 573 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 574 #else 575 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 576 #endif 577 #if defined(_DECAL3_SDF_SSN) && !defined(_DECAL3_SDF_SSN_REPLACE) 578 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 579 #elif defined(_DECAL3_SDF_SSN) && defined(_DECAL3_SDF_SSN_REPLACE) 580 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 581 #else 582 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 583 #endif 584 585 #if defined(_DECAL3_SDF_SSN_ONLY) 586 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 587 #elif defined(_DECAL3_REPLACE_ALPHA) 588 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 589 #elif defined(_DECAL3_MULTIPLY) 590 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 591 #elif defined(_DECAL3_INVERT_BLEND_ORDER) 592 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 593 #else 594 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 595 #endif 596 597 #if defined(FORWARD_BASE_PASS) 598 float3 tmp_emission = 0; 599 #if defined(_DECAL3_EMISSIONS) && defined(_DECAL3_EMISSION_MODE_ADD_PRODUCT) 600 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 601 #elif defined(_DECAL3_EMISSIONS) 602 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 603 #else 604 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 605 #endif 606 #if defined(_DECAL3_EMISSIONS_PROXIMITY) 607 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 608 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 609 #endif 610 emission += tmp_emission; 611 #endif 612 613 #if defined(_DECAL3_REFLECTIONS) && !defined(_DECAL3_REFLECTIONS_ALPHA_BLEND) 614 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 615 #elif defined(_DECAL3_REFLECTIONS) && defined(_DECAL3_REFLECTIONS_ALPHA_BLEND) 616 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 617 #else 618 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 619 #endif 620 } 621 #endif // _DECAL3 622 #if defined(_DECAL4) 623 { 624 INIT_DECAL_PARAMS(decal, _Decal4_); 625 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 626 #if defined(_DECAL4_DOMAIN_WARPING) 627 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 628 #else 629 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 630 #endif 631 #if defined(_DECAL4_SDF) && defined(_DECAL4_CMYK_WARPING_PLANES) 632 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 633 #elif defined(_DECAL4_SDF) 634 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 635 #else 636 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 637 #endif 638 #if defined(_DECAL4_TILING_MODE) 639 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 640 #else 641 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 642 #endif 643 #if defined(_DECAL4_MASK) 644 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 645 #else 646 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 647 #endif 648 649 #if defined(_DECAL4_REPLACE_ALPHA) 650 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 651 #endif 652 653 #if defined(_DECAL4_NORMAL) 654 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 655 #else 656 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 657 #endif 658 #if defined(_DECAL4_SDF_SSN) && !defined(_DECAL4_SDF_SSN_REPLACE) 659 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 660 #elif defined(_DECAL4_SDF_SSN) && defined(_DECAL4_SDF_SSN_REPLACE) 661 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 662 #else 663 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 664 #endif 665 666 #if defined(_DECAL4_SDF_SSN_ONLY) 667 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 668 #elif defined(_DECAL4_REPLACE_ALPHA) 669 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 670 #elif defined(_DECAL4_MULTIPLY) 671 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 672 #elif defined(_DECAL4_INVERT_BLEND_ORDER) 673 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 674 #else 675 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 676 #endif 677 678 #if defined(FORWARD_BASE_PASS) 679 float3 tmp_emission = 0; 680 #if defined(_DECAL4_EMISSIONS) && defined(_DECAL4_EMISSION_MODE_ADD_PRODUCT) 681 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 682 #elif defined(_DECAL4_EMISSIONS) 683 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 684 #else 685 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 686 #endif 687 #if defined(_DECAL4_EMISSIONS_PROXIMITY) 688 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 689 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 690 #endif 691 emission += tmp_emission; 692 #endif 693 694 #if defined(_DECAL4_REFLECTIONS) && !defined(_DECAL4_REFLECTIONS_ALPHA_BLEND) 695 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 696 #elif defined(_DECAL4_REFLECTIONS) && defined(_DECAL4_REFLECTIONS_ALPHA_BLEND) 697 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 698 #else 699 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 700 #endif 701 } 702 #endif // _DECAL4 703 #if defined(_DECAL5) 704 { 705 INIT_DECAL_PARAMS(decal, _Decal5_); 706 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 707 #if defined(_DECAL5_DOMAIN_WARPING) 708 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 709 #else 710 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 711 #endif 712 #if defined(_DECAL5_SDF) && defined(_DECAL5_CMYK_WARPING_PLANES) 713 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 714 #elif defined(_DECAL5_SDF) 715 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 716 #else 717 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 718 #endif 719 #if defined(_DECAL5_TILING_MODE) 720 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 721 #else 722 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 723 #endif 724 #if defined(_DECAL5_MASK) 725 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 726 #else 727 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 728 #endif 729 730 #if defined(_DECAL5_REPLACE_ALPHA) 731 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 732 #endif 733 734 #if defined(_DECAL5_NORMAL) 735 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 736 #else 737 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 738 #endif 739 #if defined(_DECAL5_SDF_SSN) && !defined(_DECAL5_SDF_SSN_REPLACE) 740 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 741 #elif defined(_DECAL5_SDF_SSN) && defined(_DECAL5_SDF_SSN_REPLACE) 742 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 743 #else 744 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 745 #endif 746 747 #if defined(_DECAL5_SDF_SSN_ONLY) 748 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 749 #elif defined(_DECAL5_REPLACE_ALPHA) 750 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 751 #elif defined(_DECAL5_MULTIPLY) 752 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 753 #elif defined(_DECAL5_INVERT_BLEND_ORDER) 754 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 755 #else 756 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 757 #endif 758 759 #if defined(FORWARD_BASE_PASS) 760 float3 tmp_emission = 0; 761 #if defined(_DECAL5_EMISSIONS) && defined(_DECAL5_EMISSION_MODE_ADD_PRODUCT) 762 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 763 #elif defined(_DECAL5_EMISSIONS) 764 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 765 #else 766 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 767 #endif 768 #if defined(_DECAL5_EMISSIONS_PROXIMITY) 769 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 770 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 771 #endif 772 emission += tmp_emission; 773 #endif 774 775 #if defined(_DECAL5_REFLECTIONS) && !defined(_DECAL5_REFLECTIONS_ALPHA_BLEND) 776 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 777 #elif defined(_DECAL5_REFLECTIONS) && defined(_DECAL5_REFLECTIONS_ALPHA_BLEND) 778 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 779 #else 780 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 781 #endif 782 } 783 #endif // _DECAL5 784 #if defined(_DECAL6) 785 { 786 INIT_DECAL_PARAMS(decal, _Decal6_); 787 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 788 #if defined(_DECAL6_DOMAIN_WARPING) 789 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 790 #else 791 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 792 #endif 793 #if defined(_DECAL6_SDF) && defined(_DECAL6_CMYK_WARPING_PLANES) 794 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 795 #elif defined(_DECAL6_SDF) 796 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 797 #else 798 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 799 #endif 800 #if defined(_DECAL6_TILING_MODE) 801 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 802 #else 803 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 804 #endif 805 #if defined(_DECAL6_MASK) 806 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 807 #else 808 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 809 #endif 810 811 #if defined(_DECAL6_REPLACE_ALPHA) 812 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 813 #endif 814 815 #if defined(_DECAL6_NORMAL) 816 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 817 #else 818 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 819 #endif 820 #if defined(_DECAL6_SDF_SSN) && !defined(_DECAL6_SDF_SSN_REPLACE) 821 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 822 #elif defined(_DECAL6_SDF_SSN) && defined(_DECAL6_SDF_SSN_REPLACE) 823 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 824 #else 825 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 826 #endif 827 828 #if defined(_DECAL6_SDF_SSN_ONLY) 829 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 830 #elif defined(_DECAL6_REPLACE_ALPHA) 831 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 832 #elif defined(_DECAL6_MULTIPLY) 833 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 834 #elif defined(_DECAL6_INVERT_BLEND_ORDER) 835 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 836 #else 837 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 838 #endif 839 840 #if defined(FORWARD_BASE_PASS) 841 float3 tmp_emission = 0; 842 #if defined(_DECAL6_EMISSIONS) && defined(_DECAL6_EMISSION_MODE_ADD_PRODUCT) 843 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 844 #elif defined(_DECAL6_EMISSIONS) 845 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 846 #else 847 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 848 #endif 849 #if defined(_DECAL6_EMISSIONS_PROXIMITY) 850 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 851 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 852 #endif 853 emission += tmp_emission; 854 #endif 855 856 #if defined(_DECAL6_REFLECTIONS) && !defined(_DECAL6_REFLECTIONS_ALPHA_BLEND) 857 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 858 #elif defined(_DECAL6_REFLECTIONS) && defined(_DECAL6_REFLECTIONS_ALPHA_BLEND) 859 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 860 #else 861 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 862 #endif 863 } 864 #endif // _DECAL6 865 #if defined(_DECAL7) 866 { 867 INIT_DECAL_PARAMS(decal, _Decal7_); 868 DS_GENERIC(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 869 #if defined(_DECAL7_DOMAIN_WARPING) 870 DS_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 871 #else 872 DS_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 873 #endif 874 #if defined(_DECAL7_SDF) && defined(_DECAL7_CMYK_WARPING_PLANES) 875 DS_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 876 #elif defined(_DECAL7_SDF) 877 DS_SDF_ON_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 878 #else 879 DS_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 880 #endif 881 #if defined(_DECAL7_TILING_MODE) 882 DS_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 883 #else 884 DS_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 885 #endif 886 #if defined(_DECAL7_MASK) 887 DS_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 888 #else 889 DS_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 890 #endif 891 892 #if defined(_DECAL7_REPLACE_ALPHA) 893 albedo.a = decal_mask ? 1.0f - decal_mask : albedo.a; 894 #endif 895 896 #if defined(_DECAL7_NORMAL) 897 DS_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 898 #else 899 DS_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 900 #endif 901 #if defined(_DECAL7_SDF_SSN) && !defined(_DECAL7_SDF_SSN_REPLACE) 902 DS_SDF_SSN_ON_MODE_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 903 #elif defined(_DECAL7_SDF_SSN) && defined(_DECAL7_SDF_SSN_REPLACE) 904 DS_SDF_SSN_ON_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 905 #else 906 DS_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 907 #endif 908 909 #if defined(_DECAL7_SDF_SSN_ONLY) 910 DS_BLEND_MODE_SSN_ONLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 911 #elif defined(_DECAL7_REPLACE_ALPHA) 912 DS_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 913 #elif defined(_DECAL7_MULTIPLY) 914 DS_BLEND_MODE_MULTIPLY(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 915 #elif defined(_DECAL7_INVERT_BLEND_ORDER) 916 DS_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 917 #else 918 DS_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 919 #endif 920 921 #if defined(FORWARD_BASE_PASS) 922 float3 tmp_emission = 0; 923 #if defined(_DECAL7_EMISSIONS) && defined(_DECAL7_EMISSION_MODE_ADD_PRODUCT) 924 DS_EMISSION_ON_MODE_ADD_PRODUCT(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 925 #elif defined(_DECAL7_EMISSIONS) 926 DS_EMISSION_ON_MODE_ADD(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 927 #else 928 DS_EMISSION_OFF(i, albedo, normal_tangent, metallic, smoothness, tmp_emission, decal); 929 #endif 930 #if defined(_DECAL7_EMISSIONS_PROXIMITY) 931 float tmp_d = distance(i.worldPos, _WorldSpaceCameraPos); 932 tmp_emission = lerp(tmp_emission, 0, saturate((tmp_d - decal.emissions_proximity_min_distance) / (decal.emissions_proximity_max_distance - decal.emissions_proximity_min_distance))); 933 #endif 934 emission += tmp_emission; 935 #endif 936 937 #if defined(_DECAL7_REFLECTIONS) && !defined(_DECAL7_REFLECTIONS_ALPHA_BLEND) 938 DS_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 939 #elif defined(_DECAL7_REFLECTIONS) && defined(_DECAL7_REFLECTIONS_ALPHA_BLEND) 940 DS_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 941 #else 942 DS_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); 943 #endif 944 } 945 #endif // _DECAL7 946} 947 948#endif // __DECALS