write a glsl shader
- User
write a glsl shader
- Assistant
Certainly! Here's a simple GLSL shader that creates a smooth color gradient across a 2D plane:
// Vertex Shader attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); } // Fragment Shader precision mediump float; uniform float time; uniform vec2 resolution; void main() { vec2 uv = gl_FragCoord.xy / resolution.xy; vec3 color = vec3(0.5 * sin(time), 0.5 * cos(time), 0.5); gl_FragColor = vec4(color, 1.0); }This shader uses the position attribute to pass in the coordinates of each vertex in the 2D plane, and uses those coordinates to set the gl_Position variable, which determines where each vertex is positioned on the screen.
The fragment shader then calculates the color of each pixel on the screen based on its position (gl_FragCoord) and the current time (time). The resolution uniform is used to convert the pixel coordinates into normalized UV coordinates (ranging from 0.0 to 1.0).
The color is calculated using a combination of the sin() and cos() functions, which oscillate between -1.0 and 1.0 based on the current time. These values are then scaled and combined to create a smooth gradient across the screen. Finally, the gl_FragColor variable is set to the calculated color, with an alpha value of 1.0 (fully opaque).
- User
thank you! i'll test it now :D
- Assistant
Let me know how it goes!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)