Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update frag shader + comment #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions render/mainWindow/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cd ../../render/mainWindow && cd fragment && glslangValidator -V baseShader.frag && cd ../vertex && glslangValidator -V baseShader.vert
80 changes: 79 additions & 1 deletion render/mainWindow/fragment/baseShader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,87 @@
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec3 fragColor;

layout(location = 0) out vec4 outColor;

void drawCircle(vec2 center, float radius, bool gradient, bool invert) {
float centerDistance = distance(gl_FragCoord.xy, center.xy);
vec3 grad = vec3(centerDistance/radius,centerDistance/radius,centerDistance/radius);
if (centerDistance <= radius) {
if (invert) {
outColor = vec4(1.0-fragColor.x, 0.0, 1.0-fragColor.z, 1.0);
} else {
float color = 1.0;
if (gradient) {
color = 1.-centerDistance/radius;
} outColor = vec4(color, color, color, 1.0);
}
} else {
outColor = vec4(fragColor, 1.0);
}
}

void drawQuatrefoil(vec2 center, bool gradient, bool invert) {
float x = gl_FragCoord.x-800;
float y = gl_FragCoord.y-800;
float centerDistance = pow(pow(x,2)+pow(y,2),3);
float radius = 3200000*pow(x*y,2);
if (centerDistance <= radius) {
if (invert) {
outColor = vec4(1.0-fragColor.x, 0.0, 1.0-fragColor.z, 1.0);
} else {
float color = 1.0;
if (gradient) {
color = 1.-centerDistance/radius;
} outColor = vec4(color, color, color, 1.0);
}
} else {
outColor = vec4(fragColor, 1.0);
}
}

void drawCardioid(vec2 center, float a, bool gradient, bool invert) {
float x = gl_FragCoord.x-800;
float y = gl_FragCoord.y-800;
float centerDistance = pow(pow(x,2)+pow(y,2)-a*x,2);
float radius = pow(a,2)*(pow(x,2)+pow(y,2));

if (pow(pow(x,2)+pow(y,2)-a*x,2)<=pow(a,2)*(pow(x,2)+pow(y,2))) {
if (invert) {
outColor = vec4(1.0-fragColor.x, 0.0, 1.0-fragColor.z, 1.0);
} else {
float color = 1.0;
if (gradient) {
color = 1.-centerDistance/radius;
} outColor = vec4(color, color, color, 1.0);
}
} else {
outColor = vec4(fragColor, 1.0);
}
}

void drawLemniscate(vec2 center, float d, bool gradient, bool invert) {
float x = gl_FragCoord.x-800;
float y = gl_FragCoord.y-800;
float centerDistance = pow(pow(x,2)+pow(y,2),2);
float radius = 2*pow(d,2)*(pow(x,2)-pow(y,2));
if (pow(pow(x,2)+pow(y,2),2)<=2*pow(d,2)*(pow(x,2)-pow(y,2))) {
if (invert) {
outColor = vec4(1.0-fragColor.x, 0.0, 1.0-fragColor.z, 1.0);
} else {
float color = 1.0;
if (gradient) {
color = 1.-centerDistance/radius;
} outColor = vec4(color, color, color, 1.0);
}
} else {
outColor = vec4(fragColor, 1.0);
}
}

void main() {
//drawCircle(vec2(800,800),400,true,false);
//drawCardioid(vec2(800,800),400,true,false);
//drawLemniscate(vec2(800,800),400,true,false);
//drawQuatrefoil(vec2(800,800),true,false);
outColor = vec4(fragColor, 1.0);
}
Loading