started moving shareable code to modules

This commit is contained in:
Valerie Wolfe 2024-04-11 14:59:46 -04:00
parent 1b5a2f5fa7
commit 7413fbdc5c
8 changed files with 53 additions and 26 deletions

View file

@ -1,8 +1,4 @@
#version 120 #version 120
varying vec2 texcoord; #include "/module/empty.vert"
void main() {
gl_Position = ftransform();
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
}

View file

@ -1,15 +1,4 @@
#version 120 #version 120
varying vec2 texcoord; #include "/module/empty.frag"
varying vec4 color;
varying vec2 lmcoord;
uniform sampler2D texture;
uniform sampler2D lightmap;
void main() {
vec4 final = texture2D(texture, texcoord) * color;
final *= texture2D(lightmap, lmcoord);
gl_FragData[0] = final;
}

View file

@ -1,8 +1,6 @@
#version 120 #version 120
#define pixelSize 2 // [1 2 4 8 16] #define pixelSize 2 // [1 2 4 8 16]
#define vWarp 0 // psx vertex warp [0 1 2 4 8 16 32]
//#define tWarp // psx texture warp
varying vec2 texcoord; varying vec2 texcoord;
varying vec4 color; varying vec4 color;
@ -11,24 +9,22 @@ varying vec2 lmcoord;
uniform mat4 gbufferModelView, gbufferModelViewInverse; uniform mat4 gbufferModelView, gbufferModelViewInverse;
uniform float viewWidth, viewHeight; uniform float viewWidth, viewHeight;
#include "/module/vertex_warp.vert"
#include "/module/texture_warp.vert"
void main() { void main() {
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy; texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy; lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
color = gl_Color; color = gl_Color;
#if vWarp > 0 #if vWarp > 0
float mod = pixelSize * vWarp; vertex_warp();
vec2 screen = vec2(viewWidth / mod, viewHeight / mod);
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
vec2 nearest = round(position.xy / position.w * screen) / screen;
position.xy = nearest;
gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
#else #else
gl_Position = ftransform(); gl_Position = ftransform();
#endif #endif
#ifdef tWarp #ifdef tWarp
gl_Position /= abs(gl_Position.w); texture_warp();
#endif #endif
} }

View file

@ -0,0 +1,3 @@
#define pixelSize 2 // [1 2 4 8 16]

15
shaders/module/empty.frag Normal file
View file

@ -0,0 +1,15 @@
// "empty" fragment shader
varying vec2 texcoord;
varying vec4 color;
varying vec2 lmcoord;
uniform sampler2D texture;
uniform sampler2D lightmap;
void main() {
vec4 final = texture2D(texture, texcoord) * color;
final *= texture2D(lightmap, lmcoord);
gl_FragData[0] = final;
}

View file

@ -0,0 +1,9 @@
// "empty" vertex shader
varying vec2 texcoord;
void main() {
gl_Position = ftransform();
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
}

View file

@ -0,0 +1,7 @@
//#define tWarp // psx texture warp
void texture_warp() {
gl_Position /= abs(gl_Position.w);
}

View file

@ -0,0 +1,12 @@
#define vWarp 0 // psx vertex warp [0 1 2 4 8 16 32]
vec4 vertex_warp() {
float mod = pixelSize * vWarp;
vec2 screen = vec2(viewWidth / mod, viewHeight / mod);
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
vec2 nearest = round(position.xy, position.w * screen) / screen);
position.xy = nearest;
return (gl_ProjectionMatrix * gbufferModelView * position);
}