From 4111680755d1378a76b983052d9b7c43a01a42bf Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 7 May 2021 23:22:40 -0700 Subject: [PATCH] FLWFinalizeWorld takes care of assigning gl_Position --- .../assets/create/flywheel/shaders/belt.vert | 9 +----- .../flywheel/shaders/contraption/builtin.vert | 9 +++++- .../flywheel/shaders/contraption_actor.vert | 30 +++--------------- .../shaders/contraption_structure.vert | 31 ++++--------------- .../assets/create/flywheel/shaders/flap.vert | 9 +----- .../assets/create/flywheel/shaders/model.vert | 9 +----- .../create/flywheel/shaders/oriented.vert | 9 +----- .../create/flywheel/shaders/rotating.vert | 9 +----- .../create/flywheel/shaders/std/builtin.vert | 10 ++++-- 9 files changed, 32 insertions(+), 93 deletions(-) diff --git a/src/main/resources/assets/create/flywheel/shaders/belt.vert b/src/main/resources/assets/create/flywheel/shaders/belt.vert index 78937f401..052520d2d 100644 --- a/src/main/resources/assets/create/flywheel/shaders/belt.vert +++ b/src/main/resources/assets/create/flywheel/shaders/belt.vert @@ -25,12 +25,6 @@ varying vec4 Color; varying float Diffuse; varying vec2 Light; -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - void main() { vec3 rotated = rotateVertexByQuat(aPos - .5, aInstanceRot) + aInstancePos + .5; @@ -38,7 +32,7 @@ void main() { vec3 norm = rotateVertexByQuat(aNormal, aInstanceRot); - FLWFinalizeWorldPos(worldPos, uCameraPos); + FLWFinalizeWorldPos(worldPos); FLWFinalizeNormal(norm); float scrollSize = aScrollTexture.w - aScrollTexture.y; @@ -47,7 +41,6 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll); Light = aLight; - gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION if (uDebug == 2) { diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert index 63aafdbda..2b044c280 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert +++ b/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert @@ -8,7 +8,12 @@ uniform vec3 uLightBoxSize; uniform vec3 uLightBoxMin; uniform mat4 uModel; -void FLWFinalizeWorldPos(inout vec4 worldPos, vec3 cameraPos) { +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; +uniform vec3 uCameraPos; + +void FLWFinalizeWorldPos(inout vec4 worldPos) { worldPos = uModel * worldPos; BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; @@ -16,6 +21,8 @@ void FLWFinalizeWorldPos(inout vec4 worldPos, vec3 cameraPos) { #if defined(USE_FOG) FragDistance = length(worldPos.xyz); #endif + + gl_Position = uViewProjection * worldPos; } void FLWFinalizeNormal(inout vec3 normal) { diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert index 4de728759..96d516359 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert +++ b/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert @@ -1,6 +1,7 @@ #version 110 #define PI 3.1415926538 +#flwbuiltins #flwinclude <"create:core/matutils.glsl"> #flwinclude <"create:core/quaternion.glsl"> #flwinclude <"create:core/diffuse.glsl"> @@ -22,45 +23,24 @@ attribute float aSpeed; varying float Diffuse; varying vec2 TexCoords; varying vec4 Color; -varying vec3 BoxCoord; varying vec2 Light; -uniform vec3 uLightBoxSize; -uniform vec3 uLightBoxMin; -uniform mat4 uModel; - -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - -#if defined(USE_FOG) -varying float FragDistance; -#endif - void main() { float degrees = aOffset + uTime * aSpeed / 20.; //float angle = fract(degrees / 360.) * PI * 2.; vec4 kineticRot = quat(aAxis, degrees); vec3 rotated = rotateVertexByQuat(aPos - aRotationCenter, kineticRot) + aRotationCenter; - vec3 localPos = rotateVertexByQuat(rotated - .5, aInstanceRot) + aInstancePos + .5; - - vec4 worldPos = uModel * vec4(localPos, 1.); + vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, aInstanceRot) + aInstancePos + .5, 1.); vec3 norm = rotateVertexByQuat(rotateVertexByQuat(aNormal, kineticRot), aInstanceRot); - norm = modelToNormal(uModel) * norm; - BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + FLWFinalizeWorldPos(worldPos); + FLWFinalizeNormal(norm); + Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aModelLight; - gl_Position = uViewProjection * worldPos; - - #if defined(USE_FOG) - FragDistance = length(worldPos.xyz); - #endif if (uDebug == 2) { Color = vec4(norm, 1.); diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert index dbcf4a595..8cec957bc 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert +++ b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert @@ -1,6 +1,7 @@ #version 110 #define PI 3.1415926538 +#flwbuiltins #flwinclude <"create:core/matutils.glsl"> #flwinclude <"create:core/diffuse.glsl"> @@ -13,41 +14,21 @@ attribute vec2 aModelLight; varying float Diffuse; varying vec2 TexCoords; varying vec4 Color; -varying vec3 BoxCoord; varying vec2 Light; -uniform vec3 uLightBoxSize; -uniform vec3 uLightBoxMin; -uniform mat4 uModel; - -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - -#if defined(USE_FOG) -varying float FragDistance; -#endif - void main() { - vec4 viewPos = uModel * vec4(aPos, 1.); + vec4 worldPos = vec4(aPos, 1.); + vec3 norm = aNormal; - vec3 norm = (uModel * vec4(aNormal, 0.)).xyz; + FLWFinalizeWorldPos(worldPos); + FLWFinalizeNormal(norm); - BoxCoord = (viewPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); - Color = aColor / diffuse(aNormal); + Color = aColor / diffuse(norm); TexCoords = aTexCoords; Light = aModelLight; - gl_Position = uViewProjection * viewPos; - #if defined(USE_FOG) - FragDistance = length(viewPos.xyz); - #endif if (uDebug == 2) { Color = vec4(norm, 1.); - } else { - Color = aColor / diffuse(aNormal); } } diff --git a/src/main/resources/assets/create/flywheel/shaders/flap.vert b/src/main/resources/assets/create/flywheel/shaders/flap.vert index 8b79964c1..cb4eba652 100644 --- a/src/main/resources/assets/create/flywheel/shaders/flap.vert +++ b/src/main/resources/assets/create/flywheel/shaders/flap.vert @@ -27,12 +27,6 @@ varying vec4 Color; varying float Diffuse; varying vec2 Light; -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - float toRad(float degrees) { return fract(degrees / 360.) * PI * 2.; } @@ -62,13 +56,12 @@ void main() { vec4 worldPos = vec4(rotated, 1.); vec3 norm = rotateVertexByQuat(rotateVertexByQuat(aNormal, flapRotation), orientation); - FLWFinalizeWorldPos(worldPos, uCameraPos); + FLWFinalizeWorldPos(worldPos); FLWFinalizeNormal(norm); Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aLight; - gl_Position = uViewProjection * worldPos; Color = vec4(1.); } diff --git a/src/main/resources/assets/create/flywheel/shaders/model.vert b/src/main/resources/assets/create/flywheel/shaders/model.vert index a6c5e3ec1..7336bd064 100644 --- a/src/main/resources/assets/create/flywheel/shaders/model.vert +++ b/src/main/resources/assets/create/flywheel/shaders/model.vert @@ -18,18 +18,12 @@ varying vec4 Color; varying float Diffuse; varying vec2 Light; -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - void main() { vec4 worldPos = aTransform * vec4(aPos, 1.); vec3 norm = aNormalMat * aNormal; - FLWFinalizeWorldPos(worldPos, uCameraPos); + FLWFinalizeWorldPos(worldPos); FLWFinalizeNormal(norm); norm = normalize(norm); @@ -37,7 +31,6 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aLight; - gl_Position = uViewProjection * worldPos; Color = aColor; } diff --git a/src/main/resources/assets/create/flywheel/shaders/oriented.vert b/src/main/resources/assets/create/flywheel/shaders/oriented.vert index 8c94ecd04..d9f6f5cc5 100644 --- a/src/main/resources/assets/create/flywheel/shaders/oriented.vert +++ b/src/main/resources/assets/create/flywheel/shaders/oriented.vert @@ -20,24 +20,17 @@ varying vec4 Color; varying float Diffuse; varying vec2 Light; -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - void main() { vec4 worldPos = vec4(rotateVertexByQuat(aPos - aPivot, aRotation) + aPivot + aInstancePos, 1.); vec3 norm = rotateVertexByQuat(aNormal, aRotation); - FLWFinalizeWorldPos(worldPos, uCameraPos); + FLWFinalizeWorldPos(worldPos); FLWFinalizeNormal(norm); Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aLight; - gl_Position = uViewProjection * worldPos; Color = aColor; } diff --git a/src/main/resources/assets/create/flywheel/shaders/rotating.vert b/src/main/resources/assets/create/flywheel/shaders/rotating.vert index 770ef4ccc..9d20b6480 100644 --- a/src/main/resources/assets/create/flywheel/shaders/rotating.vert +++ b/src/main/resources/assets/create/flywheel/shaders/rotating.vert @@ -22,12 +22,6 @@ varying vec4 Color; varying float Diffuse; varying vec2 Light; -uniform float uTime; -uniform mat4 uViewProjection; -uniform int uDebug; - -uniform vec3 uCameraPos; - mat4 kineticRotation() { float degrees = aOffset + uTime * aSpeed * 3./10.; float angle = fract(degrees / 360.) * PI * 2.; @@ -41,13 +35,12 @@ void main() { vec3 norm = modelToNormal(kineticRotation) * aNormal; - FLWFinalizeWorldPos(worldPos, uCameraPos); + FLWFinalizeWorldPos(worldPos); FLWFinalizeNormal(norm); Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aLight; - gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION if (uDebug == 2) { diff --git a/src/main/resources/assets/create/flywheel/shaders/std/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/std/builtin.vert index c5279bf75..bcf38154a 100644 --- a/src/main/resources/assets/create/flywheel/shaders/std/builtin.vert +++ b/src/main/resources/assets/create/flywheel/shaders/std/builtin.vert @@ -1,12 +1,18 @@ +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; +uniform vec3 uCameraPos; #if defined(USE_FOG) varying float FragDistance; #endif -void FLWFinalizeWorldPos(inout vec4 worldPos, vec3 cameraPos) { +void FLWFinalizeWorldPos(inout vec4 worldPos) { #if defined(USE_FOG) - FragDistance = length(worldPos.xyz - cameraPos); + FragDistance = length(worldPos.xyz - uCameraPos); #endif + + gl_Position = uViewProjection * worldPos; } void FLWFinalizeNormal(inout vec3 normal) {