浏览代码

[PlanarReflection] use alpha in sample env for weight

/main
Frédéric Vauchelles 7 年前
当前提交
c423498c
共有 3 个文件被更改,包括 11 次插入16 次删除
  1. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  2. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  3. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


// EnvIndex can also be use to fetch in another array of struct (to atlas information etc...).
// Cubemap : texCoord = direction vector
// Texture2D : texCoord = projectedPositionWS - lightData.capturePosition
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod, out float weight)
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod)
{
// 31 bit index, 1 bit cache type
uint cacheType = index & 1;

float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc, index, 0);
// Discard pixels out of oblique projection
// We only check RGB because the texture may have BC6H compression
weight = any(ndc < 0) || any(ndc > 1) || all(color.rgb >= 1000) ? 0 : 1;
color.a = any(ndc < 0) || any(ndc > 1) || all(color.rgb >= 1000) ? 0 : 1;
weight = 1;
return SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_EnvCubemapTextures, s_trilinear_clamp_sampler, texCoord, index, lod);
float4 color = SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_EnvCubemapTextures, s_trilinear_clamp_sampler, texCoord, index, lod);
color.a = 1;
return color;
weight = 0;
weight = 1;
return SampleSkyTexture(texCoord, lod);
}
}

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


float3 F = preLightData.specularFGD;
float iblMipLevel = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness);
float sampleWeight = 1;
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, iblMipLevel, sampleWeight);
weight *= sampleWeight;
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, iblMipLevel);
weight *= preLD.a;
// Smooth weighting
weight = Smoothstep01(weight);

envLighting *= Sq(1.0 - preLightData.coatIblF);
// Evaluate the Clear Coat color
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, sampleWeight);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0);
envLighting += preLightData.coatIblF * preLD.rgb;
// Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl


if (NdotL > 0.0)
{
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
acc += LambertNoPI() * weightOverPdf * val.rgb;

// in weightOverPdf of ImportanceSampleLambert call.
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotV, bsdfData.perceptualRoughness);
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
acc += disneyDiffuse * weightOverPdf * val.rgb;
}

// Fresnel component is apply here as describe in ImportanceSampleGGX function
float3 FweightOverPdf = F_Schlick(bsdfData.fresnel0, VdotH) * weightOverPdf;
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
acc += FweightOverPdf * val.rgb;
}

正在加载...
取消
保存