-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gl2shim: make shaders code more portable
- Loading branch information
Showing
2 changed files
with
118 additions
and
125 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 |
---|---|---|
@@ -1,69 +1,65 @@ | ||
R"( | ||
#if VER <= 300 | ||
#define layout(x) | ||
#endif | ||
#if VER < 300 | ||
#define out attribute | ||
#define in varying | ||
#define texture texture2D | ||
#endif | ||
#if VER >= 130 | ||
precision mediump float; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
uniform sampler2D uTex0; | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
uniform sampler2D uTex1; | ||
#endif | ||
#if FEAT_ALPHA_TEST | ||
uniform float uAlphaTest; | ||
#endif | ||
#if FEAT_FOG | ||
uniform vec4 uFog; | ||
#endif | ||
uniform vec4 uColor; | ||
#if ATTR_COLOR | ||
in vec4 vColor; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
in vec2 vTexCoord0; | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
in vec2 vTexCoord1; | ||
#endif | ||
#if ATTR_NORMAL | ||
in vec2 vNormal; | ||
#endif | ||
#if VER >= 300 | ||
out vec4 oFragColor; | ||
#else | ||
#define oFragColor gl_FragColor | ||
#endif | ||
void main() | ||
{ | ||
#if ATTR_COLOR | ||
vec4 c = vColor; | ||
#else | ||
vec4 c = uColor; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
c = c * texture(uTex0, vTexCoord0); | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
c = c * texture(uTex1, vTexCoord1); | ||
#endif | ||
#if FEAT_ALPHA_TEST | ||
if(c.a <= uAlphaTest) | ||
discard; | ||
#endif | ||
#if FEAT_FOG | ||
float fogDist = gl_FragCoord.z / gl_FragCoord.w; | ||
float fogRate = clamp(exp(-uFog.w * fogDist), 0.f, 1.f); | ||
c.rgb = mix(uFog.rgb, c.rgb, fogRate); | ||
#endif | ||
oFragColor = c; | ||
} | ||
)" | ||
"#if VER <= 300\n" | ||
"#define layout(x)\n" | ||
"#endif\n" | ||
"#if VER < 300\n" | ||
"#define out attribute\n" | ||
"#define in varying\n" | ||
"#define texture texture2D\n" | ||
"#endif\n" | ||
"#if VER >= 130\n" | ||
"precision mediump float;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"uniform sampler2D uTex0;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"uniform sampler2D uTex1;\n" | ||
"#endif\n" | ||
"#if FEAT_ALPHA_TEST\n" | ||
"uniform float uAlphaTest;\n" | ||
"#endif\n" | ||
"#if FEAT_FOG\n" | ||
"uniform vec4 uFog;\n" | ||
"#endif\n" | ||
"uniform vec4 uColor;\n" | ||
"#if ATTR_COLOR\n" | ||
"in vec4 vColor;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"in vec2 vTexCoord0;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"in vec2 vTexCoord1;\n" | ||
"#endif\n" | ||
"#if ATTR_NORMAL\n" | ||
"in vec2 vNormal;\n" | ||
"#endif\n" | ||
"#if VER >= 300\n" | ||
"out vec4 oFragColor;\n" | ||
"#else\n" | ||
"#define oFragColor gl_FragColor\n" | ||
"#endif\n" | ||
"void main()\n" | ||
"{\n" | ||
"#if ATTR_COLOR\n" | ||
"vec4 c = vColor;\n" | ||
"#else\n" | ||
"vec4 c = uColor;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"c = c * texture(uTex0, vTexCoord0);\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"c = c * texture(uTex1, vTexCoord1);\n" | ||
"#endif\n" | ||
"#if FEAT_ALPHA_TEST\n" | ||
"if(c.a <= uAlphaTest)\n" | ||
"discard;\n" | ||
"#endif\n" | ||
"#if FEAT_FOG\n" | ||
"float fogDist = gl_FragCoord.z / gl_FragCoord.w;\n" | ||
"float fogRate = clamp(exp(-uFog.w * fogDist), 0.f, 1.f);\n" | ||
"c.rgb = mix(uFog.rgb, c.rgb, fogRate);\n" | ||
"#endif\n" | ||
"oFragColor = c;\n" | ||
"}\n" |
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 |
---|---|---|
@@ -1,56 +1,53 @@ | ||
R"( | ||
#if VER <= 300 | ||
#define layout(x) | ||
#endif | ||
#if VER < 300 | ||
#define in attribute | ||
#define out varying | ||
#endif | ||
layout(location = LOC_ATTR_POSITION) in vec3 inPosition; | ||
#if ATTR_COLOR | ||
layout(location = LOC_ATTR_COLOR) in vec4 inColor; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
layout(location = LOC_ATTR_TEXCOORD0) in vec2 inTexCoord0; | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
layout(location = LOC_ATTR_TEXCOORD1) in vec2 inTexCoord1; | ||
#endif | ||
#if ATTR_NORMAL | ||
in vec3 inNormal; | ||
#endif | ||
#if ATTR_COLOR | ||
out vec4 vColor; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
out vec2 vTexCoord0; | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
out vec2 vTexCoord1; | ||
#endif | ||
#if ATTR_NORMAL | ||
out vec3 vNormal; | ||
#endif | ||
uniform mat4 uMVP; | ||
void main() | ||
{ | ||
gl_Position = uMVP * vec4(inPosition,1.0f); | ||
#if ATTR_COLOR | ||
vColor = inColor; | ||
#endif | ||
#if ATTR_NORMAL | ||
vNormal = inNormal; | ||
#endif | ||
#if ATTR_TEXCOORD0 | ||
vTexCoord0 = inTexCoord0; | ||
#endif | ||
#if ATTR_TEXCOORD1 | ||
vTexCoord1 = inTexCoord1; | ||
#endif | ||
} | ||
)" | ||
"#if VER <= 300\n" | ||
"#define layout(x)\n" | ||
"#endif\n" | ||
"#if VER < 300\n" | ||
"#define in attribute\n" | ||
"#define out varying\n" | ||
"#endif\n" | ||
"\n" | ||
"layout(location = LOC_ATTR_POSITION) in vec3 inPosition;\n" | ||
"#if ATTR_COLOR\n" | ||
"layout(location = LOC_ATTR_COLOR) in vec4 inColor;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"layout(location = LOC_ATTR_TEXCOORD0) in vec2 inTexCoord0;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"layout(location = LOC_ATTR_TEXCOORD1) in vec2 inTexCoord1;\n" | ||
"#endif\n" | ||
"\n" | ||
"#if ATTR_NORMAL\n" | ||
"in vec3 inNormal;\n" | ||
"#endif\n" | ||
"#if ATTR_COLOR\n" | ||
"out vec4 vColor;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"out vec2 vTexCoord0;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"out vec2 vTexCoord1;\n" | ||
"#endif\n" | ||
"#if ATTR_NORMAL\n" | ||
"out vec3 vNormal;\n" | ||
"#endif\n" | ||
"\n" | ||
"uniform mat4 uMVP;\n" | ||
"\n" | ||
"void main()\n" | ||
"{\n" | ||
"gl_Position = uMVP * vec4(inPosition,1.0f);\n" | ||
"#if ATTR_COLOR\n" | ||
"vColor = inColor;\n" | ||
"#endif\n" | ||
"#if ATTR_NORMAL\n" | ||
"vNormal = inNormal;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD0\n" | ||
"vTexCoord0 = inTexCoord0;\n" | ||
"#endif\n" | ||
"#if ATTR_TEXCOORD1\n" | ||
"vTexCoord1 = inTexCoord1;\n" | ||
"#endif\n" | ||
"}\n" |