Extracting per-pixel shader information for a face

edited January 2017 in GLSL / Shaders

Hi all, I'm hoping this isn't too horribly complicated, but I'd like to figure out how to get the per-pixel values for a 3D face after applying lighting. I would like to use this to map individual faces to a PGraphics buffer that I then projection map onto an object. To put it another way, I'd like to bake the lighting for each face as I step through the frames of a sketch to an unwrapped 2D texture that I can access, pixel by pixel, or otherwise manipulate as a PGraphic or PImage. I think PShaders are the ticket, but I can't figure out where to start.

I'd be happy if I could get this to work with a simple cube, or even a single planar face. Could expand from there...

Best, Drew Hamilton

Tagged:

Answers

  • After a little research, I'm realizing that there is no OpenGL buffer that contains all the information for individual faces in 3DLand, and there is also no method to access variables in a shader.

    The only two solutions I can come up with are:

    1. To write code to orient to a face and read from the framebuffer, but that could be problematic if you have occluded faces.

    2. To write a custom ray tracer, but that defeats the purpose of having OpenGL at all.

    Any ideas appreciated!

    Best, Drew

  • If you draw your 3D image and after applying lightning to it, then you could call loadPixels() to access every pixel in the screen individually or you could use get() a an alternative. You can do this for every frame and you will be storing all this pixel info that you are interested in. In other terms, you could just save each frame and analyze the data later.

    https://processing.org/reference/PImage_get_.html

    https://processing.org/reference/PImage_loadPixels_.html

    Kf

  • I was hoping for something that would give me direct access to the light values on a piece of geometry, as opposed to the pixel values after being projected onto the screen, if that makes sense...

Sign In or Register to comment.