Update core shader libraries to support texture arrays

This commit is contained in:
Lukas Aldershaab 2021-01-02 03:19:51 +01:00
parent 3c8d07a03e
commit 6f23dd191d
3 changed files with 59 additions and 0 deletions

View file

@ -166,6 +166,35 @@ vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float
return offset;
}
/// Same as the above but for arrays
vec2 parallaxOffset( sampler2DArray texMap, vec3 texCoord, vec3 negViewTS, float depthScale )
{
float depth = texture( texMap, texCoord ).a/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
{
depth = ( depth + texture( texMap, texCoord + vec3(offset, 0.0) ).a )/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
vec2 parallaxOffsetDxtnm(sampler2DArray texMap, vec3 texCoord, vec3 negViewTS, float depthScale)
{
float depth = texture(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + texture(texMap, texCoord + vec3(offset, 0.0)).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
/// The maximum value for 10bit per component integer HDR encoding.
const float HDR_RGB10_MAX = 4.0;

View file

@ -60,6 +60,7 @@
//helper if you want to pass sampler/texture in a function
//2D
#define TORQUE_SAMPLER2D(tex) Texture2D texture_##tex, SamplerState tex
#define TORQUE_SAMPLER2DARRAY(tex) Texture2DArray texture_##tex, SamplerState tex
#define TORQUE_SAMPLER2D_MAKEARG(tex) texture_##tex, tex
// Sampler comparison state - use above MAKEARG with this
#define TORQUE_SAMPLER2DCMP(tex) Texture2D texture_##tex, SamplerComparisonState tex

View file

@ -167,6 +167,35 @@ float2 parallaxOffsetDxtnm(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 neg
return offset;
}
/// Copy of the above to functions, but for arrays
float2 parallaxOffsetTexArray(TORQUE_SAMPLER2DARRAY(texMap), float3 texCoord, float3 negViewTS, float depthScale)
{
float depth = TORQUE_TEX2D(texMap, texCoord).a/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + TORQUE_TEX2D(texMap, texCoord + float3(offset, 0.0)).a)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
}
return offset;
}
float2 parallaxOffsetDxtnmTexArray(TORQUE_SAMPLER2DARRAY(texMap), float3 texCoord, float3 negViewTS, float depthScale)
{
float depth = TORQUE_TEX2D(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + TORQUE_TEX2D(texMap, texCoord + float3(offset, 0.0)).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
/// The maximum value for 10bit per component integer HDR encoding.
static const float HDR_RGB10_MAX = 4.0;