FLWFinalizeWorld takes care of assigning gl_Position

This commit is contained in:
JozsefA 2021-05-07 23:22:40 -07:00
parent 05b56b9b5e
commit 4111680755
9 changed files with 32 additions and 93 deletions

View file

@ -25,12 +25,6 @@ varying vec4 Color;
varying float Diffuse; varying float Diffuse;
varying vec2 Light; varying vec2 Light;
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
void main() { void main() {
vec3 rotated = rotateVertexByQuat(aPos - .5, aInstanceRot) + aInstancePos + .5; vec3 rotated = rotateVertexByQuat(aPos - .5, aInstanceRot) + aInstancePos + .5;
@ -38,7 +32,7 @@ void main() {
vec3 norm = rotateVertexByQuat(aNormal, aInstanceRot); vec3 norm = rotateVertexByQuat(aNormal, aInstanceRot);
FLWFinalizeWorldPos(worldPos, uCameraPos); FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm); FLWFinalizeNormal(norm);
float scrollSize = aScrollTexture.w - aScrollTexture.y; float scrollSize = aScrollTexture.w - aScrollTexture.y;
@ -47,7 +41,6 @@ void main() {
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll); TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll);
Light = aLight; Light = aLight;
gl_Position = uViewProjection * worldPos;
#ifdef CONTRAPTION #ifdef CONTRAPTION
if (uDebug == 2) { if (uDebug == 2) {

View file

@ -8,7 +8,12 @@ uniform vec3 uLightBoxSize;
uniform vec3 uLightBoxMin; uniform vec3 uLightBoxMin;
uniform mat4 uModel; 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; worldPos = uModel * worldPos;
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
@ -16,6 +21,8 @@ void FLWFinalizeWorldPos(inout vec4 worldPos, vec3 cameraPos) {
#if defined(USE_FOG) #if defined(USE_FOG)
FragDistance = length(worldPos.xyz); FragDistance = length(worldPos.xyz);
#endif #endif
gl_Position = uViewProjection * worldPos;
} }
void FLWFinalizeNormal(inout vec3 normal) { void FLWFinalizeNormal(inout vec3 normal) {

View file

@ -1,6 +1,7 @@
#version 110 #version 110
#define PI 3.1415926538 #define PI 3.1415926538
#flwbuiltins
#flwinclude <"create:core/matutils.glsl"> #flwinclude <"create:core/matutils.glsl">
#flwinclude <"create:core/quaternion.glsl"> #flwinclude <"create:core/quaternion.glsl">
#flwinclude <"create:core/diffuse.glsl"> #flwinclude <"create:core/diffuse.glsl">
@ -22,45 +23,24 @@ attribute float aSpeed;
varying float Diffuse; varying float Diffuse;
varying vec2 TexCoords; varying vec2 TexCoords;
varying vec4 Color; varying vec4 Color;
varying vec3 BoxCoord;
varying vec2 Light; 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() { void main() {
float degrees = aOffset + uTime * aSpeed / 20.; float degrees = aOffset + uTime * aSpeed / 20.;
//float angle = fract(degrees / 360.) * PI * 2.; //float angle = fract(degrees / 360.) * PI * 2.;
vec4 kineticRot = quat(aAxis, degrees); vec4 kineticRot = quat(aAxis, degrees);
vec3 rotated = rotateVertexByQuat(aPos - aRotationCenter, kineticRot) + aRotationCenter; 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); vec3 norm = rotateVertexByQuat(rotateVertexByQuat(aNormal, kineticRot), aInstanceRot);
norm = modelToNormal(uModel) * norm;
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm);
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aModelLight; Light = aModelLight;
gl_Position = uViewProjection * worldPos;
#if defined(USE_FOG)
FragDistance = length(worldPos.xyz);
#endif
if (uDebug == 2) { if (uDebug == 2) {
Color = vec4(norm, 1.); Color = vec4(norm, 1.);

View file

@ -1,6 +1,7 @@
#version 110 #version 110
#define PI 3.1415926538 #define PI 3.1415926538
#flwbuiltins
#flwinclude <"create:core/matutils.glsl"> #flwinclude <"create:core/matutils.glsl">
#flwinclude <"create:core/diffuse.glsl"> #flwinclude <"create:core/diffuse.glsl">
@ -13,41 +14,21 @@ attribute vec2 aModelLight;
varying float Diffuse; varying float Diffuse;
varying vec2 TexCoords; varying vec2 TexCoords;
varying vec4 Color; varying vec4 Color;
varying vec3 BoxCoord;
varying vec2 Light; 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() { 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); Diffuse = diffuse(norm);
Color = aColor / diffuse(aNormal); Color = aColor / diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aModelLight; Light = aModelLight;
gl_Position = uViewProjection * viewPos;
#if defined(USE_FOG)
FragDistance = length(viewPos.xyz);
#endif
if (uDebug == 2) { if (uDebug == 2) {
Color = vec4(norm, 1.); Color = vec4(norm, 1.);
} else {
Color = aColor / diffuse(aNormal);
} }
} }

View file

@ -27,12 +27,6 @@ varying vec4 Color;
varying float Diffuse; varying float Diffuse;
varying vec2 Light; varying vec2 Light;
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
float toRad(float degrees) { float toRad(float degrees) {
return fract(degrees / 360.) * PI * 2.; return fract(degrees / 360.) * PI * 2.;
} }
@ -62,13 +56,12 @@ void main() {
vec4 worldPos = vec4(rotated, 1.); vec4 worldPos = vec4(rotated, 1.);
vec3 norm = rotateVertexByQuat(rotateVertexByQuat(aNormal, flapRotation), orientation); vec3 norm = rotateVertexByQuat(rotateVertexByQuat(aNormal, flapRotation), orientation);
FLWFinalizeWorldPos(worldPos, uCameraPos); FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm); FLWFinalizeNormal(norm);
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aLight; Light = aLight;
gl_Position = uViewProjection * worldPos;
Color = vec4(1.); Color = vec4(1.);
} }

View file

@ -18,18 +18,12 @@ varying vec4 Color;
varying float Diffuse; varying float Diffuse;
varying vec2 Light; varying vec2 Light;
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
void main() { void main() {
vec4 worldPos = aTransform * vec4(aPos, 1.); vec4 worldPos = aTransform * vec4(aPos, 1.);
vec3 norm = aNormalMat * aNormal; vec3 norm = aNormalMat * aNormal;
FLWFinalizeWorldPos(worldPos, uCameraPos); FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm); FLWFinalizeNormal(norm);
norm = normalize(norm); norm = normalize(norm);
@ -37,7 +31,6 @@ void main() {
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aLight; Light = aLight;
gl_Position = uViewProjection * worldPos;
Color = aColor; Color = aColor;
} }

View file

@ -20,24 +20,17 @@ varying vec4 Color;
varying float Diffuse; varying float Diffuse;
varying vec2 Light; varying vec2 Light;
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
void main() { void main() {
vec4 worldPos = vec4(rotateVertexByQuat(aPos - aPivot, aRotation) + aPivot + aInstancePos, 1.); vec4 worldPos = vec4(rotateVertexByQuat(aPos - aPivot, aRotation) + aPivot + aInstancePos, 1.);
vec3 norm = rotateVertexByQuat(aNormal, aRotation); vec3 norm = rotateVertexByQuat(aNormal, aRotation);
FLWFinalizeWorldPos(worldPos, uCameraPos); FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm); FLWFinalizeNormal(norm);
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aLight; Light = aLight;
gl_Position = uViewProjection * worldPos;
Color = aColor; Color = aColor;
} }

View file

@ -22,12 +22,6 @@ varying vec4 Color;
varying float Diffuse; varying float Diffuse;
varying vec2 Light; varying vec2 Light;
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
mat4 kineticRotation() { mat4 kineticRotation() {
float degrees = aOffset + uTime * aSpeed * 3./10.; float degrees = aOffset + uTime * aSpeed * 3./10.;
float angle = fract(degrees / 360.) * PI * 2.; float angle = fract(degrees / 360.) * PI * 2.;
@ -41,13 +35,12 @@ void main() {
vec3 norm = modelToNormal(kineticRotation) * aNormal; vec3 norm = modelToNormal(kineticRotation) * aNormal;
FLWFinalizeWorldPos(worldPos, uCameraPos); FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm); FLWFinalizeNormal(norm);
Diffuse = diffuse(norm); Diffuse = diffuse(norm);
TexCoords = aTexCoords; TexCoords = aTexCoords;
Light = aLight; Light = aLight;
gl_Position = uViewProjection * worldPos;
#ifdef CONTRAPTION #ifdef CONTRAPTION
if (uDebug == 2) { if (uDebug == 2) {

View file

@ -1,12 +1,18 @@
uniform float uTime;
uniform mat4 uViewProjection;
uniform int uDebug;
uniform vec3 uCameraPos;
#if defined(USE_FOG) #if defined(USE_FOG)
varying float FragDistance; varying float FragDistance;
#endif #endif
void FLWFinalizeWorldPos(inout vec4 worldPos, vec3 cameraPos) { void FLWFinalizeWorldPos(inout vec4 worldPos) {
#if defined(USE_FOG) #if defined(USE_FOG)
FragDistance = length(worldPos.xyz - cameraPos); FragDistance = length(worldPos.xyz - uCameraPos);
#endif #endif
gl_Position = uViewProjection * worldPos;
} }
void FLWFinalizeNormal(inout vec3 normal) { void FLWFinalizeNormal(inout vec3 normal) {