Refactored ShapeRenderProgram into SRP and WorldRenderProgram

- ShapeRP now handles positions, textures and color multipliers only,
normals, view transforms and light calculations are now in WorldRP
- Renamed WorldRenderer to ShapeRenderHelper
- Moved normal computation to WorldRP code from Face
- No default ShapeRP exists, methods in Faces and Shapes now explicitly
require a program
- Removed unnecessary glBind from texture loader
- Refactored and renamed GLSL code
- Added a view bobbing test, enable with I_WANT_TO_THROW_UP in
LayerWorld
This commit is contained in:
2020-08-01 00:24:38 +03:00
parent 16205909ed
commit 8aa0bb8aa0
25 changed files with 503 additions and 204 deletions

View File

@@ -2,7 +2,6 @@
varying vec3 varyingColorMultiplier;
varying vec2 varyingTextureCoords;
varying vec3 varyingNormals;
uniform sampler2D textureSlot;
uniform vec2 textureStart;
@@ -36,16 +35,6 @@ void applyColorMultiplier() {
linearMultiply(gl_FragColor, vec4(varyingColorMultiplier, 1.0));
}
void applyShading() {
vec3 light = normalize(vec3(0.5, 1.0, 0.2));
vec3 normal = varyingNormals;
float angleCos = dot(normal, light);
float lightness = (angleCos + 1.5) / 2;
linearMultiply(gl_FragColor, vec4(lightness, lightness, lightness, 1.0));
}
void applyAlpha() {
if (gl_FragColor.w < 0.01) {
discard;

View File

@@ -8,20 +8,13 @@ varying vec3 varyingColorMultiplier;
attribute vec2 inputTextureCoords;
varying vec2 varyingTextureCoords;
attribute vec3 inputNormals;
varying vec3 varyingNormals;
uniform mat4 worldTransform;
uniform mat4 finalTransform;
vec4 applyFinalTransform(vec4 vector) {
return finalTransform * vector;
}
void transferToFragment() {
void shapeTransferToFragment() {
varyingColorMultiplier = inputColorMultiplier;
varyingTextureCoords = inputTextureCoords;
mat3 worldRotation = mat3(worldTransform);
varyingNormals = normalize(worldRotation * inputNormals);
}

View File

@@ -0,0 +1,13 @@
#version 120
varying vec3 varyingNormals;
void applyShading() {
vec3 light = normalize(vec3(0.5, 1.0, 0.2));
vec3 normal = varyingNormals;
float angleCos = dot(normal, light);
float lightness = (angleCos + 1.5) / 2;
linearMultiply(gl_FragColor, vec4(lightness, lightness, lightness, 1.0));
}

View File

@@ -0,0 +1,13 @@
#version 120
attribute vec3 inputNormals;
varying vec3 varyingNormals;
uniform mat4 worldTransform;
void worldTransferToFragment() {
shapeTransferToFragment();
mat3 worldRotation = mat3(worldTransform);
varyingNormals = normalize(worldRotation * inputNormals);
}

View File

@@ -2,5 +2,5 @@
void main(void) {
gl_Position = applyFinalTransform(vec4(inputPositions, 1.0));
transferToFragment();
worldTransferToFragment();
}