Skip to main content.
December 8th, 2006

I must be stupid, stupid, stupid.

I’ve been fiddling with 3D with the goal of implementing Shadow Mapping for almost a month now.
I spent quite a bit of time around the engine, ironing things, getting it ready to quickly plug-in shaders.. and now I’ve been stuck on the facking Shadow Mapping for several days !
In theory it’s nothing special, in practice 3D graphics sometimes really sucks !
The problem is that there is a general concept, a lot of half-assed implementations, many ambiguous discussions on the net, a million papers and books that focus on different details. But no real complete reference. This is for Shadow Mapping but also for many other things.

The main issue with 3D graphics is that one works with transformation matrices and different 3D spaces. Matrix manipulation is not that difficult, but millions of ambiguities raise with coordinate systems, order of concatenation, inversion of matrices… plus the fact that shaders are hard to impossible to debug.
Doing an actual implementation is a royal pain in the ass, and it’s especially sad that I tend to try solve by trial and error. Flip matrices, swap orders, try to do something like some reference implementation does… but never actually really being sure what details am I missing.
For example I saw some code arbitrarily adding w to (x,y,z) to the light-view homogeneous space vertex after being transformed in a shader. Why ?! Why the fuck ?!  ..nobody knows, there is no telling. It’s something that needs to be done because of the specific situation.
I hate feeling stupid and fiddling for hours with parameters. Trying to grow a working implementation out of web-searches.
It doesn’t help that I still don’t have a credit card to buy English books via Internet, and the best library with English books I knew here in Tokyo seems to have given up on carrying the good coding books. Of course one can find a lot of shit on how to use Office and code in Perl and Ruby.. but who the fuck needs those ?! I need my 3D books !!!
…but I also know that to get something to work one needs about 10 books treating the same subject. That has always been the case, but more so now that there are tons of Game Programming Gems, GPU Gems, ShaderX. All written by hundreds of people.

If everyone is so good, why can’t I find a decent explanation on-line ?!

zzzzzzzzzzzzzzzz

Posted by Davide Pasca in Programming, 3D Graphics

This entry was posted on Friday, December 8th, 2006 at 1:54 am and is filed under Programming, 3D Graphics. You can follow any responses to this entry through the comments RSS 2.0 feed. You can leave a response, or trackback from your own site.

11 Responses to “I must be stupid, stupid, stupid.”

  1. rince says:

    I find that a good source of reliable and easy to understand information is from nvidia, ati or directx documentation and samples. What exactly are you looking for, maybe I can point you at a sample?

    Also shader debugging seems to have gotten better. On PC and 360 you can use PIX or you can debug shaders in source asm or HLSL, on PS3 there is no for of shader debugging yet unfortunately…

  2. Davide Pasca says:

    nVidia documentation can’t give the damn formula for tex2dproj() ..what does it do ?!
    The CG reference doesn’t have it ! The CG User Manual says it does project, also mentions some swizzling, what does it mean ? Do I have to specify .xyw ? It’s it already assumed to be that way ?
    Does tex2dproj() really output x/w, y/w, z/w ?

    That’s only an example.. I’m using a mathematical function and I don’t have the facking formula for it !!
    How hard is it to put the formula in the documentation ?? It should be all over the places, but instead it’s a mission do find that simple vital information.

    I don’t want to do trial and error forever, I want to know what I’m doing !!!

    Fuck ATI and nVidia !!!

  3. duddie says:

    So we expected shady story and instead we are being served with some 3D… disappointment !!!!

  4. Davide Pasca says:

    Sorry Duddie !

    I promised a shady story, but first I need to focus on my shadow story (ah ah).

    BTW, things good a good turn as I figured my shadow map projection matrix was being loaded improperly.

    I was using:

    cgGLSetMatrixParameterfr( mat_param, mat._m[0] );

    ..in place of..

    cgGLSetMatrixParameterfc( mat_param, mat._m[0] );

    Because I use the OpenGL format of matrices, I was mistakenly loading the matrix as a row-matrix, but it should have been as a column-matrix.

    And here comes facking OpenGL too !! I can’t believe the standard tells people to think column matrices but to store row matrices ! ..in a one dimensional array, nonetheless.
    This has had so much negative repercussion, especially when one considers that there is then Direct3D that tells you to think row matrices and store them that way.

  5. rince says:

    Maybe opengl sucks?

    Seems to me like I would render the scene from the lights perspective into z only texture (shadow map). Set that texture on one of the texture stages. Then render the scene from cameras perspective and also for each vertex calculate their shadow map u,v and z in light space. This could be done by transforming the vertex by the light space draw matrix and then normalizing the x,y to 0..1 range to get the uvs Then I would pass the calculated shadow map uv’s and light space z to the pixel shader. In the pixel shader I would use the shadow map uv’s to look up the z value from the shadow map and compare it to the light space z value that i am passing down to determine if the pixel is in shadow or not?

  6. Davide Pasca says:

    Mr. Rince…

    I agree, maybe OpenGL sucks.. but your answer doesn’t make sense.
    My complaint is about how things are not explained anywhere in detail, and you just explained the theory again 8)

    With OpenGL was also pretty difficult to get the Z buffer allocated right with the Framebuffer Objects thing. Bind this, attach that.. bha !

  7. rince says:

    Well if I know the theory and the maths implementation details never seem to stop me.

    What is your actual problem? Is opengl interface too convoluted for you to figure out how to implement what you want?

  8. Davide Pasca says:

    ummmmm I was trying to convey the idea that programming, implementing techniques is a pain because there are many unknowns and there is hardly a sure well defined portable way to do things. I think Mark Kilgard through nVidia released a detailed paper about stencil shadows, but there is no such thing for shadow maps. However, even for stencil shadows, there is the problem of the edges revealing themselves (actual geometry vs shading) which doesn’t seem to concern most explanations, but is a real problem in the implementations (a couple of possible solutions came out in the recent years).

    Writing code is not math, although having the math behind is important. Being a programmer myself, I know that I’m not going to stopped, however I’m frustrated by the lack of actual specific documentation. And in some cases one is supposed to read tons of bullshit (for example the OpenGL extension documentation, which includes some sort of log of decisions along with the specification).

    Currently I’m dealing with the GL_COMPARE_R_TO_TEXTURE_ARB texture parameter. This should magically enable tex2dproj() to do a Z compare between the current position’s Z and the depth texture’s Z.
    To debug, it would be a great start to have the plain formula used by tex2dproj(), but that isn’t available in the standard CG documentation..

    I shouldn’t be telling you about implementation issues. If you have no problems then you are not earning your pay ;)

  9. rince says:

    Well for once I am not relying on opengl to do ‘magic enabling’ for me =)

    I choose interfaces that let me see and control what I am doing =)

    So I do still have problems, but they are of a different nature. =)

  10. Davide Pasca says:

    I agree that OpenGL is confusing and obsolete. However I remember clearly I had some hard time trying to get FSAA going with Float 16 frame buffer on the XBox 360, which uses Direct3D, but also some custom tiled video RAM buffer.

    AA is a requirement for shipping titles, yet most samples don’t implement it (at least last I checked a few months back). Only a couple had FSAA going, but how to mix that with float buffers, etc, was not explained.
    I did it eventually, but it was definitely not straightforward.

  11. rince says:

    FSAA using multisampling or supersampling? Also in 1280×720 or 640×480?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>