-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tr2: use hybrid OpenGL/DirectX rendering
- Loading branch information
Showing
93 changed files
with
9,312 additions
and
12,473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
#ifdef OGL33C | ||
out vec2 vertTexCoords; | ||
out vec2 vertCoords; | ||
#else | ||
varying vec2 vertTexCoords; | ||
varying vec2 vertCoords; | ||
#endif | ||
|
||
layout(location = 0) in vec2 inPosition; | ||
layout(location = 1) in vec2 inTexCoords; | ||
|
||
void main(void) { | ||
gl_Position = vec4(inPosition * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0); | ||
vertCoords = inPosition; | ||
vertTexCoords = inTexCoords; | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
#define EFFECT_NONE 0 | ||
#define EFFECT_VIGNETTE 1 | ||
|
||
uniform sampler2D texMain; | ||
uniform sampler1D texPalette; | ||
uniform sampler2D texAlpha; | ||
uniform bool paletteEnabled; | ||
uniform bool alphaEnabled; | ||
uniform int effect; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURE2D texture | ||
#define TEXTURE1D texture | ||
|
||
in vec2 vertTexCoords; | ||
in vec2 vertCoords; | ||
out vec4 outColor; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURE2D texture2D | ||
#define TEXTURE1D texture1D | ||
|
||
varying vec2 vertTexCoords; | ||
varying vec2 vertCoords; | ||
#endif | ||
|
||
void main(void) { | ||
vec2 uv = vertTexCoords; | ||
|
||
if (alphaEnabled) { | ||
float alpha = TEXTURE2D(texAlpha, uv).r; | ||
if (alpha < 0.5) { | ||
discard; | ||
} | ||
} | ||
|
||
if (paletteEnabled) { | ||
float paletteIndex = TEXTURE2D(texMain, uv).r; | ||
OUTCOLOR = TEXTURE1D(texPalette, paletteIndex); | ||
} else { | ||
OUTCOLOR = TEXTURE2D(texMain, uv); | ||
} | ||
|
||
if (effect == EFFECT_VIGNETTE) { | ||
float x_dist = vertCoords.x - 0.5; | ||
float y_dist = vertCoords.y - 0.5; | ||
float light = 256 - sqrt(x_dist * x_dist + y_dist * y_dist ) * 300.0; | ||
light = clamp(light, 0, 255) / 255; | ||
OUTCOLOR *= vec4(light, light, light, 1); | ||
} | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
layout(location = 0) in vec3 inPosition; | ||
layout(location = 1) in vec3 inTexCoords; | ||
layout(location = 2) in vec4 inColor; | ||
|
||
uniform mat4 matProjection; | ||
uniform mat4 matModelView; | ||
|
||
#ifdef OGL33C | ||
out vec4 vertColor; | ||
out vec3 vertTexCoords; | ||
#else | ||
varying vec4 vertColor; | ||
varying vec3 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
gl_Position = matProjection * matModelView * vec4(inPosition, 1); | ||
vertColor = inColor / 255.0; | ||
vertTexCoords = inTexCoords; | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform sampler2D tex0; | ||
uniform bool texturingEnabled; | ||
uniform bool smoothingEnabled; | ||
uniform bool colorKeyEnabled; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURESIZE textureSize | ||
#define TEXTURE texture | ||
#define TEXELFETCH texelFetch | ||
|
||
in vec4 vertColor; | ||
in vec3 vertTexCoords; | ||
out vec4 OUTCOLOR; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURESIZE textureSize2D | ||
#define TEXELFETCH texelFetch2D | ||
#define TEXTURE texture2D | ||
|
||
varying vec4 vertColor; | ||
varying vec3 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
OUTCOLOR = vertColor; | ||
|
||
if (texturingEnabled) { | ||
#if defined(GL_EXT_gpu_shader4) || defined(OGL33C) | ||
if (colorKeyEnabled && smoothingEnabled) { | ||
// do not use smoothing for chroma key | ||
ivec2 size = TEXTURESIZE(tex0, 0); | ||
int tx = int((vertTexCoords.x / vertTexCoords.z) * size.x) % size.x; | ||
int ty = int((vertTexCoords.y / vertTexCoords.z) * size.y) % size.y; | ||
vec4 texel = TEXELFETCH(tex0, ivec2(tx, ty), 0); | ||
if (texel.a == 0.0) { | ||
discard; | ||
} | ||
} | ||
#endif | ||
|
||
vec4 texColor = TEXTURE(tex0, vertTexCoords.xy / vertTexCoords.z); | ||
if (colorKeyEnabled && texColor.a == 0.0) { | ||
discard; | ||
} | ||
|
||
OUTCOLOR = vec4(OUTCOLOR.rgb * texColor.rgb, texColor.a); | ||
} | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
layout(location = 0) in vec2 inPosition; | ||
|
||
void main(void) { | ||
gl_Position = vec4(inPosition * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0); | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform float opacity; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
out vec4 outColor; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#endif | ||
|
||
void main(void) { | ||
OUTCOLOR = vec4(0, 0, 0, opacity); | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
layout(location = 0) in vec2 inPosition; | ||
|
||
#ifdef OGL33C | ||
out vec2 vertTexCoords; | ||
#else | ||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
vertTexCoords = inPosition; | ||
gl_Position = vec4(vertTexCoords * vec2(2.0, 2.0) + vec2(-1.0, -1.0), 0.0, 1.0); | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform sampler2D tex0; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURE texture | ||
|
||
in vec2 vertTexCoords; | ||
out vec4 OUTCOLOR; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURE texture2D | ||
|
||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
OUTCOLOR = TEXTURE(tex0, vertTexCoords); | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.