Backport terrain shaders to version 330 core

This commit is contained in:
Retera 2020-12-19 01:02:20 -05:00
parent 03c3d34aa3
commit a5d4085e47
3 changed files with 177 additions and 306 deletions

View File

@ -8,6 +8,7 @@ import java.nio.FloatBuffer;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.etheller.warsmash.datasources.DataSource;
import com.etheller.warsmash.parsers.mdlx.Geoset;
import com.etheller.warsmash.parsers.mdlx.MdlxModel;
@ -71,7 +72,7 @@ public class CliffMesh {
this.renderJobs.put(position);
}
public void render() {
public void render(final ShaderProgram cliffShader) {
if (this.renderJobs.position() == 0) {
return;
}
@ -82,23 +83,24 @@ public class CliffMesh {
GL20.GL_DYNAMIC_DRAW);
this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.vertexBuffer);
this.gl.glVertexAttribPointer(0, 3, GL20.GL_FLOAT, false, 0, 0);
this.gl.glVertexAttribPointer(cliffShader.getAttributeLocation("vPosition"), 3, GL20.GL_FLOAT, false, 0, 0);
this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.uvBuffer);
this.gl.glVertexAttribPointer(1, 2, GL20.GL_FLOAT, false, 0, 0);
this.gl.glVertexAttribPointer(cliffShader.getAttributeLocation("vUV"), 2, GL20.GL_FLOAT, false, 0, 0);
this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.normalBuffer);
this.gl.glVertexAttribPointer(2, 3, GL20.GL_FLOAT, false, 0, 0);
this.gl.glVertexAttribPointer(cliffShader.getAttributeLocation("vNormal"), 3, GL20.GL_FLOAT, false, 0, 0);
this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.instanceBuffer);
this.gl.glVertexAttribPointer(3, 4, GL20.GL_FLOAT, false, 0, 0);
this.gl.glVertexAttribDivisor(3, 1);
final int offsetAttributeLocation = cliffShader.getAttributeLocation("vOffset");
this.gl.glVertexAttribPointer(offsetAttributeLocation, 4, GL20.GL_FLOAT, false, 0, 0);
this.gl.glVertexAttribDivisor(offsetAttributeLocation, 1);
this.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, this.indexBuffer);
this.gl.glDrawElementsInstanced(GL20.GL_TRIANGLES, this.indices, GL30.GL_UNSIGNED_SHORT, 0,
this.renderJobs.remaining() / 4);
this.gl.glVertexAttribDivisor(3, 0); // ToDo use vao
this.gl.glVertexAttribDivisor(offsetAttributeLocation, 0); // ToDo use vao
this.renderJobs.clear();
}

View File

