Lights not working
Lights not working
Lights not working
Lights not working
Lights not working
Lights not working Lights not working Lights not working Lights not working Lights not working Lights not working Lights not working Lights not working
Lights not working Lights not working
Lights not working
Go Back  Xtreme Visual Basic Talk > > > > Lights not working


Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2006, 01:40 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Unhappy Lights not working


So, I've read pretty much everything there is about DirectX9 Lights, which is not alot. I've tried to Copy-Convert-Paste the code made by Microsoft in C# to VB2005 .NET. Nothing works, except for the ambient value. I've seen that some (not all) C# exaples use effect files for drawing the light but surely there is a better way to do this?! I tried creating a Vertex Shader earlier today but guessing with is supposed to be passed to the shader in that Integer array is impossible . I guess the shader would be the solution to this problem.

I know this is a quite big request but could anyone who has successfully managed to get any of the 3 light types to work copy paste the code here in Visual Basic for me, please? Oh and, some help on those shaders would be nice.

My latest attempt on this, also not working, can be seen below. This setting is set OnResetDevice which is called once, just after the device is created. I've also tried all my ideas in the main render loop like it was done in one of the Microsoft examples, this does not change anything however.

Code:
            With D3D_Device.Lights(0)
                .Type = Direct3D.LightType.Directional
                .Diffuse = Color.Green
                .Direction = New Vector3(0, -1, 0)
                .Range = 1000
                .Enabled = True
                .Update()
            End With
...help...

Last edited by ShadowWolf; 06-21-2006 at 05:07 AM.
Reply With Quote
  #2  
Old 06-21-2006, 01:13 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Have you set the Lighting renderstate to true?
__________________
Cheers
Reply With Quote
  #3  
Old 06-21-2006, 04:37 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
Have you set the Lighting renderstate to true?
Unfortunately yes

Edit: renderstates beeing set (immediately after device creation):

Code:
D3D_Device.RenderState.ZBufferEnable = True
D3D_Device.RenderState.CullMode = Direct3D.Cull.CounterClockwise 'Direct3D.Cull.None
D3D_Device.RenderState.Lighting = True
D3D_Device.RenderState.Ambient = System.Drawing.Color.FromArgb(0, 128, 128, 128)

Last edited by ShadowWolf; 06-21-2006 at 04:51 AM.
Reply With Quote
  #4  
Old 06-21-2006, 04:54 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Have you got your object in the position that the light is pointing?
__________________
Cheers
Reply With Quote
  #5  
Old 06-21-2006, 05:03 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
Have you got your object in the position that the light is pointing?
I have built a room without a ceiling, the floor, and walls are all meshes (for a reason) and afaik New Vector(0,-1,0) is down, well actually I have been trying all kinds of random values on that vector and none seem to be casting light in any direction.

PS. I updated the light code in the first post a bit, I think the current one is more likely to work.

A picture of my room:
Attached Images
File Type: png let_there_be_light.png (153.2 KB, 18 views)
Reply With Quote
  #6  
Old 06-21-2006, 05:07 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

And you say you've tried the Directional light?

Have you assigned materials to the meshes?
__________________
Cheers
Reply With Quote
  #7  
Old 06-21-2006, 05:09 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
And you say you've tried the Directional light?

Have you assigned materials to the meshes?
Yeah Directional light code is now in the top post, I figured that one is more likely to work than my desperate Point light code. Here is the mesh texture loading code:

Code:
        
