-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gles2: Split shaders into separate files
- Loading branch information
Showing
6 changed files
with
99 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
/* | ||
* OpenGL Shaders | ||
*/ | ||
|
||
// define constants | ||
pub const XBGR: &str = "XBGR"; | ||
pub const EXTERNAL: &str = "EXTERNAL"; | ||
pub const DEBUG_FLAGS: &str = "DEBUG_FLAGS"; | ||
|
||
pub const VERTEX_SHADER: &str = include_str!("./texture.vert"); | ||
pub const FRAGMENT_SHADER: &str = include_str!("./texture.frag"); | ||
|
||
pub const VERTEX_SHADER_SOLID: &str = include_str!("./solid.vert"); | ||
pub const FRAGMENT_SHADER_SOLID: &str = include_str!("./solid.frag"); |
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,8 @@ | ||
#version 100 | ||
|
||
precision mediump float; | ||
uniform vec4 color; | ||
|
||
void main() { | ||
gl_FragColor = color; | ||
} |
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,19 @@ | ||
#version 100 | ||
|
||
uniform mat3 matrix; | ||
attribute vec2 vert; | ||
attribute vec4 position; | ||
|
||
mat2 scale(vec2 scale_vec){ | ||
return mat2( | ||
scale_vec.x, 0.0, | ||
0.0, scale_vec.y | ||
); | ||
} | ||
|
||
void main() { | ||
vec2 transform_translation = position.xy; | ||
vec2 transform_scale = position.zw; | ||
vec3 position = vec3(vert * scale(transform_scale) + transform_translation, 1.0); | ||
gl_Position = vec4(matrix * position, 1.0); | ||
} |
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,35 @@ | ||
#version 100 | ||
#if defined(EXTERNAL) | ||
#extension GL_OES_EGL_image_external : require | ||
#endif | ||
|
||
precision mediump float; | ||
#if defined(EXTERNAL) | ||
uniform samplerExternalOES tex; | ||
#else | ||
uniform sampler2D tex; | ||
#endif | ||
|
||
uniform float alpha; | ||
varying vec2 v_coords; | ||
|
||
#if defined(DEBUG_FLAGS) | ||
uniform float tint; | ||
#endif | ||
|
||
void main() { | ||
vec4 color; | ||
|
||
#if defined(XBGR) | ||
color = vec4(texture2D(tex, v_coords).rgb, 1.0) * alpha; | ||
#else | ||
color = texture2D(tex, v_coords) * alpha; | ||
#endif | ||
|
||
#if defined(DEBUG_FLAGS) | ||
if (tint == 1.0) | ||
color = vec4(0.0, 0.3, 0.0, 0.2) + color * 0.8; | ||
#endif | ||
|
||
gl_FragColor = color; | ||
} |
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,23 @@ | ||
#version 100 | ||
uniform mat3 matrix; | ||
uniform mat3 tex_matrix; | ||
|
||
attribute vec2 vert; | ||
attribute vec4 vert_position; | ||
|
||
varying vec2 v_coords; | ||
|
||
mat2 scale(vec2 scale_vec){ | ||
return mat2( | ||
scale_vec.x, 0.0, | ||
0.0, scale_vec.y | ||
); | ||
} | ||
|
||
void main() { | ||
vec2 vert_transform_translation = vert_position.xy; | ||
vec2 vert_transform_scale = vert_position.zw; | ||
vec3 position = vec3(vert * scale(vert_transform_scale) + vert_transform_translation, 1.0); | ||
v_tex_coords = (tex_matrix * position).xy; | ||
gl_Position = vec4(matrix * position, 1.0); | ||
} |