浏览代码

HDRenderPipeline: Parrallax occlusion mapping add lod fading

/main
Sebastien Lagarde 8 年前
当前提交
52f90645
共有 4 个文件被更改,包括 31 次插入1 次删除
  1. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  2. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  3. 17
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  4. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


float2 uv = ADD_IDX(layerTexCoord.base).uv;
// Compute lod as we will sample inside a loop (so can't use regular sampling)
float lod = CALCULATE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv);
// It appear that CALCULATE_TEXTURE2D_LOD only return interger lod. We want to use float lod to have smoother transition and fading
// float lod = CALCULATE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv);
float lod = ComputeTextureLOD(uv, GET_TEXELSIZE_NAME(ADD_IDX(_HeightMap)));
// Do a first step before the loop to init all value correctly
float2 texOffsetCurrent = 0;

float2 offset = texOffsetCurrent - ratio * texOffsetPerStep;
#endif
// TODO: expose LOD fading
//float lodThreshold = 0.0;
//offset *= (1.0 - saturate(lod - lodThreshold));
// Apply offset only on base. Details could use another mapping and will not be consistant...
// Don't know if this will still ok.

5
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);
float4 _HeightMap_TexelSize; // Unity facility. This will provide the size of the heightmap to the shader
float _HeightAmplitude;
float _HeightCenter;

PROP_DECL(float, _NormalScale);
PROP_DECL_TEX2D(_HeightMap);
float4 _HeightMap0_TexelSize;
float4 _HeightMap1_TexelSize;
float4 _HeightMap2_TexelSize;
float4 _HeightMap3_TexelSize;
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);

17
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


}
// ----------------------------------------------------------------------------
// Texture utilities
// ----------------------------------------------------------------------------
// texelSize is Unity XXX_TexelSize feature parameters
// x contains 1.0/width, y contains 1.0 / height, z contains width, w contains height
float ComputeTextureLOD(float2 uv, float4 texelSize)
{
uv *= texelSize.zw;
float2 ddx_ = ddx(uv);
float2 ddy_ = ddy(uv);
float d = max(dot(ddx_, ddx_), dot(ddy_, ddy_));
return max(0.5 * log2(d), 0.0);
}
// ----------------------------------------------------------------------------
// Texture format sampling
// ----------------------------------------------------------------------------

2
Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl


// Transforms 2D UV by scale/bias property
#define TRANSFORM_TEX(tex, name) ((tex.xy) * name##_ST.xy + name##_ST.zw)
#define GET_TEXELSIZE_NAME(name) (name##_TexelSize)
#endif // UNITY_COMMON_MATERIAL_INCLUDED
正在加载...
取消
保存