Loading...
Logo
Processing Forum

OPENGL Shadows

in Core Library Questions  •  1 years ago  
Does anyone know of a simple example where OPENGL creates real-time shadows?

I know this is possible, but I have no idea how to implement it. 

Here is a good starting point:

Copy code
  1. import processing.opengl.*;

  2. void setup() {
  3. size(400, 400, OPENGL);
  4. camera(300, 300, 150, 100, 100, 50, 1, 1, 0);
  5. smooth();
  6. noStroke();
  7. }

  8. void draw() {
  9. rotateZ(frameCount/30.5);
  10. background(0);
  11. directionalLight(255, 255, 255, 0, -200, -100);
  12. fill(255);
  13. rect(-150, -150, 300, 300);
  14. sphere(50);
  15. //imitation shadow
  16. fill(10,100); translate(0,0,1); ellipse(0,-25,100,120); translate(0,0,-1);
  17. }

Replies(3)

Re: OPENGL Shadows

1 years ago
Any ideas?

Re: OPENGL Shadows

1 years ago
Shadow algorithms that could be applied to a general 3D scene are not simple. The page you mention in your post describes a technique called "stencil shadow volumes", but you need to use low-level opengl calls in order to implement it. Another couple of online articles that might be useful as well: here, and here.

Re: OPENGL Shadows

1 years ago
"Real" shadows usually involve ray tracing, which the OpenGL renderer doesn't do.  Your imitation shadow looks just fine though.  I've seen similar imitation shadows done on more complex models by flattening them via scale.  The hard part is drawing them on non-flat surfaces.