For I = 0 To Materials.Length - 1
   D3D_Wall_Textures(I) = Direct3D.TextureLoader.FromFile(Dev, "textures\" & Materials(I).TextureFilename, 64, 128, 1, 0, Direct3D.Format.R8G8B8, Direct3D.Pool.Managed, Direct3D.Filter.None, Direct3D.Filter.None, 0)
   D3D_Wall_Materials(I) = Materials(I).Material3D
   D3D_Wall_Materials(I).Ambient = D3D_Wall_Materials(I).Diffuse
Next
Reply With Quote
  #8  
Old 06-21-2006, 05:13 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Is there any chance that you could post the code and I can help you out quicker.
__________________
Cheers
Reply With Quote
  #9  
Old 06-21-2006, 05:16 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
Is there any chance that you could post the code and I can help you out quicker.
I will have a link for you to my personal server in a moment. Thanks for your help and time ardman.
Reply With Quote
  #10  
Old 06-21-2006, 07:34 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Right, I sorted it.
Code:
Dim testlight As New Microsoft.DirectX.Direct3D.Light

With testlight
    .Type = Direct3D.LightType.Point
    .Specular = Color.Green
    .Diffuse = Color.Green
    .Ambient = Color.Green
    .Position = New Vector3(0, 10, 0)
    .Direction = New Vector3(0, -1, 0)
    .Range = 50
End With

D3D_Device.Lights(0).FromLight(testlight)
D3D_Device.Lights(0).Enabled = True
D3D_Device.Lights(0).Update()
Viola! You'll have a green square on your floor.
__________________
Cheers
Reply With Quote
  #11  
Old 06-21-2006, 07:36 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

You don't have to add the Specular. I was playing around with the lights. If you want a spot light, you'll need to add the InnerConeAngle and the OuterConeAngle and the light will still work. You can have some great fun with this as you could code the light swinging etc. :-)
__________________
Cheers
Reply With Quote
  #12  
Old 06-21-2006, 08:48 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
You don't have to add the Specular. I was playing around with the lights. If you want a spot light, you'll need to add the InnerConeAngle and the OuterConeAngle and the light will still work. You can have some great fun with this as you could code the light swinging etc. :-)
I can't believe I haven't seen that FromLight sub but umm, sorry to spoil the fun... no light here. Are you sure you didn't change anything else? I'll keep experimenting with this method but so far there is no light.
Reply With Quote
  #13  
Old 06-21-2006, 10:57 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Talking It's working

Quote:
Originally Posted by ShadowWolf
I can't believe I haven't seen that FromLight sub but umm, sorry to spoil the fun... no light here. Are you sure you didn't change anything else? I'll keep experimenting with this method but so far there is no light.
I know double posting on some forums are fobidden/not encouraged but this one requires it! I've managed to get lights to work perfectly! This is what I did:

I did not touch the code, instead I installed the most recent DXSDK available and used the dlls in that sdk instead. It turns out the dlls had the same version numbers as the old ones I used but now it works! I hope this helps others in trouble too.
Reply With Quote
  #14  
Old 06-21-2006, 11:14 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Was that with your old code or the revised code?
__________________
Cheers
Reply With Quote
  #15  
Old 06-21-2006, 11:25 AM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by ardman
Was that with your old code or the revised code?
Slightly modified one, but nothing major, I know it was the sdk that did it. Since I did not update the code while installing the new sdk. All I did after the install was change the dll file references and run the program and I had a green light.
Reply With Quote
  #16  
Old 06-21-2006, 01:36 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Angry Turns out it's not working.

After doing some tests it turns out it's not working. Basically all that changed was that the ambient light is no longer taken from this line:
Code:
Dev.RenderState.Ambient = System.Drawing.Color.FromArgb(0, 100, 100, 100)
But from this line (from DirectX.Direct3D.Light):
Code:
D3D_Light.Ambient = Color.FromArgb(0, 255, 255, 255)
So help is still wanted, and any ideas are welcome.
Reply With Quote
  #17  
Old 06-21-2006, 03:26 PM
Moohasha's Avatar
Moohasha Moohasha is offline
Centurion
 
Join Date: Nov 2004
Location: Texas
Posts: 165
Default

Is there any chance your normals may be screwed up? Your lighting may work perfectly, but if your normals aren't right, you'll get messy results. Two things:

1.) Since you're loading a mesh, check whatever app you used to make the mesh to make sure the normals are correct. In fact, you can load the mesh in the DX Mesh Viewer and check the normals.

2.) If you're scaling the objects at all, it also scales the normals and that can throw things off. You have to normalize the normals after any scaling.

Just a thought.
__________________
"The whole trouble comes from the fact that there is so much tinkering with software. It is not made in a clean fabrication process, which it should be. What we need, is software engineering." — F.L. Bauer, 1968
Reply With Quote
  #18  
