Browse Source

Update core shader libraries to support texture arrays

Lukas Aldershaab 4 years ago
parent
commit
6f23dd191d

+ 29 - 0
Templates/BaseGame/game/core/rendering/shaders/gl/torque.glsl

@@ -166,6 +166,35 @@ vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float
    return offset;
    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.
 /// The maximum value for 10bit per component integer HDR encoding.
 const float HDR_RGB10_MAX = 4.0;
 const float HDR_RGB10_MAX = 4.0;
 
 

+ 1 - 0
Templates/BaseGame/game/core/rendering/shaders/shaderModel.hlsl

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

+ 29 - 0
Templates/BaseGame/game/core/rendering/shaders/torque.hlsl

@@ -167,6 +167,35 @@ float2 parallaxOffsetDxtnm(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 neg
    return offset;
    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.
 /// The maximum value for 10bit per component integer HDR encoding.
 static const float HDR_RGB10_MAX = 4.0;
 static const float HDR_RGB10_MAX = 4.0;