diff --git a/assets/Shaders/FragmentShader.fs b/assets/Shaders/FragmentShader.fs index 95479296..c0b65bf2 100644 --- a/assets/Shaders/FragmentShader.fs +++ b/assets/Shaders/FragmentShader.fs @@ -2,6 +2,7 @@ #extension GL_ARB_shading_language_include : require #include "./lib/lights.fs" #include "./lib/material.fs" +#include "./lib/standarduniform.fs" //Shaders/FragmentShader.fs diff --git a/assets/Shaders/VertexShader.vs b/assets/Shaders/VertexShader.vs index e977ca9e..a3f8d23c 100644 --- a/assets/Shaders/VertexShader.vs +++ b/assets/Shaders/VertexShader.vs @@ -1,5 +1,7 @@ //Vertex Shader #version 450 core +#extension GL_ARB_shading_language_include : require +#include "./lib/standarduniform.fs" @@ -12,11 +14,7 @@ layout (location = 4) in vec2 aTex; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; //bone related variables const int MAX_WEIGHTS = 4; @@ -58,14 +56,14 @@ void main() { //push frag, normal, and texture positions to fragment shader FragPos = vec3(model * FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = mat3(transpose(inverse(model))) * FinalNormal.xyz; TexCoord = aTex; //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * model * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * model * FinalVertex; } \ No newline at end of file diff --git a/assets/Shaders/core/lightDepth/lightDepth.vs b/assets/Shaders/core/lightDepth/lightDepth.vs index 9ee21066..6f65ab35 100644 --- a/assets/Shaders/core/lightDepth/lightDepth.vs +++ b/assets/Shaders/core/lightDepth/lightDepth.vs @@ -1,9 +1,12 @@ -#version 330 core +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" + + layout (location = 0) in vec3 aPos; layout (location = 2) in vec4 aWeights; layout (location = 3) in vec4 aIndex; -uniform mat4 lightSpaceMatrix; uniform mat4 model; //bone related variables @@ -23,5 +26,5 @@ void main(){ FinalVertex = vec4(aPos, 1.0); - gl_Position = lightSpaceMatrix * model * FinalVertex; + gl_Position = standardUniforms.lightSpaceMatrix * model * FinalVertex; } \ No newline at end of file diff --git a/assets/Shaders/core/oit/general/FragmentShader.fs b/assets/Shaders/core/oit/general/FragmentShader.fs index fdc79af0..7dc2e1b5 100644 --- a/assets/Shaders/core/oit/general/FragmentShader.fs +++ b/assets/Shaders/core/oit/general/FragmentShader.fs @@ -2,6 +2,7 @@ #extension GL_ARB_shading_language_include : require #include "../../../lib/lights.fs" #include "../../../lib/material.fs" +#include "../../../lib/standarduniform.fs" layout (location = 0) out vec4 accum; diff --git a/assets/Shaders/core/oit/general/VertexShader.vs b/assets/Shaders/core/oit/general/VertexShader.vs index b017a842..6ce2f637 100644 --- a/assets/Shaders/core/oit/general/VertexShader.vs +++ b/assets/Shaders/core/oit/general/VertexShader.vs @@ -1,5 +1,7 @@ //Vertex Shader -#version 400 core +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../../lib/standarduniform.fs" @@ -12,11 +14,7 @@ layout (location = 4) in vec2 aTex; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; //bone related variables const int MAX_WEIGHTS = 4; @@ -58,14 +56,14 @@ void main() { //push frag, normal, and texture positions to fragment shader FragPos = vec3(model * FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = mat3(transpose(inverse(model))) * FinalNormal.xyz; TexCoord = aTex; //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * model * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * model * FinalVertex; } \ No newline at end of file diff --git a/assets/Shaders/entities/block/block.vs b/assets/Shaders/entities/block/block.vs index 861f3f16..643a7c69 100644 --- a/assets/Shaders/entities/block/block.vs +++ b/assets/Shaders/entities/block/block.vs @@ -1,5 +1,7 @@ //Vertex Shader -#version 330 core +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" //defines #define TEXTURE_MAP_SCALE 1.0 @@ -14,11 +16,7 @@ layout (location = 5) in int samplerIndices; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; @@ -41,7 +39,7 @@ void main() { //push frag, normal, and texture positions to fragment shader FragPos = vec3(model * FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = mat3(transpose(inverse(model))) * aNormal; uv = aTex; @@ -50,9 +48,9 @@ void main() { //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * model * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * model * FinalVertex; } diff --git a/assets/Shaders/entities/foliage/foliage.fs b/assets/Shaders/entities/foliage/foliage.fs index da5cfcc0..4fd959f9 100644 --- a/assets/Shaders/entities/foliage/foliage.fs +++ b/assets/Shaders/entities/foliage/foliage.fs @@ -2,6 +2,7 @@ #extension GL_ARB_shading_language_include : require #include "../../lib/lights.fs" #include "../../lib/material.fs" +#include "../../lib/standarduniform.fs" //foliage.fs @@ -22,22 +23,13 @@ in vec3 normalRot2; uniform dvec3 viewPos; -// uniform DirLight dirLight; -// uniform PointLight pointLights[NR_POINT_LIGHTS]; -// uniform SpotLight spotLight; uniform Material material; //texture stuff -// uniform sampler2D ourTexture; -uniform int hasTransparency; -// uniform sampler2D specularTexture; uniform vec3 baseColor; uniform vec3 tipColor; -uniform mat4 view; - - /** The output */ diff --git a/assets/Shaders/entities/foliage/foliage.vs b/assets/Shaders/entities/foliage/foliage.vs index 28c30b60..961bb49e 100644 --- a/assets/Shaders/entities/foliage/foliage.vs +++ b/assets/Shaders/entities/foliage/foliage.vs @@ -1,7 +1,8 @@ //Vertex Shader -#version 430 core +#version 450 core #extension GL_ARB_shading_language_include : require #include "../../lib/material.fs" +#include "../../lib/standarduniform.fs" @@ -27,14 +28,8 @@ uniform Material material; uniform sampler2D dataMap; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; -uniform dvec3 viewPos; uniform vec3 modelWorldPos; -uniform float time; /** @@ -96,7 +91,7 @@ void main() { zOffset + modelWorldPos.z, 1.0 ); - float curveFloatNoiseSample = clamp(map(openSimplex2_ImproveXY(vec3(worldPos.x,worldPos.z,time)).x,-1.0,1.0,0,1),0,1); + float curveFloatNoiseSample = clamp(map(openSimplex2_ImproveXY(vec3(worldPos.x,worldPos.z,standardUniforms.time)).x,-1.0,1.0,0,1),0,1); // //calculate rotations @@ -106,16 +101,16 @@ void main() { float windDirectionSpeedMagnitude = 0.05; vec3 windDirectionMovementOverTime = vec3( - windDirectionSpeedMagnitude * time, - windDirectionSpeedMagnitude * time, + windDirectionSpeedMagnitude * standardUniforms.time, + windDirectionSpeedMagnitude * standardUniforms.time, 0 ); float windStrengthMagnitude = 0.2; vec3 windStrengthOverTime = vec3( - windStrengthMagnitude * time, - windStrengthMagnitude * time, + windStrengthMagnitude * standardUniforms.time, + windStrengthMagnitude * standardUniforms.time, 0 ); @@ -160,7 +155,7 @@ void main() { //shift in viewspace to make it feel slightly fuller // //dot view and normal - vec3 viewDir = normalize(vec3(viewPos) - FinalVertex.xyz); + vec3 viewDir = normalize(vec3(standardUniforms.viewPos) - FinalVertex.xyz); float viewDotNormal = clamp(dot(FinalNormal.xz,viewDir.xz),0,1); //calculate thinkening factor to shift verts slightly based on view angle float viewSpaceThickenFactor = easeOut(1.0 - viewDotNormal); @@ -174,17 +169,17 @@ void main() { //push frag, normal, and texture positions to fragment shader // FragPos = vec3(FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = vec3(FinalNormal); TexCoord = aTex; //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * FinalVertex; } mat4 rotation3dX(float angle) { diff --git a/assets/Shaders/entities/skybox/FragmentShaderNoTexture.fs b/assets/Shaders/entities/skybox/FragmentShaderNoTexture.fs index 738ffe92..8c317899 100644 --- a/assets/Shaders/entities/skybox/FragmentShaderNoTexture.fs +++ b/assets/Shaders/entities/skybox/FragmentShaderNoTexture.fs @@ -1,6 +1,6 @@ -#version 330 core +#version 450 core out vec4 FragColor; diff --git a/assets/Shaders/entities/skybox/VertexShaderNoTexture.vs b/assets/Shaders/entities/skybox/VertexShaderNoTexture.vs index 82e15797..8dc779e3 100644 --- a/assets/Shaders/entities/skybox/VertexShaderNoTexture.vs +++ b/assets/Shaders/entities/skybox/VertexShaderNoTexture.vs @@ -1,5 +1,7 @@ //Vertex Shader -#version 330 core +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" @@ -9,10 +11,7 @@ layout (location = 1) in float id; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; @@ -29,6 +28,6 @@ void main() //send color to the frag shader color = colors[int(id)]; //set final position with opengl space - vec4 pos = projection * view * model * FinalVertex; + vec4 pos = standardUniforms.projection * standardUniforms.view * model * FinalVertex; gl_Position = pos.xyww; } diff --git a/assets/Shaders/entities/skysphere/skysphere.fs b/assets/Shaders/entities/skysphere/skysphere.fs index 7b1c7181..5dd9b44e 100644 --- a/assets/Shaders/entities/skysphere/skysphere.fs +++ b/assets/Shaders/entities/skysphere/skysphere.fs @@ -1,6 +1,8 @@ #version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" /** diff --git a/assets/Shaders/entities/skysphere/skysphere.vs b/assets/Shaders/entities/skysphere/skysphere.vs index bf0f47ec..723c5741 100644 --- a/assets/Shaders/entities/skysphere/skysphere.vs +++ b/assets/Shaders/entities/skysphere/skysphere.vs @@ -1,6 +1,7 @@ //Vertex Shader -#version 330 core - +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" //input buffers @@ -10,11 +11,7 @@ layout (location = 4) in vec2 aTex; //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; @@ -36,15 +33,15 @@ void main() { //push frag, normal, and texture positions to fragment shader FragPos = vec3(model * FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = mat3(transpose(inverse(model))) * aNormal; TexCoord = aTex; //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * model * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * model * FinalVertex; } diff --git a/assets/Shaders/entities/terrain2/terrain2.fs b/assets/Shaders/entities/terrain2/terrain2.fs index 5ad2dbba..2029fa1d 100644 --- a/assets/Shaders/entities/terrain2/terrain2.fs +++ b/assets/Shaders/entities/terrain2/terrain2.fs @@ -2,6 +2,7 @@ #extension GL_ARB_shading_language_include : require #include "../../lib/lights.fs" #include "../../lib/material.fs" +#include "../../lib/standarduniform.fs" //texture defines #define ATLAS_ELEMENT_DIM 256.0 @@ -35,7 +36,6 @@ uniform dvec3 viewPos; // uniform PointLight pointLights[NR_POINT_LIGHTS]; // uniform SpotLight spotLight; uniform Material material; -uniform mat4 view; /** diff --git a/assets/Shaders/entities/terrain2/terrain2.vs b/assets/Shaders/entities/terrain2/terrain2.vs index e9ebfcc5..4bc4c69e 100644 --- a/assets/Shaders/entities/terrain2/terrain2.vs +++ b/assets/Shaders/entities/terrain2/terrain2.vs @@ -1,5 +1,7 @@ //Vertex Shader -#version 330 core +#version 450 core +#extension GL_ARB_shading_language_include : require +#include "../../lib/standarduniform.fs" //defines #define TEXTURE_MAP_SCALE 1.0 @@ -15,11 +17,7 @@ layout (location = 6) in vec3 samplerRatioVectors; //the interpolated ratio of H //coordinate space transformation matrices -uniform mat4 transform; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; @@ -45,7 +43,7 @@ void main() { //push frag, normal, and texture positions to fragment shader FragPos = vec3(model * FinalVertex); - ViewFragPos = vec3(view * model * FinalVertex); + ViewFragPos = vec3(standardUniforms.view * model * FinalVertex); Normal = mat3(transpose(inverse(model))) * aNormal; // //clamp the aPos vector to just shy of its surrounding values @@ -68,11 +66,11 @@ void main() { //shadow map stuff - FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0); + FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0); //set final position with opengl space - gl_Position = projection * view * model * FinalVertex; + gl_Position = standardUniforms.projection * standardUniforms.view * model * FinalVertex; } diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 12d5ebc6..27fd9769 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1974,6 +1974,7 @@ Performance improvements - Far-away entities do not spawn physics by default - Clustering terrain draw calls - Reduce allocations in some rendering paths + - Leverage standard uniforms buffer Lod emitter service checker function Mesh profiling Upgrade target framerate diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 4f7a3ff1..2c57ded1 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -700,11 +700,13 @@ public class PhysicsEntityUtils { * @return The rigid body created (note, attachment has already been performed) */ public static void clientAttachTriGeomRigidBody(Entity terrain, TriGeomData data){ + CollisionEngine.lockOde(); DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), data, Collidable.TYPE_STATIC_BIT); CollisionBodyCreation.setAutoDisable(Globals.clientState.clientSceneWrapper.getCollisionEngine(), terrainBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); Collidable collidable = new Collidable(terrain,Collidable.TYPE_STATIC, false); Globals.clientState.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, collidable); PhysicsEntityUtils.setDBody(terrain,terrainBody); + CollisionEngine.unlockOde(); terrain.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); } @@ -715,10 +717,12 @@ public class PhysicsEntityUtils { * @return The rigid body created (note, attachment has already been performed) */ public static void clientAttachTriGeomCollider(Entity terrain, TriGeomData data){ + CollisionEngine.lockOde(); DGeom terrainGeom = CollisionBodyCreation.generateGeomFromTerrainData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), data, Collidable.TYPE_STATIC_BIT); Collidable collidable = new Collidable(terrain,Collidable.TYPE_STATIC, true); PhysicsEntityUtils.setCollidable(terrain, collidable); Globals.clientState.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainGeom, collidable); + CollisionEngine.unlockOde(); PhysicsEntityUtils.setDGeom(terrain,terrainGeom); } diff --git a/src/main/java/electrosphere/renderer/model/Mesh.java b/src/main/java/electrosphere/renderer/model/Mesh.java index f3b5192a..cda51b2a 100644 --- a/src/main/java/electrosphere/renderer/model/Mesh.java +++ b/src/main/java/electrosphere/renderer/model/Mesh.java @@ -563,14 +563,9 @@ public class Mesh { //buffer model/view/proj matrices try(MemoryStack stack = MemoryStack.stackPush()){ openGLState.getActiveShader().setUniform(openGLState, "model", parent.getModelMatrix()); - openGLState.getActiveShader().setUniform(openGLState, "view", Globals.renderingEngine.getViewMatrix()); - openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.renderingEngine.getProjectionMatrix()); openGLState.getActiveShader().setUniform(openGLState, "viewPos", CameraEntityUtils.getCameraEye(Globals.clientState.playerCamera)); Vector3f worldPos = new Vector3f((float)parent.getWorldPos().x,(float)parent.getWorldPos().y,(float)parent.getWorldPos().z); openGLState.getActiveShader().setUniform(openGLState, "modelWorldPos", worldPos); - openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.renderingEngine.getLightDepthMatrix()); - openGLState.getActiveShader().setUniform(openGLState, "frame", (int)Globals.engineState.timekeeper.getNumberOfRenderFramesElapsed()); - openGLState.getActiveShader().setUniform(openGLState, "time", (float)Globals.engineState.timekeeper.getCurrentRendererTime()); openGLState.glBindBufferBase(StandardUniformManager.STANDARD_UNIFORM_BUFFER_BIND_POINT, Globals.renderingEngine.getStandardUniformManager().getStandardUnifomSSBO()); } Globals.renderingEngine.checkError();