Reputation: 11
In OpenGL I could just do something like
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
...
GLfloat position[] = {-1.0f, 0.5f, 0.5f, 0.0f};
glLightfv(GL_LIGHT1, GL_DIFFUSE, color);
glLightfv(GL_LIGHT1, GL_POSITION, position);
And I'd have a directional light.
How would I go about creating a directional light in a shader in webgl? In particular the following situation:
------------------------> | O
^ ^ ^
directional light source wall Some object
Where I'd like the wall (or any other opaque objecct) to absorb out the light, preventing it from hitting object O
Upvotes: 1
Views: 817
Reputation: 76772
You can use a technique called shadow mapping to get pretty nice looking shadows. Here's a tutorial I used to learn about it:
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
http://en.wikipedia.org/wiki/Shadow_mapping
Upvotes: 1