浏览代码

Support depth offset with the triplanar POM

/stochastic_alpha_test
Evgenii Golubev 7 年前
当前提交
9fe5367d
共有 2 个文件被更改,包括 28 次插入20 次删除
  1. 29
      SampleScenes/HDTest/GraphicTest/Parallax Occlusion Mapping/Material/POM - Wood triplanar.mat
  2. 19
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl

29
SampleScenes/HDTest/GraphicTest/Parallax Occlusion Mapping/Material/POM - Wood triplanar.mat


m_PrefabInternal: {fileID: 0}
m_Name: POM - Wood triplanar
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _HEIGHTMAP _MAPPING_TRIPLANAR _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_ShaderKeywords: _DEPTHOFFSET_ON _HEIGHTMAP _MAPPING_TRIPLANAR _NORMALMAP _NORMALMAP_TANGENT_SPACE
_PER_PIXEL_DISPLACEMENT _PER_PIXEL_DISPLACEMENT_OBJECT_SCALE _PER_PIXEL_DISPLACEMENT_TILING_SCALE
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

m_Offset: {x: 0, y: 0}
- _BaseColorMap:
m_Texture: {fileID: 2800000, guid: 927434958f610214aa6a4179f134f5fd, type: 3}
m_Scale: {x: 2, y: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BentNormalMap:
m_Texture: {fileID: 0}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _ATDistance: 1
- _AlbedoAffectEmissive: 0
- _AlphaCutoff: 0.5
- _AlphaCutoffEnable: 0

- _CoatIOR: 0.5
- _CullMode: 2
- _Cutoff: 0.5
- _DepthOffsetEnable: 0
- _DepthOffsetEnable: 1
- _DetailAOScale: 1
- _DetailAlbedoScale: 1
- _DetailHeightScale: 1

- _DstBlend: 0
- _EmissiveColorMode: 1
- _EmissiveIntensity: 0
- _EnablePerPixelDisplacement: 0
- _EnablePerPixelDisplacement: 1
- _EnableSpecularOcclusion: 0
- _EnableVertexDisplacement: 0
- _EnableWind: 0

- _HeightAmplitude: 0.02
- _HeightAmplitude: 0.5
- _HeightMax: 1
- _HeightMin: -1
- _HeightMax: 50
- _HeightMin: 0
- _IOR: 1
- _InvTilingScale: 1
- _MaterialID: 1
- _Metallic: 0
- _Mode: 0

- _PPDLodThreshold: 5
- _PPDMaxSamples: 15
- _PPDMaxSamples: 64
- _PPDPrimitiveLength: 1
- _PPDPrimitiveWidth: 1
- _PerPixelDisplacementTilingScale: 1
- _RefractionMode: 0
- _ShiverDirectionality: 0.5
- _ShiverDrag: 0.2
- _Smoothness: 0.5

- _SubsurfaceProfile: 0
- _SubsurfaceRadius: 1
- _SurfaceType: 0
- _TexWorldScale: 0.1
- _TexWorldScale: 0.2
- _ThicknessMultiplier: 1
- _UVBase: 5
- _UVDetail: 0
- _UVMappingPlanar: 0

- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
- _InvPrimScale: {r: 1, g: 1, b: 0, a: 0}
- _TransmittanceColor: {r: 1, g: 1, b: 1, a: 1}
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMask: {r: 0, g: 0, b: 0, a: 0}

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


// Perform a POM in each direction and modify appropriate texture coordinate
ppdParam.uv = layerTexCoord.base.uvZY;
viewDirTS = float3(V.x > 0.0 ? uvZY : -uvZY, V.x);
viewDirTS *= GetInverseObjectScale().xzy; // Switch from Y-up to Z-up
unitAngle = saturate(FastACosPos(viewDirUV.z) * INV_HALF_PI); // TODO: optimize
unitAngle = saturate(FastACosPos(abs(viewDirUV.z)) * INV_HALF_PI); // TODO: optimize
numSteps = (int)lerp(_PPDMinSamples, _PPDMaxSamples, unitAngle);
float2 offsetZY = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirUV, 1, ppdParam, planeHeight);

height = layerTexCoord.triplanarWeights.x * planeHeight;
NdotV = layerTexCoord.triplanarWeights.x * abs(viewDirTS.z);
viewDirTS *= GetInverseObjectScale().xzy; // Switch from Y-up to Z-up
unitAngle = saturate(FastACosPos(viewDirUV.z) * INV_HALF_PI); // TODO: optimize
unitAngle = saturate(FastACosPos(abs(viewDirUV.z)) * INV_HALF_PI); // TODO: optimize
numSteps = (int)lerp(_PPDMinSamples, _PPDMaxSamples, unitAngle);
float2 offsetXZ = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirUV, 1, ppdParam, planeHeight);

NdotV += layerTexCoord.triplanarWeights.y * abs(viewDirTS.z);
viewDirTS *= GetInverseObjectScale().xzy; // Switch from Y-up to Z-up
unitAngle = saturate(FastACosPos(viewDirUV.z) * INV_HALF_PI); // TODO: optimize
unitAngle = saturate(FastACosPos(abs(viewDirUV.z)) * INV_HALF_PI); // TODO: optimize
numSteps = (int)lerp(_PPDMinSamples, _PPDMaxSamples, unitAngle);
float2 offsetXY = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirUV, 1, ppdParam, planeHeight);

NdotV = 1; // TODO.
NdotV += layerTexCoord.triplanarWeights.z * abs(viewDirTS.z);
}
else
{

float3 viewDirTS = isPlanar ? float3(uvXZ, V.y) : TransformWorldToTangent(V, input.worldToTangent);
viewDirTS *= GetInverseObjectScale().xzy; // Switch from Y-up to Z-up
NdotV = viewDirTS.z;
NdotV = abs(viewDirTS.z);
float unitAngle = saturate(FastACosPos(viewDirUV.z) * INV_HALF_PI); // TODO: optimize
float unitAngle = saturate(FastACosPos(abs(viewDirUV.z)) * INV_HALF_PI); // TODO: optimize
// POM uses a normalized view vector in the UV space to intersect the heightmap within a 1x1x1 box.
float2 offset = ParallaxOcclusionMapping(lod, _PPDLodThreshold, numSteps, viewDirUV, 1, ppdParam, height);
// Apply offset to all UVSet0 / planar

正在加载...
取消
保存