@ -66,7 +66,6 @@ public class Terrain {
public ShaderProgram groundShader;
public ShaderProgram waterShader;
public ShaderProgram cliffShader;
public ShaderProgram testShader;
public float waterIndex;
public float waterIncreasePerFrame;
public float waterHeightOffset;
@ -399,7 +398,6 @@ public class Terrain {
this.groundShader = webGL.createShaderProgram(TerrainShaders.Terrain.vert, TerrainShaders.Terrain.frag);
this.cliffShader = webGL.createShaderProgram(TerrainShaders.Cliffs.vert, TerrainShaders.Cliffs.frag);
this.waterShader = webGL.createShaderProgram(TerrainShaders.Water.vert, TerrainShaders.Water.frag);
this.testShader = webGL.createShaderProgram(TerrainShaders.Test.vert, TerrainShaders.Test.frag);
this.uberSplatShader = webGL.createShaderProgram(W3xShaders.UberSplat.vert, W3xShaders.UberSplat.frag);
@ -902,15 +900,35 @@ public class Terrain {
gl.glUniformMatrix4fv(this.groundShader.getUniformLocation("DepthBiasMVP"), 1, false,
dynamicShadowManager.getDepthBiasMVP().val, 0);
gl.glUniform1i(this.groundShader.getUniformLocation("cliff_textures"), 0);
gl.glActiveTexture(GL30.GL_TEXTURE0);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.groundHeight);
gl.glActiveTexture(GL30.GL_TEXTURE1);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.groundCornerHeight);
gl.glUniform1i(this.groundShader.getUniformLocation("pathing_map_static"), 2);
gl.glActiveTexture(GL30.GL_TEXTURE2);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.groundTextureData);
gl.glUniform1i(this.groundShader.getUniformLocation("sample0"), 3);
gl.glUniform1i(this.groundShader.getUniformLocation("sample1"), 4);
gl.glUniform1i(this.groundShader.getUniformLocation("sample2"), 5);
gl.glUniform1i(this.groundShader.getUniformLocation("sample3"), 6);
gl.glUniform1i(this.groundShader.getUniformLocation("sample4"), 7);
gl.glUniform1i(this.groundShader.getUniformLocation("sample5"), 8);
gl.glUniform1i(this.groundShader.getUniformLocation("sample6"), 9);
gl.glUniform1i(this.groundShader.getUniformLocation("sample7"), 10);
gl.glUniform1i(this.groundShader.getUniformLocation("sample8"), 11);
gl.glUniform1i(this.groundShader.getUniformLocation("sample9"), 12);
gl.glUniform1i(this.groundShader.getUniformLocation("sample10"), 13);
gl.glUniform1i(this.groundShader.getUniformLocation("sample11"), 14);
gl.glUniform1i(this.groundShader.getUniformLocation("sample12"), 15);
gl.glUniform1i(this.groundShader.getUniformLocation("sample13"), 16);
gl.glUniform1i(this.groundShader.getUniformLocation("sample14"), 17);
gl.glUniform1i(this.groundShader.getUniformLocation("sample15"), 18);
gl.glUniform1i(this.groundShader.getUniformLocation("sample16"), 19);
gl.glUniform1i(this.groundShader.getUniformLocation("shadowMap"), 20);
for (int i = 0; i < this.groundTextures.size(); i++) {
gl.glActiveTexture(GL30.GL_TEXTURE3 + i);
gl.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.groundTextures.get(i).id);
@ -924,7 +942,7 @@ public class Terrain {
// gl.glEnableVertexAttribArray(0);
gl.glBindBuffer(GL30.GL_ARRAY_BUFFER, Shapes.INSTANCE.vertexBuffer);
gl.glVertexAttribPointer(0, 2, GL30.GL_FLOAT, false, 0, 0);
gl.glVertexAttribPointer(this.groundShader.getAttributeLocation("vPosition"), 2, GL30.GL_FLOAT, false, 0, 0);
gl.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, Shapes.INSTANCE.indexBuffer);
if (WIREFRAME_TERRAIN) {
@ -942,26 +960,6 @@ public class Terrain {
}
private GL30 renderGroundIntersectionMesh() {
if (true) {
throw new UnsupportedOperationException("No longer supported");
}
this.webGL.useShaderProgram(this.testShader);
final GL30 gl = Gdx.gl30;
gl.glDisable(GL30.GL_CULL_FACE);
gl.glDisable(GL30.GL_BLEND);
this.testShader.setUniformMatrix("MVP", this.camera.viewProjectionMatrix);
gl.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.testArrayBuffer);
this.testShader.setVertexAttribute("vPosition", 3, GL30.GL_FLOAT, false, 12, 0);
gl.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, this.testElementBuffer);
gl.glDrawElements(GL30.GL_LINES, this.softwareGroundMesh.indices.length, GL30.GL_UNSIGNED_SHORT, 0);// );
gl.glEnable(GL30.GL_BLEND);
return gl;
}
public void renderUberSplats(final boolean onTopLayer) {
final GL30 gl = Gdx.gl30;
final WebGL webGL = this.webGL;
@ -1018,24 +1016,29 @@ public class Terrain {
gl.glEnable(GL30.GL_BLEND);
gl.glBlendFunc(GL30.GL_SRC_ALPHA, GL30.GL_ONE_MINUS_SRC_ALPHA);
gl.glUniformMatrix4fv(0, 1, false, this.camera.viewProjectionMatrix.val, 0);
gl.glUniform4fv(1, 1, this.minShallowColor, 0);
gl.glUniform4fv(2, 1, this.maxShallowColor, 0);
gl.glUniform4fv(3, 1, this.minDeepColor, 0);
gl.glUniform4fv(4, 1, this.maxDeepColor, 0);
gl.glUniform1f(5, this.waterHeightOffset);
gl.glUniform1i(6, (int) this.waterIndex);
gl.glUniform1f(this.waterShader.getUniformLocation("centerOffsetX"), this.centerOffset[0]);
gl.glUniform1f(this.waterShader.getUniformLocation("centerOffsetY"), this.centerOffset[1]);
gl.glUniform4fv(11, 1, this.shaderMapBounds, 0);
this.waterShader.setUniformMatrix4fv("MVP", this.camera.viewProjectionMatrix.val, 0, 16);
this.waterShader.setUniform4fv("shallow_color_min", this.minShallowColor, 0, 4);
this.waterShader.setUniform4fv("shallow_color_max", this.maxShallowColor, 0, 4);
this.waterShader.setUniform4fv("deep_color_min", this.minDeepColor, 0, 4);
this.waterShader.setUniform4fv("deep_color_max", this.maxDeepColor, 0, 4);
this.waterShader.setUniformf("water_offset", this.waterHeightOffset);
this.waterShader.setUniformi("current_texture", (int) this.waterIndex);
this.waterShader.setUniformf("centerOffsetX", this.centerOffset[0]);
this.waterShader.setUniformf("centerOffsetY", this.centerOffset[1]);
this.waterShader.setUniform4fv("mapBounds", this.shaderMapBounds, 0, 4);
final W3xSceneLightManager lightManager = (W3xSceneLightManager) this.viewer.worldScene.getLightManager();
final DataTexture terrainLightsTexture = lightManager.getTerrainLightsTexture();
terrainLightsTexture.bind(3);
gl.glUniform1f(9, lightManager.getTerrainLightCount());
gl.glUniform1f(10, terrainLightsTexture.getHeight());
this.waterShader.setUniformi("lightTexture", 3);
this.waterShader.setUniformf("lightCount", lightManager.getTerrainLightCount());
this.waterShader.setUniformf("lightTextureHeight", terrainLightsTexture.getHeight());
this.waterShader.setUniformi("water_height_texture", 0);
this.waterShader.setUniformi("ground_height_texture", 1);
this.waterShader.setUniformi("water_exists_texture", 2);
this.waterShader.setUniformi("water_textures", 4);
gl.glActiveTexture(GL30.GL_TEXTURE0);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.waterHeight);
gl.glActiveTexture(GL30.GL_TEXTURE1);
@ -1046,7 +1049,7 @@ public class Terrain {
gl.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.waterTextureArray);
gl.glBindBuffer(GL30.GL_ARRAY_BUFFER, Shapes.INSTANCE.vertexBuffer);
gl.glVertexAttribPointer(0, 2, GL30.GL_FLOAT, false, 0, 0);
gl.glVertexAttribPointer(this.waterShader.getAttributeLocation("vPosition"), 2, GL30.GL_FLOAT, false, 0, 0);
gl.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, Shapes.INSTANCE.indexBuffer);
gl.glDrawElementsInstanced(GL30.GL_TRIANGLES, Shapes.INSTANCE.quadIndices.length * 3, GL30.GL_UNSIGNED_INT, 0,
@ -1081,9 +1084,8 @@ public class Terrain {
// WC3 models are 128x too large
tempMatrix.set(this.camera.viewProjectionMatrix);
gl.glUniformMatrix4fv(0, 1, false, tempMatrix.val, 0);
gl.glUniform1i(1, this.viewer.renderPathing);
gl.glUniform1i(2, this.viewer.renderLighting);
gl.glUniformMatrix4fv(this.cliffShader.getUniformLocation("MVP"), 1, false, tempMatrix.val, 0);
gl.glUniform1i(this.cliffShader.getUniformLocation("show_lighting"), this.viewer.renderLighting);
final W3xSceneLightManager lightManager = (W3xSceneLightManager) this.viewer.worldScene.getLightManager();
final DataTexture unitLightsTexture = lightManager.getTerrainLightsTexture();
@ -1097,15 +1099,17 @@ public class Terrain {
gl.glActiveTexture(GL30.GL_TEXTURE2);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.shadowMap);
this.cliffShader.setUniformi("cliff_textures", 0);
gl.glActiveTexture(GL30.GL_TEXTURE0);
gl.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.cliffTextureArray);
this.cliffShader.setUniformi("height_texture", 1);
gl.glActiveTexture(GL30.GL_TEXTURE1);
gl.glBindTexture(GL30.GL_TEXTURE_2D, this.groundHeight);
// gl.glActiveTexture(GL30.GL_TEXTURE2);
for (final CliffMesh i : this.cliffMeshes) {
gl.glUniform1f(this.cliffShader.getUniformLocation("centerOffsetX"), this.centerOffset[0]);
gl.glUniform1f(this.cliffShader.getUniformLocation("centerOffsetY"), this.centerOffset[1]);
i.render();
i.render(this.cliffShader);
}
}

