Skip to content
The Chat Archive
Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written) OpenAssistant Conversations (oasst2)

write a glsl shader

In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
  1. User

    write a glsl shader

  2. 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).

  3. User

    thank you! i'll test it now :D

  4. Assistant

    Sounds good, Let me know if you need anything further!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.