?
Solved

DirectX8 lighting looking bad...

Posted on 2003-03-11
8
Medium Priority
?
299 Views
Last Modified: 2013-12-08
here's what it looks like:
http://serialcoders.sytes.net/light.jpg

here's the wired version
http://serialcoders.sytes.net/wired.jpg

here's the lit wired version so that you may see my geometry easier
http://serialcoders.sytes.net/litwire.jpg

I used to be using a triangle strip where you have a single diagonal line through the middle of each square.  Now I'm using a triangle list to specify each of those triangles.  Made no difference to the look of things.  Each square is 200x200 units.  The light is a POINT light with a range of 100 and is positioned above the middle vertex (between the grid and camera).  I've tried different distances, like 1 to 100 away from the point, but the light remains unchanged.  Attenuation0 is 0.  Attenuation1 is 0.01.  Attenuation2 is 0.

If you want to see certain chunks of the code, ask.

The problem should be pretty obvious.  I have no idea why I've got that ugly outlining of different lines - you know, how the lines appear brighter.  Also, I have no idea why the light is elongated and not semi-circular or squared.  Also, I have no idea why the light effect doesn't shrink when I make the light's position farther from the grid (toward the camera).

Why is it acting this way, and how do I make it look smooth?

(I'm doing this project in Visual Basic, however, if you post code in C, I'll be able to read it just fine)
0
Comment
Question by:SilentRage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:joachimc
ID: 8126044
Are you refering to the gradiant you get? Are you using 32 bit color ? if you use 16 bit color that might not be enough.
0
 
LVL 1

Author Comment

by:SilentRage
ID: 8130702
I'm using 32 bit color.  I don't mind if the gradient is kinda rough.  But you can see the white lines along the geometry lines.  All but two of them anyway.  For some reason the light is elongated.  Notice that the light in the "wired" version is evently distributed on all geometry lines.
0
 
LVL 4

Expert Comment

by:joachimc
ID: 8134611
It seems to me that you are not creating the triangles as you think. Try creating every other triangle with different vertex colors so you see that they are placed correctly.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 1

Author Comment

by:SilentRage
ID: 8138361
the triangles are not lit.  They have a XYZ position, a XYZ normal, and a TEX1.  The lighting and materials provide colors and lighting.
0
 
LVL 4

Expert Comment

by:joachimc
ID: 8141682
I am aware of that. The reason for giving them colors are that you can see that they are drawn in the way you want them. So you don't have problems with winding order etc.
0
 
LVL 1

Author Comment

by:SilentRage
ID: 8142539
If you look above you can see that they are drawn the right way in the wired and litwired images.  I have also drawn the triangles one at a time during testing and they are indeed drawn the right way.  Additionally, I know the NORMALS are correct otherwise I wouldn't be able to see the light period.  I know they ARE drawn clockwise, cause then they'd get CULLED if they were (CULL_CCW is enabled).

Also,  I'm using a triangle list so that I have manual control over what order each point is rendered.  I know the geometry is drawn exactly like I designed it.  Here's code:

Dim Platform(99) As CUSTOMVERTEX   '100 points in the grid
Dim Indices(971) As Integer        '972 indices

    'Set the Normal facing down
    Normal = XYZ(0, -1, 0)

    'Draw the grid on the Y plane at 200.
    For Z = 1000 To -800 Step -200
        For X = -1000 To 800 Step 200
            Platform(I) = CreateVertex(X, 200, Z, Normal, 0, 0)
            I = I + 1
        Next
    Next

    Set Ceiling = DX8.Device.CreateVertexBuffer(D3DFVF_CUSTOMSIZE * 100, D3DUSAGE_WRITEONLY, D3DFVF_CUSTOM, D3DPOOL_DEFAULT)
    D3DVertexBuffer8SetData Ceiling, 0, D3DFVF_CUSTOMSIZE * 100, 0, Platform(0)

    'Grid is 9x9 squares
    'Each square has 4 triangles
    'Each triangle is drawn clockwise
    'Each triangle has 3 points
    'Each square has 12 points
    'Each row has 9 squares (0-8)

    I = 0
    'Y loops us from the top row to the bottom row
    'Y is the indice index of the upper left corner of the first square on this row
    For Z = 0 To 80 Step 10
        'X loops us from left to right along the Y row
        'X is the upper left of each square on this row
        'In this loop we draw the 4 triangles of the square
        For X = 0 To 8
            'Forward Right
            Indices(I) = Z + X + 1
            'Forward Left
            Indices(I + 1) = Z + X
            'Back Right
            Indices(I + 2) = Z + 10 + X + 1

            'Forward Left
            Indices(I + 3) = Z + X
            'Back Left
            Indices(I + 4) = Z + 10 + X
            'Back Right
            Indices(I + 5) = Z + 10 + X + 1
           
            'Forward Right
            Indices(I + 6) = Z + X + 1
            'Back Left
            Indices(I + 7) = Z + 10 + X
            'Back Right
            Indices(I + 8) = Z + 10 + X + 1

            'Forward Right
            Indices(I + 9) = Z + X + 1
            'Forward Left
            Indices(I + 10) = Z + X
            'Back Left
            Indices(I + 11) = Z + 10 + X
            I = I + 12
        Next
    Next

    Set CIBuffer = DX8.Device.CreateIndexBuffer(1944, 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT)
    D3DIndexBuffer8SetData CIBuffer, 0, 1944, 0, Indices(0)

If you are unable to understand this code, that's ok.  Cause you don't have to understand it to know it works.  My wired and litwired images in my first post showed you that the geometry was drawn.
0
 
LVL 1

Author Comment

by:SilentRage
ID: 8146255
Well, I think I found my problem with conversations with other people.  First, the reason the light was elongated is for two reasons.  It seems that by drawing 2 triangles on top of the other 2 triangles, the light only lit the vertices of the second pair of triangles.  Now, if I didn't draw the first or second pair of triangles, I can get the same light for more efficiency.  Then, to make it not elongated, and smoother looking, all I could do was increase the resolution (or density or tesselation).  Another solution is as copied from a post in another board:

"You could also look into using per-pixel lighting as another drawing method, but beware of the fact that only cards with DX7+ DDIs will be able to run your game with per-pixel lighting using either DOT3 on older cards or a pixel shader on newer ones."

I'll try to get this question PAQ'd and my points redeemed.
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8147670
PAQ'd and all 125 points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question