View File

@ -10,29 +10,29 @@ public class TerrainShaders {
private Cliffs() {
}
public static final String vert = "#version 450 core\r\n" + //
public static final String vert = "#version 330 core\r\n" + //
"\r\n" + //
"layout (location = 0) in vec3 vPosition;\r\n" + //
"layout (location = 1) in vec2 vUV;\r\n" + //
"layout (location = 2) in vec3 vNormal;\r\n" + //
"layout (location = 3) in vec4 vOffset;\r\n" + //
"in vec3 vPosition;\r\n" + //
"in vec2 vUV;\r\n" + //
"in vec3 vNormal;\r\n" + //
"in vec4 vOffset;\r\n" + //
"\r\n" + //
"layout (location = 0) uniform mat4 MVP;\r\n" + //
"uniform mat4 MVP;\r\n" + //
"\r\n" + //
"layout (binding = 1) uniform sampler2D height_texture;\r\n" + //
"layout (binding = 3) uniform sampler2D shadowMap;\r\n" + //
"layout (location = 3) uniform float centerOffsetX;\r\n" + //
"layout (location = 4) uniform float centerOffsetY;\r\n" + //
"layout (location = 5) uniform sampler2D lightTexture;\r\n" + //
"layout (location = 6) uniform float lightCount;\r\n" + //
"layout (location = 7) uniform float lightTextureHeight;\r\n" + //
"uniform sampler2D height_texture;\r\n" + //
"uniform sampler2D shadowMap;\r\n" + //
"uniform float centerOffsetX;\r\n" + //
"uniform float centerOffsetY;\r\n" + //
"uniform sampler2D lightTexture;\r\n" + //
"uniform float lightCount;\r\n" + //
"uniform float lightTextureHeight;\r\n" + //
"\r\n" + //
"layout (location = 0) out vec3 UV;\r\n" + //
"layout (location = 1) out vec3 Normal;\r\n" + //
"layout (location = 2) out vec2 pathing_map_uv;\r\n" + //
"layout (location = 3) out vec3 position;\r\n" + //
"layout (location = 4) out vec2 v_suv;\r\n" + //
"layout (location = 5) out vec3 shadeColor;\r\n" + //
"out vec3 UV;\r\n" + //
"out vec3 Normal;\r\n" + //
"out vec2 pathing_map_uv;\r\n" + //
"out vec3 position;\r\n" + //
"out vec2 v_suv;\r\n" + //
"out vec3 shadeColor;\r\n" + //
"\r\n" + //
"void main() {\r\n" + //
" pathing_map_uv = (vec2(vPosition.x + 128, vPosition.y) / 128 + vOffset.xy) * 4;\r\n" + //
@ -61,26 +61,25 @@ public class TerrainShaders {
" vec3 terrain_normal = normalize(vNormal);//vec3(hL - hR, hD - hU, 2.0)+vNormal);\r\n" + //
"\r\n" + //
" Normal = terrain_normal;\r\n" + //
Shaders.lightSystem("terrain_normal", "myposition.xyz", "lightTexture", "lightTextureHeight", "lightCount",
true)
Shaders.lightSystem("terrain_normal", "myposition.xyz", "lightTexture", "lightTextureHeight",
"lightCount", true)
+ "\r\n" + //
" shadeColor = clamp(lightFactor, 0.0, 1.0);\r\n" + //
"}";
public static final String frag = "#version 450 core\r\n" + //
public static final String frag = "#version 330 core\r\n" + //
"\r\n" + //
"layout (binding = 0) uniform sampler2DArray cliff_textures;\r\n" + //
"layout (binding = 2) uniform usampler2D pathing_map_static;\r\n" + //
"layout (binding = 3) uniform sampler2D shadowMap;\r\n" + //
"uniform sampler2DArray cliff_textures;\r\n" + //
"uniform sampler2D shadowMap;\r\n" + //
"\r\n" + //
"layout (location = 1) uniform bool show_pathing_map_static;\r\n" + //
"layout (location = 2) uniform bool show_lighting;\r\n" + //
"uniform bool show_lighting;\r\n" + //
"\r\n" + //
"layout (location = 0) in vec3 UV;\r\n" + //
"layout (location = 1) in vec3 Normal;\r\n" + //
"layout (location = 2) in vec2 pathing_map_uv;\r\n" + //
"layout (location = 4) in vec2 v_suv;\r\n" + //
"layout (location = 5) in vec3 shadeColor;\r\n" + //
"in vec3 UV;\r\n" + //
"in vec3 Normal;\r\n" + //
"in vec2 pathing_map_uv;\r\n" + //
"in vec3 position;\r\n" + //
"in vec2 v_suv;\r\n" + //
"in vec3 shadeColor;\r\n" + //
"\r\n" + //
"out vec4 color;\r\n" + //
"\r\n" + //
@ -93,31 +92,6 @@ public class TerrainShaders {
" color.rgb *= shadeColor;\r\n" + //
" }\r\n" + //
"\r\n" + //
" uvec4 byte = texelFetch(pathing_map_static, ivec2(pathing_map_uv), 0);\r\n" + //
" if (show_pathing_map_static) {\r\n" + //
" vec4 pathing_color = vec4(min(byte.r & 2, 1), min(byte.r & 4, 1), min(byte.r & 8, 1), 0.25);\r\n"
+ //
" color = length(pathing_color.rgb) > 0 ? color * 0.75 + pathing_color * 0.5 : color;\r\n" + //
" }\r\n" + //
"}";
public static final String posFrag = "#version 450 core\r\n" + //
"\r\n" + //
"layout (binding = 0) uniform sampler2DArray cliff_textures;\r\n" + //
"layout (binding = 2) uniform usampler2D pathing_map_static;\r\n" + //
"\r\n" + //
"layout (location = 1) uniform bool show_pathing_map_static;\r\n" + //
"layout (location = 2) uniform bool show_lighting;\r\n" + //
"\r\n" + //
"layout (location = 0) in vec3 UV;\r\n" + //
"layout (location = 1) in vec3 Normal;\r\n" + //
"layout (location = 2) in vec2 pathing_map_uv;\r\n" + //
"layout (location = 3) in vec3 position;\r\n" + //
"\r\n" + //
"out vec4 color;\r\n" + //
"\r\n" + //
"void main() {\r\n" + ///
" color = vec4(position.xyz, 1.0);\r\n" + //
"}";
}
@ -125,28 +99,28 @@ public class TerrainShaders {
private Terrain() {
}
public static final String vert = "#version 450 core\r\n" + //
public static final String vert = "#version 330 core\r\n" + //
"\r\n" + //
"layout (location = 0) in vec2 vPosition;\r\n" + //
"layout (location = 1) uniform mat4 MVP;\r\n" + //
"layout (location = 6) uniform mat4 DepthBiasMVP;\r\n" + //
"in vec2 vPosition;\r\n" + //
"uniform mat4 MVP;\r\n" + //
"uniform mat4 DepthBiasMVP;\r\n" + //
"\r\n" + //
"layout (binding = 0) uniform sampler2D height_texture;\r\n" + //
"layout (binding = 1) uniform sampler2D height_cliff_texture;\r\n" + //
"layout (binding = 2) uniform usampler2D terrain_texture_list;\r\n" + //
"layout (location = 4) uniform float centerOffsetX;\r\n" + //
"layout (location = 5) uniform float centerOffsetY;\r\n" + //
"layout (location = 7) uniform sampler2D lightTexture;\r\n" + //
"layout (location = 8) uniform float lightCount;\r\n" + //
"layout (location = 9) uniform float lightTextureHeight;\r\n" + //
"uniform sampler2D height_texture;\r\n" + //
"uniform sampler2D height_cliff_texture;\r\n" + //
"uniform usampler2D terrain_texture_list;\r\n" + //
"uniform float centerOffsetX;\r\n" + //
"uniform float centerOffsetY;\r\n" + //
"uniform sampler2D lightTexture;\r\n" + //
"uniform float lightCount;\r\n" + //
"uniform float lightTextureHeight;\r\n" + //
"\r\n" + //
"layout (location = 0) out vec2 UV;\r\n" + //
"layout (location = 1) out flat uvec4 texture_indices;\r\n" + //
"layout (location = 2) out vec2 pathing_map_uv;\r\n" + //
"layout (location = 4) out vec3 position;\r\n" + //
"layout (location = 5) out vec3 ShadowCoord;\r\n" + //
"layout (location = 6) out vec2 v_suv;\r\n" + //
"layout (location = 7) out vec3 shadeColor;\r\n" + //
"out vec2 UV;\r\n" + //
"flat out uvec4 texture_indices;\r\n" + //
"out vec2 pathing_map_uv;\r\n" + //
"out vec3 position;\r\n" + //
"out vec3 ShadowCoord;\r\n" + //
"out vec2 v_suv;\r\n" + //
"out vec3 shadeColor;\r\n" + //
"\r\n" + //
"void main() { \r\n" + //
" ivec2 size = textureSize(terrain_texture_list, 0);\r\n" + //
@ -170,9 +144,9 @@ public class TerrainShaders {
" vec3 positionWorld = vec3((vPosition.x + pos.x)*128.0 + centerOffsetX, (vPosition.y + pos.y)*128.0 + centerOffsetY, height.r*128.0);\r\n"
+ //
" position = positionWorld;\r\n" + //
" gl_Position = ((texture_indices.a & 32768) == 0) ? MVP * vec4(position.xyz, 1) : vec4(2.0, 0.0, 0.0, 1.0);\r\n"
" gl_Position = ((texture_indices.a & 32768u) == 0u) ? MVP * vec4(position.xyz, 1) : vec4(2.0, 0.0, 0.0, 1.0);\r\n"
+ //
" ShadowCoord = (((texture_indices.a & 32768) == 0) ? DepthBiasMVP * vec4(position.xyz, 1) : vec4(2.0, 0.0, 0.0, 1.0)).xyz;\r\n"
" ShadowCoord = (((texture_indices.a & 32768u) == 0u) ? DepthBiasMVP * vec4(position.xyz, 1) : vec4(2.0, 0.0, 0.0, 1.0)).xyz;\r\n"
+ //
" v_suv = (vPosition + pos) / size;\r\n" + //
" position.x = (position.x - centerOffsetX) / (size.x * 128.0);\r\n" + //
@ -182,42 +156,42 @@ public class TerrainShaders {
" shadeColor = clamp(lightFactor, 0.0, 1.0);\r\n" + //
"}";
public static final String frag = "#version 450 core\r\n" + //
public static final String frag = "#version 330 core\r\n" + //
"\r\n" + //
"layout (location = 2) uniform bool show_pathing_map;\r\n" + //
"layout (location = 3) uniform bool show_lighting;\r\n" + //
"uniform bool show_pathing_map;\r\n" + //
"uniform bool show_lighting;\r\n" + //
"\r\n" + //
"layout (binding = 3) uniform sampler2DArray sample0;\r\n" + //
"layout (binding = 4) uniform sampler2DArray sample1;\r\n" + //
"layout (binding = 5) uniform sampler2DArray sample2;\r\n" + //
"layout (binding = 6) uniform sampler2DArray sample3;\r\n" + //
"layout (binding = 7) uniform sampler2DArray sample4;\r\n" + //
"layout (binding = 8) uniform sampler2DArray sample5;\r\n" + //
"layout (binding = 9) uniform sampler2DArray sample6;\r\n" + //
"layout (binding = 10) uniform sampler2DArray sample7;\r\n" + //
"layout (binding = 11) uniform sampler2DArray sample8;\r\n" + //
"layout (binding = 12) uniform sampler2DArray sample9;\r\n" + //
"layout (binding = 13) uniform sampler2DArray sample10;\r\n" + //
"layout (binding = 14) uniform sampler2DArray sample11;\r\n" + //
"layout (binding = 15) uniform sampler2DArray sample12;\r\n" + //
"layout (binding = 16) uniform sampler2DArray sample13;\r\n" + //
"layout (binding = 17) uniform sampler2DArray sample14;\r\n" + //
"layout (binding = 18) uniform sampler2DArray sample15;\r\n" + //
"layout (binding = 19) uniform sampler2DArray sample16;\r\n" + //
"uniform sampler2DArray sample0;\r\n" + //
"uniform sampler2DArray sample1;\r\n" + //
"uniform sampler2DArray sample2;\r\n" + //
"uniform sampler2DArray sample3;\r\n" + //
"uniform sampler2DArray sample4;\r\n" + //
"uniform sampler2DArray sample5;\r\n" + //
"uniform sampler2DArray sample6;\r\n" + //
"uniform sampler2DArray sample7;\r\n" + //
"uniform sampler2DArray sample8;\r\n" + //
"uniform sampler2DArray sample9;\r\n" + //
"uniform sampler2DArray sample10;\r\n" + //
"uniform sampler2DArray sample11;\r\n" + //
"uniform sampler2DArray sample12;\r\n" + //
"uniform sampler2DArray sample13;\r\n" + //
"uniform sampler2DArray sample14;\r\n" + //
"uniform sampler2DArray sample15;\r\n" + //
"uniform sampler2DArray sample16;\r\n" + //
"\r\n" + //
// "layout (binding = 20) uniform usampler2D pathing_map_static;\r\n" + //
// "layout (binding = 21) uniform usampler2D pathing_map_dynamic;\r\n" + //
"layout (binding = 20) uniform sampler2D shadowMap;\r\n" + //
"uniform sampler2D shadowMap;\r\n" + //
"\r\n" + //
"layout (location = 0) in vec2 UV;\r\n" + //
"layout (location = 1) in flat uvec4 texture_indices;\r\n" + //
"layout (location = 2) in vec2 pathing_map_uv;\r\n" + //
"layout (location = 4) in vec3 position;\r\n" + //
"layout (location = 5) in vec3 ShadowCoord;\r\n" + //
"layout (location = 6) in vec2 v_suv;\r\n" + //
"layout (location = 7) in vec3 shadeColor;\r\n" + //
"in vec2 UV;\r\n" + //
"flat in uvec4 texture_indices;\r\n" + //
"in vec2 pathing_map_uv;\r\n" + //
"in vec3 position;\r\n" + //
"in vec3 ShadowCoord;\r\n" + //
"in vec2 v_suv;\r\n" + //
"in vec3 shadeColor;\r\n" + //
"\r\n" + //
"layout (location = 0) out vec4 color;\r\n" + //
"out vec4 color;\r\n" + //
// "layout (location = 1) out vec4 position;\r\n" + //
"\r\n" + //
"vec4 get_fragment(uint id, vec3 uv) {\r\n" + //
@ -225,53 +199,53 @@ public class TerrainShaders {
" vec2 dy = dFdy(uv.xy);\r\n" + //
"\r\n" + //
" switch(id) {\r\n" + //
" case 0:\r\n" + //
" case 0u:\r\n" + //
" return textureGrad(sample0, uv, dx, dy);\r\n" + //
" case 1:\r\n" + //
" case 1u:\r\n" + //
" return textureGrad(sample1, uv, dx, dy);\r\n" + //
" case 2:\r\n" + //
" case 2u:\r\n" + //
" return textureGrad(sample2, uv, dx, dy);\r\n" + //
" case 3:\r\n" + //
" case 3u:\r\n" + //
" return textureGrad(sample3, uv, dx, dy);\r\n" + //
" case 4:\r\n" + //
" case 4u:\r\n" + //
" return textureGrad(sample4, uv, dx, dy);\r\n" + //
" case 5:\r\n" + //
" case 5u:\r\n" + //
" return textureGrad(sample5, uv, dx, dy);\r\n" + //
" case 6:\r\n" + //
" case 6u:\r\n" + //
" return textureGrad(sample6, uv, dx, dy);\r\n" + //
" case 7:\r\n" + //
" case 7u:\r\n" + //
" return textureGrad(sample7, uv, dx, dy);\r\n" + //
" case 8:\r\n" + //
" case 8u:\r\n" + //
" return textureGrad(sample8, uv, dx, dy);\r\n" + //
" case 9:\r\n" + //
" case 9u:\r\n" + //
" return textureGrad(sample9, uv, dx, dy);\r\n" + //
" case 10:\r\n" + //
" case 10u:\r\n" + //
" return textureGrad(sample10, uv, dx, dy);\r\n" + //
" case 11:\r\n" + //
" case 11u:\r\n" + //
" return textureGrad(sample11, uv, dx, dy);\r\n" + //
" case 12:\r\n" + //
" case 12u:\r\n" + //
" return textureGrad(sample12, uv, dx, dy);\r\n" + //
" case 13:\r\n" + //
" case 13u:\r\n" + //
" return textureGrad(sample13, uv, dx, dy);\r\n" + //
" case 14:\r\n" + //
" case 14u:\r\n" + //
" return textureGrad(sample14, uv, dx, dy);\r\n" + //
" case 15:\r\n" + //
" case 15u:\r\n" + //
" return textureGrad(sample15, uv, dx, dy);\r\n" + //
" case 16:\r\n" + //
" case 16u:\r\n" + //
" return textureGrad(sample16, uv, dx, dy);\r\n" + //
" case 17:\r\n" + //
" case 17u:\r\n" + //
" return vec4(0, 0, 0, 0);\r\n" + //
" }\r\n" + //
"}\r\n" + //
"\r\n" + //
"\r\n" + //
"void main() {\r\n" + //
" color = get_fragment(texture_indices.a & 31, vec3(UV, texture_indices.a >> 5));\r\n" + //
" color = color * color.a + get_fragment(texture_indices.b & 31, vec3(UV, texture_indices.b >> 5)) * (1 - color.a);\r\n"
" color = get_fragment(texture_indices.a & 31u, vec3(UV, texture_indices.a >> 5));\r\n" + //
" color = color * color.a + get_fragment(texture_indices.b & 31u, vec3(UV, texture_indices.b >> 5)) * (1 - color.a);\r\n"
+ //
" color = color * color.a + get_fragment(texture_indices.g & 31, vec3(UV, texture_indices.g >> 5)) * (1 - color.a);\r\n"
" color = color * color.a + get_fragment(texture_indices.g & 31u, vec3(UV, texture_indices.g >> 5)) * (1 - color.a);\r\n"
+ //
" color = color * color.a + get_fragment(texture_indices.r & 31, vec3(UV, texture_indices.r >> 5)) * (1 - color.a);\r\n"
" color = color * color.a + get_fragment(texture_indices.r & 31u, vec3(UV, texture_indices.r >> 5)) * (1 - color.a);\r\n"
+ //
" float shadow = texture2D(shadowMap, v_suv).r;\r\n" + //
// " float visibility = 1.0;\r\n" + //
@ -297,140 +271,31 @@ public class TerrainShaders {
// + //
// " }\r\n" + //
"}";
public static final String posFrag = "#version 450 core\r\n" + //
"\r\n" + //
"layout (location = 2) uniform bool show_pathing_map;\r\n" + //
"layout (location = 3) uniform bool show_lighting;\r\n" + //
"\r\n" + //
"layout (binding = 3) uniform sampler2DArray sample0;\r\n" + //
"layout (binding = 4) uniform sampler2DArray sample1;\r\n" + //
"layout (binding = 5) uniform sampler2DArray sample2;\r\n" + //
"layout (binding = 6) uniform sampler2DArray sample3;\r\n" + //
"layout (binding = 7) uniform sampler2DArray sample4;\r\n" + //
"layout (binding = 8) uniform sampler2DArray sample5;\r\n" + //
"layout (binding = 9) uniform sampler2DArray sample6;\r\n" + //
"layout (binding = 10) uniform sampler2DArray sample7;\r\n" + //
"layout (binding = 11) uniform sampler2DArray sample8;\r\n" + //
"layout (binding = 12) uniform sampler2DArray sample9;\r\n" + //
"layout (binding = 13) uniform sampler2DArray sample10;\r\n" + //
"layout (binding = 14) uniform sampler2DArray sample11;\r\n" + //
"layout (binding = 15) uniform sampler2DArray sample12;\r\n" + //
"layout (binding = 16) uniform sampler2DArray sample13;\r\n" + //
"layout (binding = 17) uniform sampler2DArray sample14;\r\n" + //
"layout (binding = 18) uniform sampler2DArray sample15;\r\n" + //
"layout (binding = 19) uniform sampler2DArray sample16;\r\n" + //
"\r\n" + //
"layout (binding = 20) uniform usampler2D pathing_map_static;\r\n" + //
"layout (binding = 21) uniform usampler2D pathing_map_dynamic;\r\n" + //
"\r\n" + //
"layout (location = 0) in vec2 UV;\r\n" + //
"layout (location = 1) in flat uvec4 texture_indices;\r\n" + //
"layout (location = 2) in vec2 pathing_map_uv;\r\n" + //
"layout (location = 3) in vec3 normal;\r\n" + //
"layout (location = 4) in vec3 position;\r\n" + //
"\r\n" + //
"layout (location = 0) out vec4 color;\r\n" + //
"\r\n" + //
"vec4 get_fragment(uint id, vec3 uv) {\r\n" + //
" vec2 dx = dFdx(uv.xy);\r\n" + //
" vec2 dy = dFdy(uv.xy);\r\n" + //
"\r\n" + //
" switch(id) {\r\n" + //
" case 0:\r\n" + //
" return textureGrad(sample0, uv, dx, dy);\r\n" + //
" case 1:\r\n" + //
" return textureGrad(sample1, uv, dx, dy);\r\n" + //
" case 2:\r\n" + //
" return textureGrad(sample2, uv, dx, dy);\r\n" + //
" case 3:\r\n" + //
" return textureGrad(sample3, uv, dx, dy);\r\n" + //
" case 4:\r\n" + //
" return textureGrad(sample4, uv, dx, dy);\r\n" + //
" case 5:\r\n" + //
" return textureGrad(sample5, uv, dx, dy);\r\n" + //
" case 6:\r\n" + //
" return textureGrad(sample6, uv, dx, dy);\r\n" + //
" case 7:\r\n" + //
" return textureGrad(sample7, uv, dx, dy);\r\n" + //
" case 8:\r\n" + //
" return textureGrad(sample8, uv, dx, dy);\r\n" + //
" case 9:\r\n" + //
" return textureGrad(sample9, uv, dx, dy);\r\n" + //
" case 10:\r\n" + //
" return textureGrad(sample10, uv, dx, dy);\r\n" + //
" case 11:\r\n" + //
" return textureGrad(sample11, uv, dx, dy);\r\n" + //
" case 12:\r\n" + //
" return textureGrad(sample12, uv, dx, dy);\r\n" + //
" case 13:\r\n" + //
" return textureGrad(sample13, uv, dx, dy);\r\n" + //
" case 14:\r\n" + //
" return textureGrad(sample14, uv, dx, dy);\r\n" + //
" case 15:\r\n" + //
" return textureGrad(sample15, uv, dx, dy);\r\n" + //
" case 16:\r\n" + //
" return textureGrad(sample16, uv, dx, dy);\r\n" + //
" case 17:\r\n" + //
" return vec4(0, 0, 0, 0);\r\n" + //
" }\r\n" + //
"}\r\n" + //
"\r\n" + //
"\r\n" + //
"void main() {\r\n" + //
" color = vec4(position.xyz, 1.0);\r\n" + //
"}";
}
public static final class Test {
private Test() {
}
public static final String vert = "#version 450 core\r\n" + //
"\r\n" + //
"layout (location = 0) in vec3 vPosition;\r\n" + //
"layout (location = 1) uniform mat4 MVP;\r\n" + //
"\r\n" + //
"\r\n" + //
"void main() { \r\n" + //
" gl_Position = MVP * vec4(vPosition, 1.0);\r\n" + //
"}";
public static final String frag = "#version 450 core\r\n" + //
"\r\n" + //
"\r\n" + //
"layout (location = 0) out vec4 color;\r\n" + //
"\r\n" + //
"\r\n" + //
"\r\n" + //
"void main() {\r\n" + //
" color = vec4(1.0,1.0,1.0,1.0);\r\n" + //
"}";
}
public static final class Water {
private Water() {
}
public static final String vert = "#version 450 core\r\n" + //
public static final String vert = "#version 330 core\r\n" + //
"\r\n" + //
"layout (location = 0) in vec2 vPosition;\r\n" + //
"in vec2 vPosition;\r\n" + //
"\r\n" + //
"layout (binding = 0) uniform sampler2D water_height_texture;\r\n" + //
"layout (binding = 1) uniform sampler2D ground_height_texture;\r\n" + //
"layout (binding = 2) uniform sampler2D water_exists_texture;\r\n" + //
"layout (location = 7) uniform float centerOffsetX;\r\n" + //
"layout (location = 8) uniform float centerOffsetY;\r\n" + //
"uniform sampler2D water_height_texture;\r\n" + //
"uniform sampler2D ground_height_texture;\r\n" + //
"uniform sampler2D water_exists_texture;\r\n" + //
"uniform float centerOffsetX;\r\n" + //
"uniform float centerOffsetY;\r\n" + //
"\r\n" + //
"layout (location = 0) uniform mat4 MVP;\r\n" + //
"layout (location = 1) uniform vec4 shallow_color_min;\r\n" + //
"layout (location = 2) uniform vec4 shallow_color_max;\r\n" + //
"layout (location = 3) uniform vec4 deep_color_min;\r\n" + //
"layout (location = 4) uniform vec4 deep_color_max;\r\n" + //
"layout (location = 5) uniform float water_offset;\r\n" + //
"layout (binding = 3) uniform sampler2D lightTexture;\r\n" + //
"layout (location = 9) uniform float lightCount;\r\n" + //
"layout (location = 10) uniform float lightTextureHeight;\r\n" + //
"uniform mat4 MVP;\r\n" + //
"uniform vec4 shallow_color_min;\r\n" + //
"uniform vec4 shallow_color_max;\r\n" + //
"uniform vec4 deep_color_min;\r\n" + //
"uniform vec4 deep_color_max;\r\n" + //
"uniform float water_offset;\r\n" + //
"uniform sampler2D lightTexture;\r\n" + //
"uniform float lightCount;\r\n" + //
"uniform float lightTextureHeight;\r\n" + //
"\r\n" + //
"out vec2 UV;\r\n" + //
"out vec4 Color;\r\n" + //
@ -475,14 +340,14 @@ public class TerrainShaders {
" shadeColor = clamp(lightFactor, 0.0, 1.0);\r\n" + //
" }";
public static final String frag = "#version 450 core\r\n" + //
public static final String frag = "#version 330 core\r\n" + //
"\r\n" + //
"layout (binding = 4) uniform sampler2DArray water_textures;\r\n" + //
"layout (binding = 2) uniform sampler2D water_exists_texture;\r\n" + //
"uniform sampler2DArray water_textures;\r\n" + //
"uniform sampler2D water_exists_texture;\r\n" + //
"\r\n" + //
"\r\n" + //
"layout (location = 6) uniform int current_texture;\r\n" + //
"layout (location = 11) uniform vec4 mapBounds;\r\n" + //
"uniform int current_texture;\r\n" + //
"uniform vec4 mapBounds;\r\n" + //
"\r\n" + //
"in vec2 UV;\r\n" + //
"in vec4 Color;\r\n" + //