浏览代码

Add _SURFACE_TYPE_TRANSPARENT keyword (so fog work with rough refraction)

/Yibing-Project-2
Sebastien Lagarde 7 年前
当前提交
cd755f87
共有 10 个文件被更改,包括 17 次插入16 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  2. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  7. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/UnlitUI.cs
  9. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader
  10. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/UnlitData.hlsl

1
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

1
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#if defined(_REFRACTION_THINPLANE) || defined(_REFRACTION_THICKPLANE) || defined(_REFRACTION_THICKSPHERE)
// Note: Will override thickness of SSS's property set
FillMaterialIdTransparencyData(
surfaceData.ior, surfaceData.transmittanceColor, surfaceData.atDistance, surfaceData.thickness, surfaceData.refractionMask,
surfaceData.ior, surfaceData.transmittanceColor, surfaceData.atDistance, surfaceData.thickness, surfaceData.refractionMask,
bsdfData);
#endif

[branch] if (lightData.shadowIndex >= 0)
{
#ifdef SURFACE_TYPE_TRANSPARENT
#ifdef _SURFACE_TYPE_TRANSPARENT
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS);
#else
shadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.unPositionSS).x;

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
// This feature is only for transparent Lit
#pragma shader_feature _ENABLE_FOG

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


// If we have a prepass, we need to remove the clip from the GBuffer pass (otherwise HiZ does not work on PS4)
// For Forward
// Opaque geometry always has a depth pre-pass so we never want to do the clip here. For transparent we perform the clip as usual.
#if !(SHADERPASS == SHADERPASS_FORWARD && defined(SURFACE_TYPE_OPAQUE)) && !(SHADERPASS == SHADERPASS_GBUFFER && defined(_BYPASS_ALPHA_TEST))
#if !(SHADERPASS == SHADERPASS_FORWARD && !defined(_SURFACE_TYPE_TRANSPARENT)) && !(SHADERPASS == SHADERPASS_GBUFFER && defined(_BYPASS_ALPHA_TEST))
clip(alpha - alphaCutoff);
#endif
}

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl


#include "../../Core/ShaderLibrary/ImageBasedLighting.hlsl"
#include "../Sky/AtmosphericScattering/AtmosphericScattering.hlsl"
//-----------------------------------------------------------------------------
// Blending
//-----------------------------------------------------------------------------
// This should match the possible blending modes in any material .shader file (lit/layeredlit/unlit etc)
#if defined(_BLENDMODE_ALPHA) || defined(_BLENDMODE_ADD) || defined(_BLENDMODE_MULTIPLY) || defined(_BLENDMODE_PRE_MULTIPLY)
#define SURFACE_TYPE_TRANSPARENT
#else
#define SURFACE_TYPE_OPAQUE
#endif
// Guidelines
// .Shader need to define _SURFACE_TYPE_TRANSPARENT if they use a transparent material
// Also when transparent material object use a blend mode, it must define the blend mode (Note: Rough Refraction don't use blend mode)
// _BLENDMODE_ALPHA, _BLENDMODE_ADD, _BLENDMODE_MULTIPLY, (_BLENDMODE_PRE_MULTIPLY)
//-----------------------------------------------------------------------------
// Fog sampling function for materials

{
float4 result = inputColor;
#if defined(SURFACE_TYPE_TRANSPARENT) && defined(_ENABLE_FOG)
#if defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ENABLE_FOG)
float4 fog = EvaluateAtmosphericScattering(posInput);
#if defined(_BLENDMODE_ALPHA)

// For additive, we just need to fade to black with fog density (black + background == background color == fog color)
result.rgb = result.rgb * (1.0 - fog.a);
#elif defined(_BLENDMODE_MULTIPLY)
#elif defined(_BLENDMODE_MULTIPLY)
// For multiplicative, we just need to fade to white with fog density (white * background == background color == fog color)
result.rgb = lerp(result.rgb, float3(1.0, 1.0, 1.0), fog.a);
#elif defined(_BLENDMODE_PRE_MULTIPLY)

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/UnlitUI.cs


SetupBaseUnlitKeywords(material);
SetupBaseUnlitMaterialPass(material);
SetKeyword(material, "SURFACE_TYPE_TRANSPARENT", (SurfaceType)material.GetFloat(kSurfaceType) == SurfaceType.Transparent);
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader


#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Unlit

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/UnlitData.hlsl


void DoAlphaTest(float alpha, float alphaCutoff)
{
// Don't do the clip when rendering forward opaque (unlit). Forward opaque always have a prepass (with depth test on)
#if !(SHADERPASS == SHADERPASS_FORWARD_UNLIT && defined(SURFACE_TYPE_OPAQUE))
#if !(SHADERPASS == SHADERPASS_FORWARD_UNLIT && !defined(_SURFACE_TYPE_TRANSPARENT))
clip(alpha - alphaCutoff);
#endif
}

正在加载...
取消
保存