Merge pull request #1031 from aws-lumberyard-dev/Atom/santorac/RemoveParallaxInvertFlag-ATOM-15653

ATOM-15653 Remove Unnecessary Parallax Map Invert Flag

Removed the parallax invert flags and instead all the materials assume displacement is always specified as heightmaps.
Updated property naming, tooltips, and shader variable names to reflect this.
Updated ParallaxMapping.azsli to treat depthOffset as an offset in depth value rather than an offset in height value, so it matches the fact that ParallaxMapping.azsli always operates in depth values rather than height values.

Corresponding ASV changes: aws-lumberyard/o3de-atom-sampleviewer#83
main
Chris Santora 5 years ago committed by GitHub
commit 0fd69d6d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -469,7 +469,7 @@
"max": 1.0,
"connection": {
"type": "ShaderInput",
"id": "m_depthFactor"
"id": "m_heightmapScale"
}
},
{
@ -479,18 +479,7 @@
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_depthMap"
}
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert to depthmap if the texture is heightmap",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_depthInverted"
"id": "m_heightmap"
}
},
{

@ -935,25 +935,25 @@
"parallax": [
{
"id": "textureMap",
"displayName": "Texture Map",
"description": "Depthmap to create parallax effect.",
"displayName": "Heightmap",
"description": "Displacement heightmap to create parallax effect.",
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_depthMap"
"id": "m_heightmap"
}
},
{
"id": "useTexture",
"displayName": "Use Texture",
"description": "Whether to use the texture map.",
"description": "Whether to use the heightmap.",
"type": "Bool",
"defaultValue": true
},
{
"id": "textureMapUv",
"displayName": "UV",
"description": "Depth texture map UV set",
"description": "Heightmap UV set",
"type": "Enum",
"enumIsUv": true,
"defaultValue": "Tiled",
@ -972,7 +972,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_depthFactor"
"id": "m_heightmapScale"
}
},
{
@ -985,18 +985,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_depthOffset"
}
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert to depthmap if the texture is heightmap",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_depthInverted"
"id": "m_heightmapOffset"
}
},
{

@ -108,7 +108,7 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial
// Callback function for ParallaxMapping.azsli
DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy)
{
return SampleDepthOrHeightMap(MaterialSrg::m_depthInverted, MaterialSrg::m_depthMap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy);
return SampleDepthFromHeightmap(MaterialSrg::m_heightmap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy);
}
COMMON_OPTIONS_PARALLAX()
@ -116,7 +116,7 @@ COMMON_OPTIONS_PARALLAX()
bool ShouldHandleParallax()
{
// Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled.
return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap;
return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useHeightmap;
}
bool ShouldHandleParallaxInDepthShaders()

@ -84,7 +84,7 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace)
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth);
}

@ -141,7 +141,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth, IN.m_position.w, displacementIsClipped);

@ -88,7 +88,7 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace)
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth);

