Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Setting matrix constants for effects (fx)

Author
Message
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 29th Mar 2004 13:04
Hi all,

When setting constants for effects, which matrix parameters need to be set? For example when using a simple vertex lighting shader (with the lighting performed in view space) you would normally multiply the normal with the inverse transpose of the modelView matrix. When using Cg (in OpenGL at least) you need to explicitly set the matrix parameters, however I know that directx makes certain data available by default (such as the time, the model, view and projection matricies). Which matrix semantics are automatically set? The fx browser example seems to set all matrix parameters to the identity matrix (I'm not sure how this would work but I could just be being stupid ) Does anyone have a example of using effect files that sets the matrix parameters?

Thanks for any help

Darren.
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 29th Mar 2004 21:18 Edited at: 29th Mar 2004 21:26
you will need FX Composer (but i'm sure that's not a problem)
use this code and you'll see how it works in DBP.

raw code


optimised matrices


you'll notice the difference immediately
simple, no?
hope that answers your question.


Athlon64 FX-51 | 1.5Gb DDR2 PC3400 | GeForce FX 5900 Ultra 56.60 | DirectX9.1 SDK | Audigy2 | Windows XP 64-Bit
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 29th Mar 2004 22:10
Hi Raven,

I used FXComposer to create a simple vertex lighting shader for testing (code below).



I can set all of the constants fine (I just change the pixel shader to pass through the constant I am testing). However, all I get is a black sphere (this code runs fine in FXComposer) so I assume I am missing something. When I try and set the actual matricies manually I get a red shpere (flat shaded - no lighting) which is obviously not right.

My current code is below


Any ideas why this doesn't work?
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 29th Mar 2004 23:46
I've had a read of the DirectX documentation and it seems that the semantics can be anything you want. They are meant to provide an easy way for an application to set "known" values in each effect. So does anyone know the set of semantics DarkBasicPro uses for effects?

So far the values I know work are:
1. World
2. View
3. Projection
4. WorldViewProjection
5. ViewIT
6. WorldIT

The first 4 are pretty obvious, the last two seem to link to the inverse view and world matricies, but if IT denotes inverse what denotes inverse transpose?

Of course I could have all of this wrong Any help would be appreciated.
Neophyte
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 30th Mar 2004 03:43
There is code in the FX System under the Help Files to help determine if something is being supplied by DBPro or not though I think that your list right there is basically it.

The idenity matrix thing is just a default value sort of thing. There is nothing special about them(other than the fact that you can multiple them with other matricies and not change the result of the matrice. A bit like multiply by one really.)

IT denotes inverse transpose.

As for your code, I don't have the time to sift through it right now but I'll see if I can get the time later. Though off the top of my head I didn't see any code in their to position your light though I could have just skimmed over it without realizing it.
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 30th Mar 2004 15:04
Ok I fixed it. IT denotes Inverse so the full set of matricies is:

1. World
2. View
3. Projection
4. WorldIT
5. ViewIT
6. ProjectionIT (I am guessing at this one)

None of these should need to be set explicitly for the effect. To get the transpose of any of the above you need to set the matrix (or the inverse matrix) parameter and use "SET EFFECT TRANSPOSE" which will transpose all of the matricies explicitly sent to the effect.

So the working shader code is:


The only changes being setting the viewInverse constant to use the semantic ViewIT.

And the fixed DB code is:


Phew!

Neophyte:

I know what the identity matrix is, but the fx browser seems to be setting all matrix parameters to it, that shouldn't work - having the world, view and projection matricies as the identity will not transform anything! Of course I could be reading the code wrong (not really studied it).

The constant lightDir is being set (although it's not doing much right now, but that's a much simpler problem to solve).

Thanks for the help guys.

Darren
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 30th Mar 2004 16:38
Actually on top of the list above are the concatonated matricies:

7. ModelView
8. ModelViewProjection
9. ModelViewIT (guess)
10. ModelViewProjectionIT (guess)

I'm not sure if there are any more. If anyone knows the full set of semantics could they please post them (that includes any of the authors of DarkBasicPro )

Thanks,

Darren.
Neophyte
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 30th Mar 2004 20:30
@_Gouki_

"having the world, view and projection matricies as the identity will not transform anything!"

That's the point.

"To get the transpose of any of the above you need to set the matrix (or the inverse matrix) parameter and use "SET EFFECT TRANSPOSE" which will transpose all of the matricies explicitly sent to the effect."

You can also transpose them manually with the transpose matrix command as well. Or at least that is what I did when I didn't want to transpose all of my matrix data.

I'm also fairly positive that ViewIT means ViewInverseTranspose. I have a shader that requires ViewIT and I got it working by creating a view matrix, inverting it, and than transposing it through the DBPro 3dmath command set. The result looked identical to the one in FX Composer where the ViewInverseTranspose semantic was accepted.

Also, you don't have to set worldInverseTranspose through the effect constant commands. Just change its semantic from WorldInverseTranspose to WorldIT and DBPro will supply it. I think you know this already though because WorldIT is in your list at the top, but I just wanted to remind you so you don't accidentally have to do more work than is necessary.

I just tested your two guesses as well and ModelViewIT and ModelViewProjectionIT aren't supported by DBPro. Lee is aware of FX Composer and the document with it that is a rough draft of a proposed standard semantic list so hopefully we won't have to guess what works and what doesn't as he'll implement all of the semantics listed.

If you want a complete list though you'll probably have to email lee though I've asked before and I've yet to get a response. If you can get a response could you post in this thread what they are? It would be greatly appreciated and would save a lot of time on everyone's part. Thanks. And good luck with your shaders.
_Gouki_
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 31st Mar 2004 00:20
Neophyte:

Thanks for the reply.

Ah! I think it just clicked. The identity is set to reset any transformations on each effect load. Doh! Should have worked that one out earlier

I stand corrected IT does in fact denote inverse transpose. I messed about some more with the shader and I noticed it was getting the world eye position from the matrix. The param name is viewInverse (set by FXComposer not me) but only the inverse transpose seems to work!

When I get a change I'll see if I can work out the inverse semantic (at a guess either I or Inv).

As for the "known" semantics we have:

1. World
2. View
3. Projection
4. WorldIT
5. ViewIT
6. ProjectionIT (Still a guess)
7. WorldView
8. WorldViewProjection

The working shader code is now:


And the DB code is:



Any more info would be greatly appreciated - I will post anything else I find out here.

Thanks for all the help Neophyte

Darren.

Login to post a reply

Server time is: 2025-05-29 05:59:05
Your offset time is: 2025-05-29 05:59:05