mirror of
https://github.com/bvanroll/shaders.git
synced 2025-08-29 20:12:48 +00:00
aspect ratio
This commit is contained in:
27
learning/shapes/box.frag
Normal file
27
learning/shapes/box.frag
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0,0.0,0.0);
|
||||
|
||||
|
||||
//draw box
|
||||
//float left = step(0.1,st.x); // everything > 0.1 = 1.0
|
||||
//float bottom = step(0.1,st.y); // everything > 0.1 = 1.0
|
||||
//float right = 1.0-step(0.9,st.x);
|
||||
//float top = 1.0-step(0.9,st.y);
|
||||
//color = vec3(left*bottom*top*right);
|
||||
vec2 bottom_left = step(vec2(0.1),st); // does the same as previous code but passes vec2's to get both
|
||||
vec2 top_right = vec2(1.0)-step(vec2(0.9),st);
|
||||
color = vec3(bottom_left.x * bottom_left.y * top_right.x * top_right.y);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
18
learning/shapes/circle.frag
Normal file
18
learning/shapes/circle.frag
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
// vec3 color = vec3(0.0,0.0,0.0);
|
||||
|
||||
float pct = distance(gl_FragCoord.xy, (vec2(0.5)*u_resolution)) // find a way to make this a circle even when non 1:1 aspect ratio
|
||||
vec3 color = vec3(pct);
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
21
learning/shapes/main.frag
Normal file
21
learning/shapes/main.frag
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
varying vec2 v_texcoord;
|
||||
|
||||
void main(void) {
|
||||
vec4 color = vec4(vec3(0.0), 1.0);
|
||||
vec2 pixel = 1.0/u_resolution.xy;
|
||||
vec2 st = gl_FragCoord.xy * pixel;
|
||||
vec2 uv = v_texcoord;
|
||||
|
||||
color.rgb = vec3(st.x,st.y,abs(sin(u_time)));
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
Reference in New Issue
Block a user