@ -22,15 +22,14 @@
// You can optionally provide a prefix for the set of inputs which corresponds to a prefix string supplied by the .materialtype file. This is common for multi-layered material types.
#define COMMON_SRG_INPUTS_PARALLAX(prefix) \
Texture2D prefix##m_depthMap; \
float prefix##m_depthFactor; \
float prefix##m_depthOffset; \
bool prefix##m_depthInverted;
Texture2D prefix##m_heightmap; \
float prefix##m_heightmapScale; \
float prefix##m_heightmapOffset;
#define COMMON_OPTIONS_PARALLAX(prefix) \
option bool prefix##o_useDepthMap;
option bool prefix##o_useHeightmap;
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, float depthOffset,
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS, out bool isClipped)
{
@ -48,8 +47,8 @@ void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float dep
dirToCamera = ViewSrg::m_worldPosition.xyz - worldPosition;
}
ParallaxOffset tangentOffset = GetParallaxOffset( depthFactor,
depthOffset,
ParallaxOffset tangentOffset = GetParallaxOffset( heightmapScale,
-heightmapOffset,
uv,
dirToCamera,
tangent,
@ -62,7 +61,7 @@ void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float dep
if(o_parallax_enablePixelDepthOffset)
{
PixelDepthOffset pdo = CalcPixelDepthOffset(depthFactor,
PixelDepthOffset pdo = CalcPixelDepthOffset(heightmapScale,
tangentOffset.m_offsetTS,
worldPosition,
tangent,
@ -81,19 +80,19 @@ void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float dep
}
}
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, float depthOffset,
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS)
{
bool isClipped;
GetParallaxInput(normal, tangent, bitangent, depthFactor, depthOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS, isClipped);
GetParallaxInput(normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS, isClipped);
}
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, float depthOffset,
void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
inout float2 uv, inout float3 worldPosition, inout float depthNDC)
{
float depthCS;
GetParallaxInput(normal, tangent, bitangent, depthFactor, depthOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS);
GetParallaxInput(normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS);
}

@ -1109,43 +1109,32 @@
"layer1_parallax": [
{
"id": "textureMap",
"displayName": "Texture Map",
"description": "Displacement texture map, which can be used for layer blending and/or a parallax effect.",
"displayName": "Heightmap",
"description": "Displacement heightmap, which can be used for layer blending and/or a parallax effect.",
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_layer1_m_depthMap"
"id": "m_layer1_m_heightmap"
}
},
{
"id": "useTexture",
"displayName": "Use Texture",
"description": "Whether to use the texture map.",
"description": "Whether to use the heightmap.",
"type": "Bool",
"defaultValue": true
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert the displacement map",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_layer1_m_depthInverted"
}
},
{
"id": "factor",
"displayName": "Scale",
"description": "The total height of the displacement texture map in local model units.",
"description": "The total height of the heightmap in local model units.",
"type": "Float",
"defaultValue": 0.05,
"min": 0.0,
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer1_m_depthFactor"
"id": "m_layer1_m_heightmapScale"
}
},
{
@ -1158,7 +1147,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer1_m_depthOffset"
"id": "m_layer1_m_heightmapOffset"
}
}
],
@ -1815,43 +1804,32 @@
"layer2_parallax": [
{
"id": "textureMap",
"displayName": "Texture Map",
"description": "Displacement texture map, which can be used for layer blending and/or a parallax effect.",
"displayName": "Heightmap",
"description": "Displacement heightmap, which can be used for layer blending and/or a parallax effect.",
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_layer2_m_depthMap"
"id": "m_layer2_m_heightmap"
}
},
{
"id": "useTexture",
"displayName": "Use Texture",
"description": "Whether to use the texture map.",
"description": "Whether to use the heightmap.",
"type": "Bool",
"defaultValue": true
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert the displacement map",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_layer2_m_depthInverted"
}
},
{
"id": "factor",
"displayName": "Scale",
"description": "The total height of the displacement texture map in local model units.",
"description": "The total height of the heightmap in local model units.",
"type": "Float",
"defaultValue": 0.05,
"min": 0.0,
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer2_m_depthFactor"
"id": "m_layer2_m_heightmapScale"
}
},
{
@ -1864,7 +1842,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer2_m_depthOffset"
"id": "m_layer2_m_heightmapOffset"
}
}
],
@ -2521,43 +2499,32 @@
"layer3_parallax": [
{
"id": "textureMap",
"displayName": "Texture Map",
"description": "Displacement texture map, which can be used for layer blending and/or a parallax effect.",
"displayName": "Heightmap",
"description": "Displacement heightmap, which can be used for layer blending and/or a parallax effect.",
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_layer3_m_depthMap"
"id": "m_layer3_m_heightmap"
}
},
{
"id": "useTexture",
"displayName": "Use Texture",
"description": "Whether to use the texture map.",
"description": "Whether to use the heightmap.",
"type": "Bool",
"defaultValue": true
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert the displacement map",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_layer3_m_depthInverted"
}
},
{
"id": "factor",
"displayName": "Scale",
"description": "The total height of the displacement texture map in local model units.",
"description": "The total height of the heightmap in local model units.",
"type": "Float",
"defaultValue": 0.05,
"min": 0.0,
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer3_m_depthFactor"
"id": "m_layer3_m_heightmapScale"
}
},
{
@ -2570,7 +2537,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_layer3_m_depthOffset"
"id": "m_layer3_m_heightmapOffset"
}
}
],
@ -2837,8 +2804,8 @@
"args": {
"textureProperty": "layer1_parallax.textureMap",
"useTextureProperty": "layer1_parallax.useTexture",
"dependentProperties": ["layer1_parallax.factor", "layer1_parallax.invert"],
"shaderOption": "o_layer1_o_useDepthMap"
"dependentProperties": ["layer1_parallax.factor"],
"shaderOption": "o_layer1_o_useHeightmap"
}
},
{
@ -2974,8 +2941,8 @@
"args": {
"textureProperty": "layer2_parallax.textureMap",
"useTextureProperty": "layer2_parallax.useTexture",
"dependentProperties": ["layer2_parallax.factor", "layer2_parallax.invert"],
"shaderOption": "o_layer2_o_useDepthMap"
"dependentProperties": ["layer2_parallax.factor"],
"shaderOption": "o_layer2_o_useHeightmap"
}
},
{
@ -3111,8 +3078,8 @@
"args": {
"textureProperty": "layer3_parallax.textureMap",
"useTextureProperty": "layer3_parallax.useTexture",
"dependentProperties": ["layer3_parallax.factor", "layer3_parallax.invert"],
"shaderOption": "o_layer3_o_useDepthMap"
"dependentProperties": ["layer3_parallax.factor"],
"shaderOption": "o_layer3_o_useHeightmap"
}
},
{

@ -379,7 +379,7 @@ float3 GetLayerDepthValues(float2 uv, float2 uv_ddx, float2 uv_ddy)
// layer1
{
if(o_layer1_o_useDepthMap)
if(o_layer1_o_useHeightmap)
{
float2 layerUv = uv;
if(MaterialSrg::m_parallaxUvIndex == 0)
@ -387,16 +387,16 @@ float3 GetLayerDepthValues(float2 uv, float2 uv_ddx, float2 uv_ddy)
layerUv = mul(MaterialSrg::m_layer1_m_uvMatrix, float3(uv, 1.0)).xy;
}
layerDepthValues.r = SampleDepthOrHeightMap(MaterialSrg::m_layer1_m_depthInverted, MaterialSrg::m_layer1_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.r *= MaterialSrg::m_layer1_m_depthFactor;
layerDepthValues.r = SampleDepthFromHeightmap(MaterialSrg::m_layer1_m_heightmap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.r *= MaterialSrg::m_layer1_m_heightmapScale;
}
layerDepthValues.r -= MaterialSrg::m_layer1_m_depthOffset;
layerDepthValues.r -= MaterialSrg::m_layer1_m_heightmapOffset;
}
if(o_layer2_enabled)
{
if(o_layer2_o_useDepthMap)
if(o_layer2_o_useHeightmap)
{
float2 layerUv = uv;
if(MaterialSrg::m_parallaxUvIndex == 0)
@ -404,17 +404,17 @@ float3 GetLayerDepthValues(float2 uv, float2 uv_ddx, float2 uv_ddy)
layerUv = mul(MaterialSrg::m_layer2_m_uvMatrix, float3(uv, 1.0)).xy;
}
layerDepthValues.g = SampleDepthOrHeightMap(MaterialSrg::m_layer2_m_depthInverted, MaterialSrg::m_layer2_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.g *= MaterialSrg::m_layer2_m_depthFactor;
layerDepthValues.g = SampleDepthFromHeightmap(MaterialSrg::m_layer2_m_heightmap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.g *= MaterialSrg::m_layer2_m_heightmapScale;
}
layerDepthValues.g -= MaterialSrg::m_layer2_m_depthOffset;
layerDepthValues.g -= MaterialSrg::m_layer2_m_heightmapOffset;
}
if(o_layer3_enabled)
{
if(o_layer3_o_useDepthMap)
if(o_layer3_o_useHeightmap)
{
float2 layerUv = uv;
if(MaterialSrg::m_parallaxUvIndex == 0)
@ -422,11 +422,11 @@ float3 GetLayerDepthValues(float2 uv, float2 uv_ddx, float2 uv_ddy)
layerUv = mul(MaterialSrg::m_layer3_m_uvMatrix, float3(uv, 1.0)).xy;
}
layerDepthValues.b = SampleDepthOrHeightMap(MaterialSrg::m_layer3_m_depthInverted, MaterialSrg::m_layer3_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.b *= MaterialSrg::m_layer3_m_depthFactor;
layerDepthValues.b = SampleDepthFromHeightmap(MaterialSrg::m_layer3_m_heightmap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth;
layerDepthValues.b *= MaterialSrg::m_layer3_m_heightmapScale;
}
layerDepthValues.b -= MaterialSrg::m_layer3_m_depthOffset;
layerDepthValues.b -= MaterialSrg::m_layer3_m_heightmapOffset;
}
@ -448,13 +448,13 @@ float3 ApplyBlendMaskToDepthValues(float3 blendMaskValues, float3 layerDepthValu
if(o_layer2_enabled)
{
float dropoffRange = MaterialSrg::m_layer2_m_depthOffset - zeroMaskDisplacement;
float dropoffRange = MaterialSrg::m_layer2_m_heightmapOffset - zeroMaskDisplacement;
layerDepthValues.g += dropoffRange * (1-blendMaskValues.r);
}
if(o_layer3_enabled)
{
float dropoffRange = MaterialSrg::m_layer3_m_depthOffset - zeroMaskDisplacement;
float dropoffRange = MaterialSrg::m_layer3_m_heightmapOffset - zeroMaskDisplacement;
layerDepthValues.b += dropoffRange * (1-blendMaskValues.g);
}
}

@ -881,25 +881,25 @@
"parallax": [
{
"id": "textureMap",
"displayName": "Texture Map",
"description": "Depthmap to create parallax effect.",
"displayName": "Heightmap",
"description": "Displacement heightmap to create parallax effect.",
"type": "Image",
"connection": {
"type": "ShaderInput",
"id": "m_depthMap"
"id": "m_heightmap"
}
},
{
"id": "useTexture",
"displayName": "Use Texture",
"description": "Whether to use the texture map.",
"description": "Whether to use the heightmap.",
"type": "Bool",
"defaultValue": true
},
{
"id": "textureMapUv",
"displayName": "UV",
"description": "Depth texture map UV set",
"description": "Heightmap UV set",
"type": "Enum",
"enumIsUv": true,
"defaultValue": "Tiled",
@ -918,7 +918,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_depthFactor"
"id": "m_heightmapScale"
}
},
{
@ -931,18 +931,7 @@
"softMax": 0.1,
"connection": {
"type": "ShaderInput",
"id": "m_depthOffset"
}
},
{
"id": "invert",
"displayName": "Invert",
"description": "Invert to depthmap if the texture is heightmap",
"type": "Bool",
"defaultValue": true,
"connection": {
"type": "ShaderInput",
"id": "m_depthInverted"
"id": "m_heightmapOffset"
}
},
{

@ -97,7 +97,7 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial
// Callback function for ParallaxMapping.azsli
DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy)
{
return SampleDepthOrHeightMap(MaterialSrg::m_depthInverted, MaterialSrg::m_depthMap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy);
return SampleDepthFromHeightmap(MaterialSrg::m_heightmap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy);
}
@ -106,7 +106,7 @@ COMMON_OPTIONS_PARALLAX()
bool ShouldHandleParallax()
{
// Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled.
return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap;
return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useHeightmap;
}
bool ShouldHandleParallaxInDepthShaders()

@ -86,7 +86,7 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace)
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth);
}

@ -130,7 +130,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depthNDC, IN.m_position.w, displacementIsClipped);

