Skip to content

Commit

Permalink
Implement color buffer (#5)
Browse files Browse the repository at this point in the history
* Finish adding color buffer to the shaders

* Full assignement, except bonus, finished

* Fix code such that it defines a camera rather than moving the objects

* formatting

* linting

* add pdf

---------

Co-authored-by: CraZyB1336 <[email protected]>
  • Loading branch information
michaelbrusegard and CraZyB1336 authored Sep 20, 2024
1 parent b762370 commit 510f75a
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 109 deletions.
Binary file added assignments/Computer_Graphics___Assignment_2.pdf
Binary file not shown.
74 changes: 74 additions & 0 deletions gloom-rs/shaders/fragShaderRestCode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Position for spiral, circle, and triangle.
vec2 p = vec2(2.0 * gl_FragCoord.xy) / 750.0;

// Spiral
// float theta = atan(p.y, p.x);
// color = spiral(p, 5.0, 12.0) < 0.6 ? pastel_night_sky : moon_white;

// Burgundy-red
// color = vec4(0.5, 0.0, 0.13, 1.0);

//Checker-pattern
//int x = int(gl_FragCoord.x);
//int y = int(gl_FragCoord.y);
//color = checkerbox(x, y, 30);

// Drawn Circle
// float r = 0.3;
// color = sdCircle(p, r);

// Color over time
// color = vec4(cos(time+24), sin(time * 0.2), atan(time+24, time), 1.0);

// Manual triangle
// vec2 pos1 = 2.0 * vec2(120.0, 200.0) / 750.0;
// vec2 pos2 = 2.0 * vec2(630.0, 200.0) / 750.0;
// vec2 pos3 = 2.0 * vec2(375.0, 550.0) / 750.0;
// float d = sdTriangle(pos1, pos2, pos3, p);

// color = mix(night_sky, moon_white, cos(160.0 * d));
// color *= exp(-2.3 * abs(d));

// color = d > 0.0 ? color : mix(color1, vec4(0.5, 0.0, 0.13, 1.0), 1.0 - smoothstep(0.01, 0.3, abs(d)));

// if (d >= -0.005 && d <= 0.005)
// {
// color = color1;
// }

// A sine wave
float y = 0.05*sin(10*p.x - PI*time/2) + 0.7;
float white_wave = 0.01*sin(30*p.x - PI*time/1.5) + 0.7;
float blue_wave = 0.02*cos(12*p.x + PI*time) + 0.63;
float light_wave = 0.03*cos(7*p.x - PI*time/1.8) + 0.58;

if (y > p.y)
{
color = waves;
if (p.y > light_wave - 0.06)
{
color = vec4( 84, 136, 200, 255) / 255;
}
if (p.y > blue_wave)
{
color = vec4( 143, 182, 228, 255) / 255;
}
if (p.y > white_wave)
{
color = color1;
}
}
else
{
color = night_sky;
}

vec2 moon_p = vec2(p.x - 1.0, p.y - 1.2);
float sd = sdCircle(moon_p, 0.15);
vec2 moon_rp = vec2(p.x - 0.92, p.y - 1.24);
float sdrp = sdCircle(moon_rp, 0.09);

if (sd < 0.0 && sdrp > 0.0)
{
color = vec4( 243, 249, 169, 255) / 255;
}
78 changes: 2 additions & 76 deletions gloom-rs/shaders/simple.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
uniform float time;

out vec4 color;
in vec4 vertColor;

vec4 pastel_night_sky = vec4(0.305, 0.454, 0.494, 1.0);
vec4 moon_white = vec4(0.94, 0.917, 0.66, 1.0);
Expand Down Expand Up @@ -69,81 +70,6 @@ float sdTriangle(vec2 p1, vec2 p2, vec2 p3, vec2 p)

void main()
{
// Position for spiral, circle, and triangle.
vec2 p = vec2(2.0 * gl_FragCoord.xy) / 750.0;

// Spiral
// float theta = atan(p.y, p.x);
// color = spiral(p, 5.0, 12.0) < 0.6 ? pastel_night_sky : moon_white;

// Burgundy-red
// color = vec4(0.5, 0.0, 0.13, 1.0);

//Checker-pattern
//int x = int(gl_FragCoord.x);
//int y = int(gl_FragCoord.y);
//color = checkerbox(x, y, 30);

// Drawn Circle
// float r = 0.3;
// color = sdCircle(p, r);

// Color over time
// color = vec4(cos(time+24), sin(time * 0.2), atan(time+24, time), 1.0);

// Manual triangle
// vec2 pos1 = 2.0 * vec2(120.0, 200.0) / 750.0;
// vec2 pos2 = 2.0 * vec2(630.0, 200.0) / 750.0;
// vec2 pos3 = 2.0 * vec2(375.0, 550.0) / 750.0;
// float d = sdTriangle(pos1, pos2, pos3, p);

// color = mix(night_sky, moon_white, cos(160.0 * d));
// color *= exp(-2.3 * abs(d));

// color = d > 0.0 ? color : mix(color1, vec4(0.5, 0.0, 0.13, 1.0), 1.0 - smoothstep(0.01, 0.3, abs(d)));

// if (d >= -0.005 && d <= 0.005)
// {
// color = color1;
// }

// A sine wave
float y = 0.05*sin(10*p.x - PI*time/2) + 0.7;
float white_wave = 0.01*sin(30*p.x - PI*time/1.5) + 0.7;
float blue_wave = 0.02*cos(12*p.x + PI*time) + 0.63;
float light_wave = 0.03*cos(7*p.x - PI*time/1.8) + 0.58;

if (y > p.y)
{
color = waves;
if (p.y > light_wave - 0.06)
{
color = vec4( 84, 136, 200, 255) / 255;
}
if (p.y > blue_wave)
{
color = vec4( 143, 182, 228, 255) / 255;
}
if (p.y > white_wave)
{
color = color1;
}
}
else
{
color = night_sky;
}

vec2 moon_p = vec2(p.x - 1.0, p.y - 1.2);
float sd = sdCircle(moon_p, 0.15);
vec2 moon_rp = vec2(p.x - 0.92, p.y - 1.24);
float sdrp = sdCircle(moon_rp, 0.09);

if (sd < 0.0 && sdrp > 0.0)
{
color = vec4( 243, 249, 169, 255) / 255;
}

// Default color
// color = vec4(1.0, 1.0, 1.0, 1.0);
color = vertColor;
}
18 changes: 15 additions & 3 deletions gloom-rs/shaders/simple.vert
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#version 410 core

in vec3 position;
layout(location=0) in vec3 position;
layout(location=1) in vec4 color;

uniform float oscVal;
uniform mat4 matrix;

out vec4 vertColor;

void main()
{
// vec3 flipped_position = vec3(position.x * -1, position.y * -1, position.z);
gl_Position = vec4(position, 1.0f);
vec4 pos = vec4(position, 1.0);

// When defining our matrix like this
vec4 transformed_position = matrix * pos;


gl_Position = transformed_position;
vertColor = color;
}
Loading

0 comments on commit 510f75a

Please sign in to comment.