Results 1 to 3 of 3

Thread: surface colour derived from vertex y axis

  1. #1
    Newbie Newbie
    Join Date
    Apr 2014
    Posts
    2

    surface colour derived from vertex y axis

    Hi - my first thread/post, and apologies to all if this should be in the OGSL section - I'm an openGL newbie.

    I'm generating surfaces that plot the distribution of data, each data point has an x and y value and my surface plots the number of times a particular combination of a x and y have been received - see the attached screen grab. To help visualise the vertical frequency axis I'm also applying a colour map to the z axis. The surface is drawn using triangles. calculation of the vertices colour is calculated before the data is sent to the graphics card [working on using VBOs, at the mo I specify each triangle vertex by vertex]

    My question is, can I use a shader [which I assume are compiled and loaded onto the GPU] to calculate the colour from the vertex y axis value? Can I preload a colour map into the GPU that the GPU can use to look up the y value and get the RGB value of the vertex?

    The graph has to update regularly as it will be monitoring a live steam of data. Is there any speed advantage in getting the GPU to do the colour calculation?
    Attached Images Attached Images

  2. #2
    Member Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    78
    The fragment shader would look like the following (though untested):

    Code :
    #version 330
     
    uniform sampler1D heightGradient; // gradient texture with colour transition
     
    uniform float heightMin; // height to be assigned with the lowest colour
    uniform float heightMax; // height to be assigned with the highest colour
     
    uniform vec4 vertexPosition; // position of pixel to be drawn (unprojected!)
     
    void main()
    {	
    	float coord = (vertexPosition.Y - heightMin) / (heightMax - heightMin) - heightMin; // or any other calculation that suits your needs
    	coord = clamp(coord, 0.0f, 1.0f); // can also be defined outside of GLSL to handle the behaviour outside the texture
     
    	gl_FragColor = texture1D(heightGradient, coord); // final color assign
    }

    Yes, you can preload the colour transition map to the GPU. The rest works as mentioned above. I am quite unfamiliar with data live streams, so I cannot help you there.

  3. #3
    Senior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    I just saw your post here and already responded to you other post elsewhere on the forum. Please do not cross post.

Similar Threads

  1. OpenGL does not read the colour correctly from my vertex array
    By karnivaurus in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-10-2015, 02:38 PM
  2. Setting colour of vertex doesn't work
    By karnivaurus in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-07-2015, 11:13 AM
  3. how the matrix of glOrtho is derived?
    By Leonard2012 in forum OpenGL: General
    Replies: 4
    Last Post: 03-12-2012, 10:15 PM
  4. Fastest way to stream CPU-derived vertex data
    By bmerry in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-02-2006, 06:03 AM
  5. how to draw surface with axis
    By porsgl in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-18-2002, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean