浏览代码

HDRenderPipeline: Version that work but have a tiling bug. Push for julien

/main
sebastienlagarde 8 年前
当前提交
69e1e4fa
共有 2 个文件被更改,包括 26 次插入16 次删除
  1. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  2. 32
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl


// Change the number of samples per ray depending on the viewing angle for the surface.
// Oblique angles require smaller step sizes to achieve more accurate precision for computing displacement.
// int numSteps = (int)lerp(_PPPMaxSamples, _PPPMinSamples, viewDirTS.z);
int numSteps = (int)lerp(15, 15, viewDirTS.z);
int numSteps = (int)lerp(15, 15, viewDirTS.z); // TEMP
ParallaxOcclusionMappingLayer(layerTexCoord, numSteps, viewDirTS);

ApplyPerPixelDisplacement(input, V, layerTexCoord);
float height0 = SampleHeightmap0(LayerTexCoord layerTexCoord);
float height1 = SampleHeightmap1(LayerTexCoord layerTexCoord);
float height2 = SampleHeightmap2(LayerTexCoord layerTexCoord);
float height3 = SampleHeightmap3(LayerTexCoord layerTexCoord);
float height0 = SampleHeightmap0(layerTexCoord);
float height1 = SampleHeightmap1(layerTexCoord);
float height2 = SampleHeightmap2(layerTexCoord);
float height3 = SampleHeightmap3(layerTexCoord);
float depthOffset = 0.0;
#ifdef _DEPTHOFFSET_ON

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


float ADD_IDX(SampleHeightmap)(LayerTexCoord layerTexCoord)
{
#ifdef _HEIGHTMAP
return (SAMPLE_TEXTURE2D(ADD_IDX(_HeightMap), ADD_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv).r - ADD_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
return (SAMPLE_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv).r - ADD_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
#else
return 0.0;
#endif

float2 uv = ADD_IDX(layerTexCoord.base).uv;
// Compute lod as we will sample inside a lop (so can't use regular sampling)
float lod = CALCULATE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_IDX(sampler_HeightMap), uv);
float lod = CALCULATE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv);
float prevHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv + texOffsetCurrent, lod).r * ADD_IDX(_HeightAmplitude);
float prevHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
float currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv + texOffsetCurrent, lod).r * ADD_IDX(_HeightAmplitude);
float currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
float rayHeight = 1.0 - stepSize; // Start at top less one sample
// Linear search

texOffsetCurrent += texOffsetPerStep;
// Sample height map which in this case is stored in the alpha channel of the normal map:
currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv + texOffsetCurrent, lod).r * ADD_IDX(_HeightAmplitude);
currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
float t0 = rayHeight + stepSize;
float t1 = rayHeight;
float delta0 = t0 - prevHeight;
float delta1 = t1 - currHeight;
/*
float t0 = rayHeight + stepSize;
float t1 = rayHeight;
float delta0 = t0 - prevHeight;
float delta1 = t1 - currHeight;
*/
float delta0 = currHeight - rayHeight;
float delta1 = (rayHeight + stepSize) - prevHeight;
float ratio = delta0 / (delta0 + delta1);
float2 offset = (ratio) * (texOffsetCurrent - texOffsetPerStep) + (1.0 - ratio) * texOffsetCurrent;
// Apply offset
// Apply offset only on base. Details could use another mapping and will not be consistant...
// Don't know if this will still ok.
// TODO: check with artists
ADD_IDX(layerTexCoord.details).uv += offset;
}
// Return opacity

正在加载...
取消
保存