PDA

View Full Version : Shadows in WebGL



jimmyt1988
02-28-2012, 06:02 PM
Hi all.

I have followed the learningwebgl tutorials and have gone over them many times trying different things.


I have learnt about dot products (angle between 2 vectors)[/*:m:2dzmvpoo]
I have learnt about a vector being a direction and magnitude(length of a vector)[/*:m:2dzmvpoo]
I have learnt about what a normal is (perpendicular vector to a plane (and in this case, the center of 3 vertices? right?)[/*:m:2dzmvpoo]
I have learnt about multiplying colours together to get a mix of colours that represent shading.[/*:m:2dzmvpoo]
I have learnt that you can get the distance (magnitude) of a vector by doing what is pretty much pythagoras across x,y and z rather than just aČ + bČ.[/*:m:2dzmvpoo]

I have come across a fundamental lack of understanding now and it's time to clear it up so I can progress.

Here is a few questions to start this thread going:

A vertex shader does linear interpolation between 3 points to find out all the pixels/points within that plane. The fragment shader processes each of those points which allows us to apply colours to it?[/*:m:2dzmvpoo]
I noticed that in the shader files, there is void main() for each one. Can i then assume that these are completely different apart from whatever is declared within the vertex shader is eventually passed through into the fragment shader. [/*:m:2dzmvpoo]
From the vertex shader, you are given a triangulated plane (3 vertices) in which you can do some math to... within the shader... to identify which points in the fragment shader need to be multipled with a 50% opaque black in order to cast a sexy shadow?[/*:m:2dzmvpoo]

I really do appreciate any help given. Although not utterly stuck, I find clarification the key to confident progression.

Thanks in advance!

jimmyt1988
02-29-2012, 04:44 AM
I found this and this seems to help alot. I'll read it tonight and get back to you on any further thoughts: http://archive.gamedev.net/archive/refe ... page2.html (http://archive.gamedev.net/archive/reference/programming/features/shadows/page2.html)

is it possible to write functions in the shader files:

void function_name(param1 type, param2 type){
//
}

kinda thing?

then call them like
function_name(param1 type, param2 type);

Can i have an example of a function if so.
It being made, and it being called.

Sergejack
03-02-2012, 06:51 AM
You should look for explanations about Shadow Map(ping).

lthornblad
03-03-2012, 02:30 PM
Your first post is a bit unclear in terms of what you are looking for. That article is a very simplistic type of shadowing, but perhaps that is all you need(?). The common techniques make use of either a stencil buffer or shadow mapping. There are lots of articles online for both, but they are fairly advanced topics.

To answer your last question, you can certainly create functions inside of glsl shaders similar to what you described.

jimmyt1988
03-06-2012, 07:07 AM
Do you have an example so I can get the syntax right?