浏览代码

Fix POM tiling issues (height, shadows)

/Branch_Batching2
Evgenii Golubev 7 年前
当前提交
e72d74a0
共有 2 个文件被更改,包括 12 次插入9 次删除
  1. 16
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  2. 5
      Assets/ScriptableRenderPipeline/ShaderLibrary/PerPixelDisplacement.hlsl

16
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


#if defined(_HEIGHTMAP)
maxDisplacement = _HeightAmplitude;
#endif
// TODO: explain this 0.5 factor. It is likely related to the fact that
// setting the amplitude to 2 in the UI only results in the max. displacement of 1.
return 0.5 * maxDisplacement;
return maxDisplacement;
}
// Return the minimun uv size for all layers including triplanar

// Since POM "pushes" geometry inwards (rather than extrude it), { height = height - 1 }.
// Since the result is used as a 'depthOffsetVS', it needs to be positive, so we flip the sign.
float verticalDisplacement = maxHeight - height * maxHeight;
return verticalDisplacement / NdotV;
// IDEA: precompute the tiling scale? MOV-MUL vs MOV-MOV-MAX-RCP-MUL.
float tilingScale = rcp(max(_BaseColorMap_ST.x, _BaseColorMap_ST.y));
return tilingScale * verticalDisplacement / NdotV;
}
return 0.0;

float height = (SAMPLE_UVMAPPING_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base, lod).r - _HeightCenter) * _HeightAmplitude;
#ifdef _TESSELLATION_TILING_SCALE
// When we change the tiling, we have want to conserve the ratio with the displacement (and this is consistent with per pixel displacement)
height /= max(_BaseColorMap_ST.x, _BaseColorMap_ST.y);
// IDEA: precompute the tiling scale? MOV-MUL vs MOV-MOV-MAX-RCP-MUL.
float tilingScale = rcp(max(_BaseColorMap_ST.x, _BaseColorMap_ST.y));
height *= tilingScale;
#endif
return height;
}

// Since POM "pushes" geometry inwards (rather than extrude it), { height = height - 1 }.
// Since the result is used as a 'depthOffsetVS', it needs to be positive, so we flip the sign.
float verticalDisplacement = maxHeight - height * maxHeight;
return verticalDisplacement / NdotV;
// IDEA: precompute the tiling scale? MOV-MUL vs MOV-MOV-MAX-RCP-MUL.
float tilingScale = rcp(max(_BaseColorMap_ST.x, _BaseColorMap_ST.y));
return tilingScale * verticalDisplacement / NdotV;
}
return 0.0;

5
Assets/ScriptableRenderPipeline/ShaderLibrary/PerPixelDisplacement.hlsl


// ref: https://www.gamedev.net/resources/_/technical/graphics-programming-and-theory/a-closer-look-at-parallax-occlusion-mapping-r3262
float2 ParallaxOcclusionMapping(float lod, float lodThreshold, int numSteps, float3 viewDirTS, float maxHeight, PerPixelHeightDisplacementParam ppdParam, out float outHeight)
{
// TEMP: 1/5 to achieve parity between tessellation and POM w.r.t. height for a single tile.
// TODO: explain this factor. Is there a connection with the number of samples?
maxHeight *= 0.2;
// TODO: explain this factor! Necessary to achieve parity between tessellation and POM w.r.t. height.
maxHeight *= 0.1;
// Convention: 1.0 is top, 0.0 is bottom - POM is always inward, no extrusion
float stepSize = 1.0 / (float)numSteps;

正在加载...
取消
保存