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

Thread: 2D grid with color value fields

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    3

    2D grid with color value fields

    Hello!

    I am doing a project in which I have a 3D model, from which I need to extract hight information (z-value) of each (x,y) coordinate, and then transform it into a 2D grid map, where each coordinate will have a particular colour gradient (e.g. green to red) depending on the value of the z-coordinate. Also, an alternative is to group a couple of "pixels" in a 10x10, or larger, tile, which will have an uniform color based on the medium value of the pixels within it.

    I appologize if this is a too basic question, I have researched the forum and a couple of guides, but I can only find how to make regular grids, without any information in their tiles.

    Thanks in advance!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    By height do you mean distance from the camera? If so it is just your depth buffer.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    3
    well, basically it's the real height of the object the camera sees. It's already calculated within the program, it can be considered as known. I just need to transform that value into the tile color..

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    16
    Not sure what you are trying to do. z value is normally the depth as tonyo_au said. y value is normally height.

    But if you are trying to simply color objects with a gradient going from green to red. This shouldn't be hard as you can either use the world position of the fragment to pick a color depending on the fragment position relative to the near and far plane (if you want a gradient based on the depth from the camera). Or you could use the bounds of the object and color it with the gradient based on the position of the fragment relative to the bounds of the object. (Think axis aligned bounding box (or just use min and max value of y or which ever coordinate you want to use)).

    If I have miss understood what you are trying to do feel free to clarify.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    3
    Ah, yes, I apologize, my mistake, the height is the Y coordinate.

    I'll try to clarify, maybe I didn't express myself very well, but basically it's the second thing you've mentioned..
    Basically, I would like to make a 2D grid, table or something similar, where each field (whose coordinates would be (X,Z) - which are the two of the (X,Y,Z) 3D coordinates) would have a value which is dependent on the value of the Y coordinate of that particular pixel. These values X,Y and Z I already know, I can extract them from the image.

    The problem I have, is that I don't now which structure would provide this. Should I make a grid consisting of lines intersecting - then how do I color the fields? Or, should I make like a square for each pixel and color it individually?
    Also, could you please point me maybe to some tutorials that explain this, because I was unable to find one..maybe because I didn't know how to specify my problem when I searched.

    When I manage to do this, I could maybe extend it to making one field in that grid not equivalent to just one pixel, but maybe to a tile consisting of 10x10 pixels, and then the value of that tile would be the average Y of those pixels included.

    Thanks again for your help!
    Last edited by elrakone; 04-17-2013 at 08: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
  •