@ -17,7 +17,7 @@ function GetMaterialPropertyDependencies()
end
function GetShaderOptionDependencies()
return {"o_parallax_feature_enabled", "o_useDepthMap"}
return {"o_parallax_feature_enabled", "o_useHeightmap"}
end
function Process(context)
@ -25,7 +25,7 @@ function Process(context)
local useTexture = context:GetMaterialPropertyValue_bool("parallax.useTexture")
local enable = textureMap ~= nil and useTexture
context:SetShaderOptionValue_bool("o_parallax_feature_enabled", enable)
context:SetShaderOptionValue_bool("o_useDepthMap", enable)
context:SetShaderOptionValue_bool("o_useHeightmap", enable)
end
function ProcessEditor(context)

@ -88,7 +88,7 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace)
float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3();
float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3();
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset,
GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset,
ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse,
IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth);

@ -58,7 +58,7 @@ DepthResult DepthResultAbsolute(float depth)
//! The client shader must define this function.
//! This allows the client shader to implement special depth map sampling, for example procedurally generating or blending depth maps.
//! In simple cases though, the implementation of GetDepth() can simply call SampleDepthOrHeightMap().
//! In simple cases though, the implementation of GetDepth() can simply call SampleDepthFromHeightmap().
//! @param uv the UV coordinates to use for sampling
//! @param uv_ddx will be set to ddx_fine(uv)
//! @param uv_ddy will be set to ddy_fine(uv)
@ -66,13 +66,12 @@ DepthResult DepthResultAbsolute(float depth)
DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy);
//! Convenience function that can be used to implement GetDepth().
//! @param isHeightmap indicates whether to sample the map is a height map rather than a depth map.
//! @return see struct DepthResult. In this case it will always contain a Code::Normalized result.
DepthResult SampleDepthOrHeightMap(bool isHeightmap, Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
DepthResult SampleDepthFromHeightmap(Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
{
DepthResult result;
result.m_resultCode = DepthResultCode_Normalized;
result.m_depth = abs((isHeightmap * 1.0) - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r);
result.m_depth = 1.0 - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r;
return result;
}
@ -169,20 +168,20 @@ ParallaxOffset AdvancedParallaxMapping(float depthFactor, float depthOffset, flo
float2 ddx_uv = ddx_fine(uv);
float2 ddy_uv = ddy_fine(uv);
float depthSearchStart = -depthOffset;
float depthSearchStart = depthOffset;
float depthSearchEnd = depthSearchStart + depthFactor;
float inverseDepthFactor = 1.0 / depthFactor;
// This is the relative position at which we begin searching for intersection.
// It is adjusted according to the depthOffset, raising or lowering the whole surface by depthOffset units.
float3 parallaxOffset = dirToCameraTS.xyz * dirToCameraZInverse * depthOffset;
float3 parallaxOffset = -dirToCameraTS.xyz * dirToCameraZInverse * depthOffset;
// Get an initial heightmap sample to start the intersection search, starting at our initial parallaxOffset position.
float currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
float prevSample;
// Note that when depthOffset < 0, we could actually narrow the search so that instead of going through the entire [depthSearchStart,depthSearchEnd] range
// Note that when depthOffset > 0, we could actually narrow the search so that instead of going through the entire [depthSearchStart,depthSearchEnd] range
// of the heightmap, we could go through the range [0,depthSearchEnd]. This would give more accurate results and fewer artifacts
// in case where the magnitude of depthOffset is significant. But for the sake of simplicity we currently search the whole range in all cases.
@ -271,7 +270,7 @@ ParallaxOffset AdvancedParallaxMapping(float depthFactor, float depthOffset, flo
}
// Even though we do a bunch of clamping above when calling GetClampedDepth(), there are still cases where the parallax offset
// can be noticeably above the surface and still needs to be clamped here. The main case is when depthFactor==0 and depthOffset>1.
// can be noticeably above the surface and still needs to be clamped here. The main case is when depthFactor==0 and depthOffset<1.
if(parallaxOffset.z > 0.0)
{
parallaxOffset = float3(0,0,0);
@ -371,13 +370,13 @@ ParallaxOffset CalculateParallaxOffset(float depthFactor, float depthOffset, flo
// @param dirToCameraTS - normalized direction to the camera, in tangent space.
// @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow).
ParallaxOffset GetParallaxOffset( float depthFactor,
float depthOffset,
float2 uv,
float3 dirToCameraWS,
float3 tangentWS,
float3 bitangentWS,
float3 normalWS,
float3x3 uvMatrix)
float depthOffset,
float2 uv,
float3 dirToCameraWS,
float3 tangentWS,
float3 bitangentWS,
float3 normalWS,
float3x3 uvMatrix)
{
// Tangent space eye vector
float3 dirToCameraTS = normalize(WorldSpaceToTangent(dirToCameraWS, normalWS, tangentWS, bitangentWS));

Loading…
Cancel
Save