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 2 of 2

Thread: Using a shader to calculate colour from y value

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

    Using a shader to calculate colour from y value

    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 Thumbnails Attached Thumbnails Click image for larger version. 

Name:	ogld4.jpg 
Views:	55 
Size:	23.0 KB 
ID:	1280  

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    140
    Quote Originally Posted by kevindoig View Post
    My question is, can I use a shader to calculate the colour from the vertex y axis value?
    Sure. In the vertex shader, take the y component of the position before applying perspectvie projection and do whatever computation on it. The generated variable is an out parameter/varying of the vertex shader, and the interpolated result is used by the fragment shader as fragment color.[/QUOTE]

    Quote Originally Posted by kevindoig View Post
    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?
    Write the color map into a 1D texture, use the value computed in the vertex shader to fetch the coresponding color from the texture

    Quote Originally Posted by kevindoig View Post
    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?
    Massively parallel? On the CPU, you would caclulate the color sequentially for each vertex. Depends on how involved the computation is and how many vertices you have.

Posting Permissions

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