PDA

View Full Version : [D3D] smooth lightning



chronozphere
17-06-2006, 03:19 PM
Hi all. 8)

Today i started to build some lightning-support in my engine, the only problem is that the edges of the litted area are quiet sharp (see picture).

http://www.techzine.nl/f/g/36261phpAgoh9w.jpg

When i try some Attenuation values, the light seems to dissapear (sometimes only a small litted dot is visible).

Vertex density should be OK, its a 32x24 segment plane. each segment is 20x20.

Does anyone know how to make the lightning smoother??? :?

P.S: This is my first picture of my engine in action, maybe i'll post some more later. :razz:

JSoftware
17-06-2006, 03:50 PM
I don't think you can make lighting smoother by any means if you want to use vertex lighting. I would personally go with perpixel lighting but i have no idea how to implement that in d3d

K4Z
18-06-2006, 12:34 AM
I don't know anything about D3D, but if this is simple vertex lighting, you could use a DotProduct. Depending on the angle of the vertex to the light, it will receive the appropriate lighting shade. ie, smother blend from light to shadow :wink:.

If you need a bit of code, I'll see what I can do.

Clootie
18-06-2006, 11:16 AM
First you should understand these docs/presentations:
one (http://developer.nvidia.com/object/perpixel_lighting.html)
two (http://developer.nvidia.com/object/mathematicsofperpixellighting.html)
three (http://developer.nvidia.com/object/perpixel_lighting_intro.html)

And after reading them - come back and ask questions about implementation :)
It would be great if you specify on what kind of hardware you would like to implement per-pixel lighting: DX7; DX8/9 ps.1.1/ps.1.4/ps.2.0; assembler pixel shaders or HLSL?

JSoftware
18-06-2006, 11:25 AM
dang it! K4Z is completely right! it should ofcourse look much better than that by the way you are doing it..

Do you remember to set the normals?

chronozphere
18-06-2006, 07:18 PM
I think this should be possible without perpixel-lightning. You can get quiet good results with per-vertex-lightning when vertex density is high enough (and i think it is in this case :D )

but this is even stranger:

http://www.techzine.nl/f/g/36261phpOQsLcP.jpg

This supposed to be a point light but it looks like some sort of spotlight pointing to the bottom-right corner.but despite its weird shape, it IS smooth :)
Here is the code i used:


ZeroMemory(@light,SizeOf(TD3DLight8));
light._Type := D3DLIGHT_POINT;
light.Diffuse.r := 3.0;
light.Diffuse.g := 3.0;
light.Diffuse.b := 3.0;
light.Position := D3DXVector3(0,0,20);
light.Range:= 500.0;
light.Attenuation0 := 0;
Light.Attenuation1 := 0.2;
Light.Attenuation2 := 0;
Graphic.D3D.SetLight(0, light);
Graphic.D3D.LightEnable(0, True);


This just doesn't make any sense, can someone tell me what's goin on?? :?



First you should understand these docs/presentations:
one
two
three


Wow.. that's a whole lot of math for a teenager. Do i realy need to understand it all to use per-pixel lightning (i'll try PP lightning if PV lightning doesn't seem to work out :) ).



I don't know anything about D3D, but if this is simple vertex lighting, you could use a DotProduct. Depending on the angle of the vertex to the light, it will receive the appropriate lighting shade. ie, smother blend from light to shadow Wink.


Hmmm :think: this can be a good option, but i rather let the video-hardware do the job (not my CPU) ;)

Does someone have an example wich demonstrates a point light or can someone explain the picture above??

EDIT// the previous picture i posted shows a circle like it should be, unfortunatly i dont know how to reproduce it anymore :cry:

JSoftware
18-06-2006, 07:25 PM
do you remember to set normals? and are those per-vertex normals and are they normalized?

Clootie
18-06-2006, 10:02 PM
You can find fixed-function lighting example named "Lighting" here in big archive with all DirectX SDK samples for DX 8.1 (http://www.clootie.ru/delphi/download_dx81.html#d3d_all_in_one). On page you can find some small description. Basically example allows you to change light types, turn on/off wireframe rendering, etc.

K4Z
19-06-2006, 01:49 AM
Per-Pixel Lighting would probably be over-kill for your needs.
From what I've seen, D3D lighting model is pretty restrictive, and to gain complete control you should just override it.
Depending on your scene, software lighting shouldn't be too bad, though look into 'Vertex Programs' (I think D3D calls them that also) for pretty much no frame loss.

Hmm, but anyway, if your happy to stick with D3D lighting...That second picture looks familar to a problem I had. Will need to see some more code to be sure, but from an OpenGL view (D3D is pretty much the same), make sure you are in fact using a point light instead of a spotlight.

And most importantly, make sure you are (re)setting the light position every frame, ei, if you rotate or translate the entire scene, the light might not be exactly were you think it is.

and third, as Jsoftware said, make sure you set your normals correctly, and they are in fact 'Normalised'.

That's all I can think of at the moment :wink:

NecroDOME
19-06-2006, 05:59 PM
Maybe it could be your vertex normals. I had sort of the same problem with my engine.

chronozphere
19-06-2006, 07:08 PM
ahg :x it always turns out to be a stupid bug.

I was quiet convinced that my calculatenormals routine worked correctly, but it didn't. :( Fortunatly the bug is fixed, and the point light is shown correctly.

http://www.techzine.nl/f/g/36261phpM4fQTz.jpg

Thanx everyone for helping me find this bug. :D