Lighting and Rendering

I am just learning DirectX in C#, I have been through many tutorials on the net, gaining a bit from each one, but I can't get the rendering quailty right. I'm sure there is just some little property setting somewhere, but I can't find it.

I'm trying to render a simple teapot- right now, it looks like this:

http://www.magentastudios.com/cp/teapot.jpg

here is the code:

http://www.magentastudios.com/cp/teapot.txt

I'm using C# 2005 Express, DirectX 9 December 2005, A good Vaio PC.

What am I doing wrong :)




Answer this question

Lighting and Rendering

  • Brian Keller


    try to replace this :

    device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI/4,this.Width/this.Height,0f,50f);

    By this:

    device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI/4,this.Width/this.Height,2f,50f);

    So you don't use 0 for the near plan...

    it the distance of the near plan and far plan that you define at the end of this...


  • Pradeep K

    Looks like your teapot aint normalized correctly.

    Try loading the teapot mesh file instead (<DXSDK>\samples\media\misc\teapot.x)


  • DaveWadd

    I'm not sure I get what you are saying- if you mean changing this:

    device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI/4,this.Width/this.Height,0f,200f);

    to:

    device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI/4,this.Width/this.Height,0f,50f);

    I tried that, no change.

    Plus, this is not a huge mesh object- it's as simple as something can get and still be 3D.



  • Deskman

    Are you saying that the built-in teapot mesh object is defective

    I have also tried the box and sphere, and they have similar problems.

    I would rather not load mesh files, since what I will be creating will have a simple CSG look to it.

     I have made edits, reflected in both the code and screen sample linked in the first post.

    It looks beter, but there are still random problem polygons- which polygons are blacked out varies each time the screen is drawn. When you move around with the keyboard the whole thing flashes.

    Does anyone else have any suggestions I would think with a simple program like this, and a simple requested output, there should be a simple solution out there.



  • Ben Westbrook - MSFT

    I think I know what may cause your problem,

    It might be your Projection matrix

    If you have too much distance in your Projection Matrix and you try to render
    a huge mesh the mesh will be ''Rolling over'' in the Depth Matrix
    And you will get this strange effect

    Basicly the value in the Buffer go over the value and draw on a bad depth

    If you see an effect that is like an invisible wall
    that modify the vertex as it move into your object you have the same problem I had

    I see in your teapot this series of black triangle that happen to be in front
    has if a cut off wall was messing with everything that is at that depth...
    if you move around this cut off wall (and you may have more then one roll over)
    will modify the mesh parallele to your screen

    I was using a Projection matrix that used very close to 0 to very far away
    Thinking I could prevent the closer object to cut in front of my view
    Everything was good if the object was simple but for huge mesh object
    I was having very strange output like you get

    I'm pretty sure your problem is in the projection view
    Try to use the projection value they give in the sample
    or some other people Proj matrix value that you know render big mesh
    When I put the same value they give my problem completely disapear

    the near plan should not be 0, and the far plan should not be too far
    in fact If I remember those value should some proportion of the screen


  • DaweiHuang

    I got it now!

    The problem was the near, not the far:

    device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI/4,this.Width/this.Height,1f,50f);

    It does not like zero!

    Thank You!



  • Lighting and Rendering