summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-07-20 19:23:58 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-10 18:08:27 +0100
commit4ae26db5ec12560ee2d76a1bdc78b34a45c7442a (patch)
tree01d9ac9ef41062af5e4f2d676abd3a5528020264
parentAdd a tree to the test render scene (diff)
downloadilt-4ae26db5ec12560ee2d76a1bdc78b34a45c7442a.tar.bz2
ilt-4ae26db5ec12560ee2d76a1bdc78b34a45c7442a.tar.xz
ilt-4ae26db5ec12560ee2d76a1bdc78b34a45c7442a.zip
Pull material lookup functions into a common file
-rw-r--r--gfx/gl/shaders/material.fs34
-rw-r--r--gfx/gl/shaders/materialCommon.glsl35
2 files changed, 36 insertions, 33 deletions
diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs
index 5b93707..94ed024 100644
--- a/gfx/gl/shaders/material.fs
+++ b/gfx/gl/shaders/material.fs
@@ -3,39 +3,7 @@
include(`materialInterface.glsl')
include(`materialOut.glsl')
-
-layout(binding = 0) uniform sampler2D texture0;
-
-float map(uint mapmode, float value)
-{
- switch (mapmode) {
- case 0u: // Repeat
- return fract(value);
- case 1u: // Clamp to edge
- return clamp(0.0, 1.0, value);
- case 2u: // Mirror
- discard;
- case 3u: // Decal
- if (value != clamp(0.0, 1.0, value)) {
- discard;
- }
- }
- return 0;
-}
-
-vec2 map(uvec2 mapmode, vec2 value)
-{
- return vec2(map(mapmode.x, value.x), map(mapmode.y, value.y));
-}
-
-vec4 getTextureColour(MaterialDetail mat, vec2 uv)
-{
- if (mat.textureSize.x > 0) {
- const vec2 tSize = textureSize(texture0, 0);
- uv = (mat.textureOrigin + mat.textureSize * map(mat.mapmode, uv)) / tSize;
- }
- return texture(texture0, uv);
-}
+include(`materialCommon.glsl')
void
main()
diff --git a/gfx/gl/shaders/materialCommon.glsl b/gfx/gl/shaders/materialCommon.glsl
new file mode 100644
index 0000000..a915ce3
--- /dev/null
+++ b/gfx/gl/shaders/materialCommon.glsl
@@ -0,0 +1,35 @@
+layout(binding = 0) uniform sampler2D texture0;
+
+float
+map(uint mapmode, float value)
+{
+ switch (mapmode) {
+ case 0u: // Repeat
+ return fract(value);
+ case 1u: // Clamp to edge
+ return clamp(0.0, 1.0, value);
+ case 2u: // Mirror
+ discard;
+ case 3u: // Decal
+ if (value != clamp(0.0, 1.0, value)) {
+ discard;
+ }
+ }
+ return 0;
+}
+
+vec2
+map(uvec2 mapmode, vec2 value)
+{
+ return vec2(map(mapmode.x, value.x), map(mapmode.y, value.y));
+}
+
+vec4
+getTextureColour(MaterialDetail mat, vec2 uv)
+{
+ if (mat.textureSize.x > 0) {
+ const vec2 tSize = textureSize(texture0, 0);
+ uv = (mat.textureOrigin + mat.textureSize * map(mat.mapmode, uv)) / tSize;
+ }
+ return texture(texture0, uv);
+}