Old 06-21-2006, 03:47 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Quote:
Originally Posted by Moohasha
Is there any chance your normals may be screwed up? Your lighting may work perfectly, but if your normals aren't right, you'll get messy results. Two things:

1.) Since you're loading a mesh, check whatever app you used to make the mesh to make sure the normals are correct. In fact, you can load the mesh in the DX Mesh Viewer and check the normals.

2.) If you're scaling the objects at all, it also scales the normals and that can throw things off. You have to normalize the normals after any scaling.

Just a thought.
1) Well here is something interresting. DirectX Viewer (DX Mesh Viewer) says "Normals do not exist on mesh. Attempting to calculate.". Afaik a normal is the direction in which the, I guess it's called a plane, is pointing. Obviously I'm wrong since all my textures are drawn correctly on the mesh. I'll look up some stuff on normals and try to repair this problem. Thanks for the info.

2) No scaling is applied.
Reply With Quote
  #19  
Old 06-21-2006, 04:27 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Talking This might be it

Once again I double post but once again it looks promising, this time more than last time. I actually got some signs of light on my textures now! This page helped alot:

http://www.gamedev.net/community/for...opic_id=345454

I'll keep playing with this for a while and see what I can create. Thanks alot, this has restored my will and strength to work on this!
Reply With Quote
  #20  
Old 06-22-2006, 12:55 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Interesting you say that my code didn't work. Here is the initialise function:

Code:
        Try
            Base.Show()

            D3D_Device = New Direct3D.Device(0, Direct3D.DeviceType.Hardware, Base.Handle, Direct3D.CreateFlags.SoftwareVertexProcessing, D3D_PP)

            D3D_Device.RenderState.ZBufferEnable = True
            D3D_Device.RenderState.CullMode = Direct3D.Cull.CounterClockwise 'Direct3D.Cull.None
            D3D_Device.RenderState.Lighting = True
            D3D_Device.RenderState.Ambient = System.Drawing.Color.FromArgb(0, 128, 128, 128)

            Dim testlight As New Microsoft.DirectX.Direct3D.Light

            With testlight
                .Type = Direct3D.LightType.Spot
                '.Specular = Color.Green
                .InnerConeAngle = 0.0F
                .OuterConeAngle = 10.0F
                .Diffuse = Color.Green
                .Ambient = Color.Green
                .Position = New Vector3(0, 10, 0)
                .Direction = New Vector3(0, -1, 0)
                .Range = 50
            End With

            D3D_Device.Lights(0).FromLight(testlight)
            D3D_Device.Lights(0).Enabled = True
            D3D_Device.Lights(0).Update()

            BuildWall(D3D_Device)
            BuildFloor(D3D_Device)
            BuildObjects(D3D_Device)

            D3D_Device.Transform.World = Matrix.Identity
            D3D_Device.Transform.View = Matrix.LookAtLH(New Vector3(D3D_CameraX, 200, D3D_CameraZ), New Vector3(D3D_CameraFocusX, 0, D3D_CameraFocusZ), New Vector3(0, 1, 0))
            D3D_Device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, 4 / 3, 1, 1000)

            D3D_Font_Sprite = New Direct3D.Sprite(D3D_Device)
            D3D_InfoFont = New Direct3D.Font(D3D_Device, New System.Drawing.Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Pixel, 0))
            D3D_InfoFont_Bold = New Direct3D.Font(D3D_Device, New System.Drawing.Font("Tahoma", 8, FontStyle.Bold, GraphicsUnit.Pixel, 0))

            mInitialized = True
            Return True
        Catch a As Exception
            ex = a
            Return False
        End Try
And this produced the attached screenshot.
Attached Images
File Type: bmp room.bmp (1.47 MB, 16 views)
__________________
Cheers
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Lights not working
Lights not working
Lights not working Lights not working
Lights not working
Lights not working
Lights not working Lights not working Lights not working Lights not working Lights not working Lights not working Lights not working
Lights not working
Lights not working
 
Lights not working
Lights not working
 
-->