Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Colours in GLSL

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    3

    Colours in GLSL

    Let's assume that I have a triangle with coordinates x,y,z=0,0,0 x,y,z=1,0,0 x,y,z=0.5,1,0

    I would like to achieve efect in which one half of the triangle is ( for example red ) and second blue. I ask for the code (in GLSL) in which I will be able to change
    colour of the pixel depending on coordinates of the triangle.

  2. #2
    Intern Contributor
    Join Date
    Sep 2010
    Posts
    74

    Re: Colours in GLSL

    In that case, it is be better to use two triangles.

  3. #3
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    303

    Re: Colours in GLSL

    You can give each Vertex a 1D 'texture coordinate' (0.0, 0.5 and 1.0) and color in the fragmentshader dependent on that value (provided by the VS as a varying):

    Code :
    in float texCoord;
    out vec3 color;
     
    void main() {
      if (texCoord > 0.5) {
        color = vec3(1.0, 0.0, 0.0);
      } else {
        color = vec3(0.0, 0.0, 1.0);
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •