浏览代码

Refractored refraction keyword

/Yibing-Project-2
Frédéric Vauchelles 7 年前
当前提交
4ecf28cc
共有 5 个文件被更改,包括 14 次插入20 次删除
  1. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  2. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  3. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


SetKeyword(material, "_MATID_CLEARCOAT", materialId == Lit.MaterialId.LitClearCoat);
var refractionModeValue = (Lit.RefractionMode)material.GetFloat(kRefractionMode);
SetKeyword(material, "_REFRACTION_THINPLANE", refractionModeValue == Lit.RefractionMode.ThinPlane);
SetKeyword(material, "_REFRACTION_THICKPLANE", refractionModeValue == Lit.RefractionMode.ThickPlane);
SetKeyword(material, "_REFRACTION_THICKSPHERE", refractionModeValue == Lit.RefractionMode.ThickSphere);
var hasRefraction = (!material.HasProperty(kPreRefractionPass)
|| material.GetFloat(kPreRefractionPass) <= 0.0)
&& refractionModeValue != Lit.RefractionMode.None;
SetKeyword(material, "_REFRACTION_ON", hasRefraction); // Refraction is not available for pre refraction (color buffer cannot be fetched)
// We can't have refraction in pre-refraction queue
var canHaveRefraction = !material.HasProperty(kPreRefractionPass) || material.GetFloat(kPreRefractionPass) <= 0.0;
SetKeyword(material, "_REFRACTION_THINPLANE", (refractionModeValue == Lit.RefractionMode.ThinPlane) && canHaveRefraction);
SetKeyword(material, "_REFRACTION_THICKPLANE", (refractionModeValue == Lit.RefractionMode.ThickPlane) && canHaveRefraction);
SetKeyword(material, "_REFRACTION_THICKSPHERE", (refractionModeValue == Lit.RefractionMode.ThickSphere) && canHaveRefraction);
}
}
} // namespace UnityEditor

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#include "../../../Core/ShaderLibrary/VolumeRendering.hlsl"
#endif
// Define refraction keyword helpers
#if defined(_REFRACTION_THINPLANE) || defined(_REFRACTION_THICKPLANE) || defined(_REFRACTION_THICKSPHERE)
#define HAS_REFRACTION
#else
#undef HAS_REFRACTION
#endif
// In case we pack data uint16 buffer we need to change the output render target format to uint16
// TODO: Is there a way to automate these output type based on the format declare in lit.cs ?
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16

specularLighting = float3(0.0, 0.0, 0.0);
weight = float2(0.0, 0.0);
#if !defined(_REFRACTION_ON)
return;
#endif
#if defined(_REFRACTION_THINPLANE) || defined(_REFRACTION_THICKPLANE) || defined(_REFRACTION_THICKSPHERE)
#ifdef HAS_REFRACTION
// Refraction process:
// 1. Depending on the shape model, we calculate the refracted point in world space and the optical depth
// 2. We calculate the screen space position of the refracted point

// Beer-Lamber law for absorption
float3 transmittance = exp(-bsdfData.absorptionCoefficient * opticalDepth);
diffuseLighting *= transmittance;
#else
// Use perfect flat transparency when we cannot fetch the correct pixel color for the refracted point
diffuseLighting = SAMPLE_TEXTURE2D_LOD(_GaussianPyramidColorTexture, s_trilinear_clamp_sampler, posInput.positionSS, 0.0).rgb;
#endif
}

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


#pragma shader_feature _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE
#pragma shader_feature _VERTEX_WIND
#pragma shader_feature _ _REFRACTION_THINPLANE _REFRACTION_THICKPLANE _REFRACTION_THICKSPHERE
#pragma shader_feature _REFRACTION_ON
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

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


surfaceData.specularColor *= SAMPLE_UVMAPPING_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, layerTexCoord.base).rgb;
#endif
#if defined(_REFRACTION_THINPLANE) || defined(_REFRACTION_THICKPLANE) || defined(_REFRACTION_THICKSPHERE)
#ifdef HAS_REFRACTION
surfaceData.ior = _IOR;
surfaceData.transmittanceColor = _TransmittanceColor;
surfaceData.atDistance = _ATDistance;

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


#pragma shader_feature _VERTEX_WIND
#pragma shader_feature _ _TESSELLATION_PHONG
#pragma shader_feature _ _REFRACTION_THINPLANE _REFRACTION_THICKPLANE _REFRACTION_THICKSPHERE
#pragma shader_feature _REFRACTION_ON
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

正在加载...
取消
保存