Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Andos

Raycasting Formula?

This topic is 5908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a 3D engine and I want some lights. My prob here is that the light also appears on the other side of my 3D object. I have made a light formula and I only want the light to apear on the side nearest the light source. The Raycasting formula?

Share this post


Link to post
Share on other sites
Advertisement
I assume you use the dot product to calculate light? In that case, if the result is negative (or positive), the triangle-face is facing away (just like hidden surface removal), and you should not lit the face.

Share this post


Link to post
Share on other sites
Generally, if you don''t use the api light system itself, (like OpenGL or DX lighting) you should first find the normal of your plane (triangle, quad, whatever) and the vector from the middle of that plane to the light. (you can make it faster by chosing one of the vertices and not the middle)
The dot product of these two normalized vectors should give you the cosine of the lightray falling on the plane. If it''s negative, the light is behind so the poly is not lit. If it''s positive, the light shines somewhere in front of your poly and you should compute how much it affects the polygon color. (using the cosine ofcoz)
Now sth about the dot product:
suppose you have the normalized (length = 1) normal vector: N
and the vector from your polygon to the light: L
N = (nx, ny, nz) L = (lx, ly, lz)
The dot product: Dot(N, L) should be computed as:
DotProduct = nx*lx + ny*ly + nz*lz
Got it? ;-)

I advise you to search some good tutorials on lighting. There are many.

Greetings

Share this post


Link to post
Share on other sites
You see... I''m from denamrk and only 16 years old, so I''m having a little troubble understanding what you are meaning. You are right. I''m trying to make a non textured 3D engine with the way of lightning you explained. I''ve made a formula for this. I''t quite complicated but i''s used to get the percent og lightning of the colour brightness. 0%= black 100%=white 50%=(whatever)

Share this post


Link to post
Share on other sites
You see... I''m from Denmark and only 16 years old, so I''m having a little troubble understanding what you mean. You are right. I''m trying to make a non textured 3D engine with the way of lightning you explained. I''ve made a formula for this. I''t quite complicated but i''s used to get the percent og lightning of the colour brightness. 0%= black 100%=white 50%=(whatever)
My formula is:
(( Tan-1(( Ya – Yb)/(Xa – Xb))+90)/ Tan-1((((Xa+Xb)/2)-Xlight)/(((Ya+Yb)/2)-Ylight))*100/2)+(( Tan-1(( Za – Zb)/(Xa – Xb))+90)/ Tan-1((((Xa+Xb)/2)-Xlight)/(((Za+Zb)/2)-Zlight))*100/2)

This gives the percent of the x and z divided by 2 and added to the percent of x and z and divided by 2.
I hope youunderstand what I mean.
Can you explane what vectors is? Is it the angle between to spots? I don''t know.

Share this post


Link to post
Share on other sites
Whoooow, complicated formula :D
Well a vector in the 3 dimentional space is (generally) defined by three coördinates; the x, y, and z.
Imagine a point in space with these coörds. A vector with these coördinates would be the direction to the point from the origin. (the origin is always at x = 0, y = 0, z = 0)

Unfortunately for you (God bless for me :-D), I''m not a teacher.
I think it should be a good idea to ask your mathematics-teacher more explanation about vectors and points ''cause I''m really bad in explaining things (especially in english, lol)
I advise you to look at http://www.gamedev.net/community/forums/topic.asp?topic_id=86063
they''re also talking about points and vectors.

Share this post


Link to post
Share on other sites
Oh you mean what I call a point.
The formula I fugured ouy myself, but I''m not 100% sure that it''s working.

Share this post


Link to post
Share on other sites
Gee, you''ve worked on that one, didn''t you? Am as old as you (I live in Sweden too ), and I haven''t done something like that! (Mostly because I wouldn''t think it was worth the work with all those trigs, phew!).

I''ve learnt you''re using some sort of Click-programming, right? How are your geometry and lightsources stored? How do they work? Can you read vertices and manipulate them?

If you answer these questions, we might give u some more help.

Share this post


Link to post
Share on other sites
It took me 45 minutes to make that one...
I''m planning to make several lists. One for X one for Y and one for Z and one that sorts them in a ways i can use when i shall render the screen. (No textures only coloures) If I can understand the point in polygon thing i can render the screen.

I''m thinking of make a database (made automatickley when making the 3D objects) so that my engine can detect what the ID is for the vertices in the polygon.

Example on my light formula:


Polygon(side)
|
|
| (L)ight
|
|
Result= 100% light on the surface

Polygon(side)
\
\
\ (L)ight
\
\
Result= 75% light on hte surface
because the side was twisted.


---------- (L)ight

Result= 0% light on the surface


(This is in 2D but my formulais in 3D)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!