Jump to content
  • Advertisement
Sign in to follow this  
TheKrust

World positioned lighting

This topic is 3922 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 have looked for an answer everywhere and either I'm not finding one or I'm just not understanding the answer. I am trying to create a semi-3D engine and I am working on lights. I have no problems using them but when I rortate and move around the world, I would expect the light to follow. Instead, it just stays in the same position. Does anyone know how to make the light positions align with world translation and rotation? I have yet to find an example program that even attempts to do this. (NOTE: my last 2 posts, I have had people that have given me very rude comments about being lazy and posting here rather than looking for myself. Rest assured I have looked almost everywhere I can think of and have found nothing.) [Edited by - TheKrust on September 27, 2007 5:42:16 PM]

Share this post


Link to post
Share on other sites
Advertisement
Light positions are specified in world coordinates, not model coordinates, so they are not affected by the world transformation.

When you move your camera around by the view transformation, it changes the point of view of the scene, but doesn't move any objects in the scene -- including lights.

If you want your lights to follow your camera, then you must move the lights every time you move the camera.

Relevant chapters from my book:
Chapter 6. Vertex Transformations
Chapter 8. Lighting and Materials

Share this post


Link to post
Share on other sites
hmmm... thank you, but I guess I was already having tha thought. It must be that I'm just missing a critical step.

I'm putting the light coordinates in the same place as all my other verticies, so it seems like when I transform the world, those would be transformed with it. They are all held in the same vertex buffer, and done in the same render pass. Is their some special method or key word I need to use to place the light coordinate in model space?

If I'm asking the wrong question above, a more general one might be... is there a set way to move the lights without manually having to do 3D math. DirectX automates everything else, it would seem crazy if they didn't have a function for that.

Share this post


Link to post
Share on other sites
What's wrong with doing 3D math? It seems that a lot of people are trying very hard to eke away from mathematics when it is at the -core- of game development. Hell, programming is a subset of formalized logic which is a subset of mathematics.

But that's tangential.

The point is that if you want your light to move with your camera, you are going to have to learn some matrix mathematics. Or use a library like the D3DX. It has matrix multiplication in it.

Or you could always explicitly set your light's position variable to whatever it originally was + your camera's current position so as to move it with your view.

But we really need more information. Based on your post, I'm assuming you're doing this using DirectX and the fixed function pipeline. First of all, I'd like to mention that the fixed-function pipeline has been declared deprecated and unless you need to take advantage of lesser hardware, I would recommend getting a solid understanding of how the pipeline works (transformation, clipping, rasterization, etc.) and move to a shader based engine. But that's just opinion.

I guess I need more clarification. Why is it that you'd expect the light to rotate and move around the world with you? You're specifying explicit world coordinates and will have to transform it yourself.

Share this post


Link to post
Share on other sites
Quote:
Original post by Julian Spillane
What's wrong with doing 3D math? It seems that a lot of people are trying very hard to eke away from mathematics when it is at the -core- of game development. Hell, programming is a subset of formalized logic which is a subset of mathematics.

But that's tangential.

The point is that if you want your light to move with your camera, you are going to have to learn some matrix mathematics. Or use a library like the D3DX. It has matrix multiplication in it.

ect. ect. ect......


What I was asking was HOW would I do that math? What functions would I need? (plus, I really suck at math)

BUT lol, you're not even gonna belive this. I just solved my problem. Turns out I wasn't making use of D3DTS_VIEW but using D3DTS_WORLD by accident... that cleared it all up XD .

EDIT: btw, I am converting peices of it to shader based, and eventually moving it to a full shading engine. I am picking up a couple of books right now. I don't fully get how shaders work yet, but that's why I just getting the core of the engine down right now.

Share this post


Link to post
Share on other sites
It sounds like you're using the world transform as a view transform.

Lets say I have a room with a world transform set to identity. The * vertex happens to be at 0,0.
+-----+
| |
| |
*-----+



Now I add a chair, and it's world transform translates it to (1,1).
+-----+
| |
|C |
*-----+



If I want to move the chair, I change the chair's world transform to, say, (3,2)
+-----+
| C |
| |
*-----+



Lets add a light at (2,2). This doesn't use a transform as the light position is in world space in the light structure. Transforms are only for moving vertices.
+-----+
| LC |
| |
*-----+


The world transform is for moving an object. If I move a chair across the room, I change the world transform when rendering the chair.

The view transform is for moving the camera. The room, chair and light remain where the are in world space. I'm just changing where I'm looking from.

What it sounds like you're doing is having all your geometry pre-placed in your vertex buffer, which is fine, just set world to identity. Next it sounds like you're moving through your world by changing the world transform, which is wrong. When I walk forward, it's my viewpoint that's moving (D3DTS_VIEW). It's not that the room and chair are moving backwards. Because you're moving the location of the room and chair (but not the light) you've having a problem.

Just change your code to adjust the view transform instead of the world transform and you should be set.

edit: D'oh. Of course you figured this out while I was typing.

Share this post


Link to post
Share on other sites
thanks errr ummm... Namethatnobodyelsetook .... lol, you shoulda posted that 5 minutes ago though. I just figured out that's what I was doing. It is no joke when I say there should be more posts like that... giving straight facts and answers rather than giving opinions and trying to sound superior. Unfortunatley that happens a lot (I admit occasionally I'm guilty of that too)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!