Skip to content

Commit

Permalink
Use GLSL 300 es for shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Apr 2, 2024
1 parent 1e29e1e commit cbd8708
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 6 additions & 2 deletions example/shader_fragment_2d.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#version 300 es
// fragment shaders don't have a default precision so we need
// to pick one. mediump is a good default
precision mediump float;

// color varying received from vertex shader
varying vec4 v_color;
in vec4 v_color;

// equvalent of gl_FragColor in GLSL 100
out vec4 out_color;

void main() {
gl_FragColor = v_color;
out_color = v_color;
}
8 changes: 6 additions & 2 deletions example/shader_fragment_3d.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#version 300 es

precision mediump float;

varying vec4 v_color;
in vec4 v_color;

out vec4 out_color;

void main() {
gl_FragColor = v_color;
out_color = v_color;
}
7 changes: 4 additions & 3 deletions example/shader_vertex_2d.glsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#version 300 es
// an attribute will receive data from a buffer
attribute vec2 a_position;
attribute vec4 a_color;
in vec2 a_position;
in vec4 a_color;

uniform mat3 u_matrix;

// color to pass to the fragment shader
// value in fragment shader will be interpolated
varying vec4 v_color;
out vec4 v_color;

void main() {
// Multiply the position by the matrix.
Expand Down
7 changes: 4 additions & 3 deletions example/shader_vertex_3d.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#version 300 es
// will pass vec3, but will be converted to vec4 with w = 1.0
attribute vec4 a_position;
attribute vec4 a_color;
in vec4 a_position;
in vec4 a_color;

uniform mat4 u_matrix;

varying vec4 v_color;
out vec4 v_color;

void main() {
// Multiply the position by the matrix.
Expand Down

0 comments on commit cbd8708

Please sign in to comment.