Write me a simple GLSL shader that affects only a solid unbroken blob of red color
- User
Write me a simple GLSL shader that affects only a solid unbroken blob of red color
- Assistant
Certainly! Here's a simple GLSL shader that will create a solid unbroken blob of red color:
#version 330 core uniform vec2 resolution; out vec4 fragColor; void main() { vec2 center = resolution / 2.0; float radius = min(resolution.x, resolution.y) / 4.0; float distance = length(gl_FragCoord.xy - center); if (distance <= radius) { fragColor = vec4(1.0, 0.0, 0.0, 1.0); } else { discard; } }In this shader, we define a uniform
vec2 resolutionto access the resolution of the screen. We calculate the center of the screen ascenter, and set the radius of the blob as one-fourth of the minimum of the screen's width and height.Inside the
main()function, we calculate the distance of the current fragment's coordinate from the center. If the distance is less than or equal to the radius, we set the fragment's color to red (vec4(1.0, 0.0, 0.0, 1.0)). Otherwise, we discard the fragment.Make sure to set up a basic rendering pipeline in your code to apply this shader to a renderable object.