?
Solved

DirectX8 lighting looking bad...

Posted on 2003-03-11
8
Medium Priority
?
312 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

612 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