To the best of my knowledge there is not a shortcut for doing that. You would have to set up a "virtual camera" which really just a 3D point in space. Between the virtual camera and the 3D objects you have a "virtual grid" which represents the pixels from the virtual camera's point of view. Then you would shoot a ray from the virtual camera through each hole in the grid, determine which 3D object the ray intersected, and get the length of the ray. Then you would map the lengths of the rays to black and white pixels.
Here is an image that hopefully helps the explanation. Ignore the light source and shadow in the diagram, you don't need a light source for what you want:
Hello,
Unfortunately, that's exactly what I'm trying to do and the above code won't work and give the following error :
==================================================
java.lang.runtimeException : Cannot compile vertex shader;0(18) warning C7583: Initialization of uniform variables require #120 or later0(19)
"java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:926)
at processing.mode.java.runner.Runner.reportException(Runner.java:871)
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797)
at processing.mode.java.runner.Runner$2.run(Runner.java:686)
"
@capturevision: That means, that your GLSL version doesn't allow you to initialize uniform variables directly. Just initialize them via Processing's set() function instead.
In the fragment shader code, replace lines 6 till 9 with:
Answers
To the best of my knowledge there is not a shortcut for doing that. You would have to set up a "virtual camera" which really just a 3D point in space. Between the virtual camera and the 3D objects you have a "virtual grid" which represents the pixels from the virtual camera's point of view. Then you would shoot a ray from the virtual camera through each hole in the grid, determine which 3D object the ray intersected, and get the length of the ray. Then you would map the lengths of the rays to black and white pixels.
Here is an image that hopefully helps the explanation. Ignore the light source and shadow in the diagram, you don't need a light source for what you want:
Using a simple vertex and a slightly more complex fragment shader.
Processing code:
Vertex shader code:
Fragment shader code:
In case you don't know how to use these code-snippets:
Hello, Unfortunately, that's exactly what I'm trying to do and the above code won't work and give the following error :
================================================== java.lang.runtimeException : Cannot compile vertex shader;0(18) warning C7583: Initialization of uniform variables require #120 or later0(19)
"java.lang.NullPointerException at processing.mode.java.runner.Runner.findException(Runner.java:926) at processing.mode.java.runner.Runner.reportException(Runner.java:871) at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797) at processing.mode.java.runner.Runner$2.run(Runner.java:686) "
==================================================
I'm using processing 2.1.1.. Any clue please ?
@capturevision: That means, that your GLSL version doesn't allow you to initialize uniform variables directly. Just initialize them via Processing's set() function instead.
In the fragment shader code, replace lines 6 till 9 with:
And in the Processing code, replace lines 13 till 16 with:
Hey ;) !
@Poersch : Thanks a lot.. works like a charm !
But, does that mean that I have to update my GLSL version ? I don't know how to do that, and my GPU drivers are up to date..