浏览代码

Blend decal normals in tangent space

/Add-support-for-light-specular-color-tint
Paul Melamed 7 年前
当前提交
46c0667a
共有 4 个文件被更改,包括 22 次插入2 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  3. 15
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl


ZERO_INITIALIZE(UVMapping, texCoord);
ZERO_INITIALIZE(BuiltinData, builtinData);
texCoord.uv = positionDS.xz;
surfaceData.normalWS.xyz = mul((float3x3)_DecalToWorldR, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
//surfaceData.normalWS.xyz = mul((float3x3)_DecalToWorldR, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
surfaceData.normalWS.xyz = SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1) * 0.5f + 0.5f;
surfaceData.normalWS.w = surfaceData.baseColor.w;
}

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


float3 bentNormalTS;
float3 bentNormalWS;
float alpha = GetSurfaceData(input, layerTexCoord, surfaceData, normalTS, bentNormalTS);
AddDecalNormal(posInput.positionSS.xy, normalTS);
AddDecalBaseColor(posInput.positionSS.xy, surfaceData.baseColor);
GetNormalWS(input, V, normalTS, surfaceData.normalWS);
// Use bent normal to sample GI if available
surfaceData.specularOcclusion = 1.0;

surfaceData.transmittanceMask = 0.0;
GetNormalWS(input, V, normalTS, surfaceData.normalWS);
AddDecalNormal(posInput.positionSS.xy, normalTS);
AddDecalBaseColor(posInput.positionSS.xy, surfaceData.baseColor);
// Use bent normal to sample GI if available
// If any layer use a bent normal map, then bentNormalTS contain the interpolated result of bentnormal and normalmap (in case no bent normal are available)
// Note: the code in LitDataInternal ensure that we fallback on normal map for layer that have no bentnormal

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


surfaceData.baseColor.xyz = lerp(surfaceData.baseColor.xyz, decalBaseColor.xyz, decalBaseColor.w);
float4 decalNormalWS = SAMPLE_TEXTURE2D(_DBufferTexture1, sampler_DBufferTexture1, texCoords) * float4(2.0f, 2.0f, 2.0f, 1.0f) - float4(1.0f, 1.0f, 1.0f, 0.0f);
surfaceData.normalWS = normalize(lerp(surfaceData.normalWS, decalNormalWS.xyz, decalNormalWS.w));
}
void AddDecalBaseColor(float2 texCoords, inout float3 baseColor)
{
float4 decalBaseColor = SAMPLE_TEXTURE2D(_DBufferTexture0, sampler_DBufferTexture0, texCoords);
baseColor = lerp(baseColor, decalBaseColor.xyz, decalBaseColor.w);
}
void AddDecalNormal(float2 texCoords, inout float3 normalTS)
{
float4 decalNormalTS = SAMPLE_TEXTURE2D(_DBufferTexture1, sampler_DBufferTexture1, texCoords) * float4(2.0f, 2.0f, 2.0f, 1.0f) - float4(1.0f, 1.0f, 1.0f, 0.0f);
if(decalNormalTS.w > 0.0f)
normalTS = normalize(lerp(normalTS, decalNormalTS.xyz, decalNormalTS.w));
//normalTS = (lerp(normalTS, decalNormalTS.xyz, decalNormalTS.w));
}

2
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl


SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
AddDecalToSurfaceData(posInput.positionSS.xy, surfaceData);
// AddDecalToSurfaceData(posInput.positionSS.xy, surfaceData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);

正在加载...
取消
保存