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 / The Ultimate Shader Thread.

Author
Message
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 27th Apr 2004 13:24
Neo there is a reason why I am paid to develop these...



If you weren't such an a**hole to me all the time I would explain how I have done it. But quite frankly I really don't like you after how you attacked me in several threads, so :-P


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5700 60.18 | DirectX 9.0b | CMedia 8620 | Windows XP Professional
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 27th Apr 2004 21:12
Yeah, right. That isn't going to fool me Raven. Unless, you post some code I'm not going to buy into that photoshop job of yours. I remember the fact that you are an artist.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 28th Apr 2004 03:10
fine... i was going to put it all into a media exe; but for some reason they never included any sodding media.
so i'm getting one of the guys in the IRC room to take a screenshot of it working.

they can post up with a working version.
i'm currently working on a simple explaination or the work around I have done as well.

because atm 'string function = "funcName";' does not work. As I said before, that isn't the only way to do the texture though, you have to use ASM and actually get your hands dirty.

you want to see a good example of this lookin the bump.fx in the effect folder. show's how even Lee has hacked his way around this bug. (so it isn't as if it wasn't known about)
what is more annoying about this all is that firstly it isn't documented, and secondly the function call is encoded.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5700 60.18 | DirectX 9.0b | CMedia 8620 | Windows XP Professional
ZKAT8IT
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location:
Posted: 28th Apr 2004 03:37
Raven didn't photoshop that, he sent me the exe with the media and I ran it. I have the same result and here's a screenshot of it.

Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 28th Apr 2004 04:29
@Raven

"fine... i was going to put it all into a media exe; but for some reason they never included any sodding media"

Who didn't include any media? You've lost me there.

"i'm currently working on a simple explaination or the work around I have done as well."

Just post the sodding code. I don't need an explaination.

"you want to see a good example of this lookin the bump.fx in the effect folder."

I didn't see any function calls or procedural textures being made in that fx file. Here is the source, point out where I'm wrong:


"what is more annoying about this all is that firstly it isn't documented, and secondly the function call is encoded."

I'll agree with you on the first point but what do you mean by "encoded"?

@ZKAT8IT

"he sent me the exe with the media and I ran it. "

That doesn't mean jack. There are at least two other ways that he could have faked the function call with a .exe and one of them was outlined in this very thread.

The outlined one is what Ideajuice said eariler about saving the generated texture in the preview panel in FX Composer and loading the texture in through the fx file manually. The texture isn't being generated manually its precalculated basically.

The second one would be him inlining the function into the effect which wouldn't prove me wrong at all. I sent in a bug report about the functions not getting called and he claimed that they could be. I've yet to see some hard evidence from him that he can call functions.

There is a reason that he is stalling and not posting any code and that is because he can't do it. Any code he would post would reveal him to be a lair. Plain and simple.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 28th Apr 2004 05:20
I'm not going to help you solve this.
First you accuse me of Photoshop-ing this, now someone else has run it you say it's faked another way...

Hell you've accused me twice of cheating here, why the hell should I help you? You want to figure this out you can kiss my ass.
I've given you more than enough help than you deserve.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5700 60.18 | DirectX 9.0b | CMedia 8620 | Windows XP Professional
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 29th Apr 2004 07:42
@Raven

Thanks for confirming my suspicions.

Anyway, thought you might be interested in hearing this:
Quote: "
Hi,


I have moved this email to the U6 bugs area. I suspect the shader is trying to use a procedural texture or some on the fly texture area, which I have not coded support for in U5. It will be in for U6 though. Will feedback more on this when I encounter your email again (during U6 debugging). Best to stick with shaders that use existing textures and play with those aspects while you wait



Best Regards,
Lee.
"

It was in response to the bug report that I sent in a few days ago concerning this very topic. Believe it, or don't. I don't really care. But I now know for a fact that procedural textures are not supported in U5.

@Everyone else

Anyone else interested in using procedural textures should be advised that you are gonna have to wait for U6 before support is coded in. Ideajuice's work around will help get around this current limitation for the time being.
AI666
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location:
Posted: 29th Apr 2004 08:01 Edited at: 29th Apr 2004 08:06
I'm really sorry to say, and I don't know if anyone else will agree with me on this point, but this is really getting boring and useless.

This is supposed to be a technical thread about shaders. It can be really useful to people who are totally lost in the .FX universe. Because of that, it is situated at the top of the list of threads.

It is really a shame you are turning this into a "who got the biggest shaded balls" thread. Grow up.

@Neophyte
Keep on the good work.

Cheers,
AI
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 29th Apr 2004 08:29
@AI666

"This is supposed to be a technical thread about shaders. It can be really useful to people who are totally lost in the .FX universe. Because of that, it is situated at the top of the list of threads.

It is really a shame you are turning this into a "who got the biggest shaded balls" thread. Grow up."

I'd like it to remain a technical thread as that was my original intention. Hopefully, Raven will stop picking fights with me and things can get back on track.

"Keep on the good work."

Thanks. Hopefully, within the next two days I'll have part II of my fx system tutorial up.
AI666
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location:
Posted: 29th Apr 2004 14:20
@Neophyte

My advice (only if you wish to accept it): just ignore. Answer questions of those who want to learn about technical issues. Don't waste time, energy and server space on constructing killer-arguments that proves the nitpicker wrong.

Let us just declare Raven as the with the biggest shaded balls around (photos included above as unrefutable evidence) and just get on with it

Cheers,
AI
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 29th Apr 2004 14:47
AI666 i was never bothered with keeping this civil, i posted information... it wasn't directed at anyone it was just pure information i didn't even say anything in the post; and as a result Neophyte attacked my post quite viciously, he also did this in another thread.

Surely I had a right to try and defend myself, no?

Neo, I do believe I said that a number of posts back... and that you HAD to use ASM to get around it. I even gave you an example of how Lee himself had coded a work around for you to give me a blank faced expression.
Believe me, I have had numerous conversations with Lee about the limitations in HLSL and ASM; It is thanks to alot of bugs I uncovered in ASM that the support is now close to flawless allowing you to code the Procedual texture work around. :p

Honestly this thread is pretty useless; because as I've mentioned before Neo is expecting you to understand the basics about shaders before developing them.
Before you touch ANY code you should understand what the Matricies are and why you use them, which requires NO code... infact it would require a few technical drawings using something as a reference object.
Else how else are you going to understand how to edit within the world/view/projection/identity spaces?

I know for a fact that most people trying top get into shaders have no idea of the mathematics behind using Matrix4's and Vectors.
Really this is REQUIRED before you can hope to create shaders, else you will just end up having to copy other peoples without ever understanding what is happening.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5700 60.18 | DirectX 9.0b | CMedia 8620 | Windows XP Professional
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 30th Apr 2004 00:07 Edited at: 30th Apr 2004 00:09
Well... for one, Keep up the good work Neophyte. Your tutorial was really helpful.

I do agree with AI666 to a degree. This thread is really going downhill. However, Raven is also quite right. So far, all neophyte has done for us is explain how to get fx files to work with darkbasic. Not that that's a bad thing, but we type in some code, without really understanding what it's doing. And that's not a good thing when you decide you want to make your own shader.

However, i'm hoping in the next tutorial Neophyte will go more into details with shaders, and teach us the core fundamentals. ^_^

So.... could you two please stop arguing, and just forget everything that has occurred in this thread? It'd be a great resource if completed. And not to attack Raven or anything, but instead of talking about how poor the tutorials are, he could contribute some as well.
AI666
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location:
Posted: 30th Apr 2004 00:32
@Final Epsilon
I totally agree.

Cheers,
AI
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 30th Apr 2004 02:22
@Raven

"AI666 i was never bothered with keeping this civil, i posted information..."

Which was false.

"Neo, I do believe I said that a number of posts back... and that you HAD to use ASM to get around it. "

You mean like this?
Quote: "
If you bothered to do some procedual texture tests, in both FX and ASM you'd understand alot more about the functionality in this area rather than bothering Lee.
"


That sounds like more of a personal attack than a suggestion.

"I even gave you an example of how Lee himself had coded a work around for you to give me a blank faced expression."

Blank faced expression? I didn't see any procedural textures being generated in the bump.fx shader and I challenged you to prove me wrong.

In response, you didn't say a word. I take it that means you can't. If you could it would take you ten seconds to cut and paste the part where he does generate a procedural texture in ASM. I even made it easy for you and posted the entire shader in my post so you could quickly quote from it. But you didn't. Why is that Raven?

"Believe me, I have had numerous conversations with Lee about the limitations in HLSL and ASM; It is thanks to alot of bugs I uncovered in ASM that the support is now close to flawless allowing you to code the Procedual texture work around. :p"

Yeah. Right.

You claim you can get around it in ASM but you are really tightlipped about revealing how. Its not like it would take you long. In fact, by the time you are done typing a reply to this you could have easily cut and pasted the part of the bump.fx shader where he generates a procedural texture.

But I know you won't. You don't know how to generate a procedural texture in ASM.

Of course, you'll probably come up with some cover story about how you don't want to "help" me, but we all know it is just hot air. I don't really care about procedural textures personally as I have other more interesting things I want to tinker with.

Pointing out where in the bump.fx lee worked around this issue wouldn't help me at all. It would help all of those who want to get procedural textures working, but you can't seem to bother to help them.

"Honestly this thread is pretty useless; because as I've mentioned before Neo is expecting you to understand the basics about shaders before developing them."

The point of my tutorial series so far is NOT about developing shaders. Its about getting existing ones to work in DBPro. NONE of my tutorials so far have dealt with creating shaders. If you think I'm wrong about that you can feel free to quote which tutorial I developed that dealt with this issue.

I'm also expecting NO ONE to know the basics. You can get shader to work in DBPro while having no clue whatsoever the difference between a world matrix and a projection matrix let alone what a matrix is. Knowing how they work is not essential to getting them to work in DBPro.

All you need to know is how to set constants and supply the required media. That's basically it. There are some lines of code you might need to change but they are few and far between. All the lines that need to be modified have been examined in detail and usually require changing a name to another name. You don't need to know what a matrix or a vector is to do that.

"Really this is REQUIRED before you can hope to create shaders, else you will just end up having to copy other peoples without ever understanding what is happening."

I'll agree with you here that understanding the basics is needed in order to create shaders. However, I'm not dealing with that subject yet. So your criticisms are invalid.

@AI666

"My advice (only if you wish to accept it): just ignore."

I'd like to but the problem is he is providing bad information. Since this is a technical thread its important that the facts get straightened out.

@Final Epsilon

"Well... for one, Keep up the good work Neophyte. Your tutorial was really helpful. "

Thank you.

"So far, all neophyte has done for us is explain how to get fx files to work with darkbasic. Not that that's a bad thing, but we type in some code, without really understanding what it's doing. "

Shader creation is a lengthy subject and I was saving it for a later date. My plan was first to show how to get shaders that someone else created working in DBPro. Then I'd go on to the more difficult subject of creating shaders which would also require the knowledge of how to get them to work in DBPro. I want to deal with the easy stuff first and then move on to the harder stuff.

If you want to move ahead here are a few more resources for you to look over. I don't have the time to go over them in detail unfortunately so I'm afraid you'll be on your on for the time being.

From issue 9 of the DBPro news letter:
[href]http://www.fairyengine.com/articles/hlsl2sided.htm [/href]

This one deals with pixel shaders, how to set them up in DirectX 8(not very useful for us) and the pixel shading asm language(useful for us). Note: I haven't had the time to go over how to integrate ASM shaders into the FX file system but it is really easy. For a good example of how check out the bump.fx shader that came with DBPro and that I posted above.
http://www.cfxweb.net/modules.php?name=News&file=article&sid=1305

This one is from Microsoft. Deals with HLSL and hemispherical lighting:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp

Here is a power point slide by Wolfgang Engel dealing with HLSL:
http://www.shaderx.com/direct3d.net/GDC2003/index.html

Here is another tutorial dealing with HLSL this time using RenderMonkey, a tool for developing shaders by ATI. Note: The .fx export for the current version of RenderMonkey is broken. Don't bother trying to export shaders from RenderMonkey because it would be quicker to create the .fx file by hand and paste your source into it than to have to modify the .fx file produced.
http://www.shaderx.com/direct3d.net/tutorials/RenderMonkey%20Movies/1Steps/RenderMonkey.htm

And to top it off, here is the page where I found the above two tutorials. It contains another four tutorials, Fundamentals of Vertex shaders, Programming Vertex Shaders, Fundamentals of Pixel Shaders, and Programming Pixel Shaders that might be of interest to you.
http://www.shaderx.com/direct3d.net/index.html

I hope these resources help. When I get the time I start up some introductory tutorials on writing shaders as well as some tutorials on developing your own lighting models.
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 30th Apr 2004 04:45 Edited at: 30th Apr 2004 04:46
^_^ thanks for the resource. However, i'm not that advanced yet... :-P I was just looking for a general idea for what i was typing in. heh.... Anyways.... I'm having trouble modifying the ocean shader. In the FX Composer, it looks really nifty, but i can't get it to look that way in DBP. Here's my source attached to this post. I copied all the settings exactly the way it was in FX composer, but for some reason, my vectors arn't working right. Help please?

note: Part of the source is raven's. :-P My original source code worked, but i didn't have inverting the matrix, and once he gave me his, i was too lazy to add the invert matrix to my own. So therefore, i'll give credit to him for the inverting matrix thingy.
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 30th Apr 2004 08:24 Edited at: 30th Apr 2004 08:55
@Final Epsilon

"However, i'm not that advanced yet... "

All of the links that I posted should deal with HLSL from an introductory point of view.

"In the FX Composer, it looks really nifty, but i can't get it to look that way in DBP. Here's my source attached to this post. I copied all the settings exactly the way it was in FX composer, but for some reason, my vectors arn't working right. Help please?"

I'll give it a try. However, my card doesn't support VS and PS 2.0. So whatever changes I've made I won't know for sure if it will work on your end or not. You'll have to test the changes yourself after I post my results.

Update:

There seems to be an array of type Wave that isn't being set. I'm not sure how you would go about setting that. In the shader each element of the array is set but DBPro doesn't recognize constants that are assigned a number for some reason.

I'd send this shader along with the source in to Lee as a bug report if I were you. I think arrays that are assigned numbers in the shader file ought to stay set in DBPro.

In the mean time, the only way you could probably get this to work is if you changed the Ocean shader so it didn't use a Wave array. That would take a bit of work though.
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 30th Apr 2004 15:55
Ocean seems to work ok. I don't remember having to change the shader itself (aside from changing resourcename to name), but the object you apply it to is important.

If you use a sphere, the effect will pinch together at the center and look wrong.

I had to use a plane divided into many sections to get it to look right.

If you try to use a squashed cube or sphere, it will turn inside out halfway through the effect and it will look like the effect starts scrolling backwards.

You didn't say what was wrong with the effect. You just said you couldn't get it to look the same way as it does in FX Composer. Perhaps if you try a tesselated plane....

E Unibus Plurum
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 30th Apr 2004 16:51
:: sighs :: sorry neo, but you have a serious problem and you need to sort it before you bother trying to teach people.

I don't write these tutorial things with good reason.
If you require help with them then ask me; else I'm going to leave people to figure it out on thier own.

However if anyone wants, I will draw up the explaination of the Matrices and how they work...

Ideajuice try ->this<-
it should look like this,


I know that I am not the only one to get these results as Darthster also got them, he also noticed the exact same bug I have with the Matrices that DBP has.

That is using a Sphere... that is the entire point in Inverting the View Matrix.

When you inverse the matrix what this does is basically flips it;
from:
[01,02,03,04]
[05,06,07,08]
[09,10,11,12]
[13,14,15,16]

to this:
[04,03,02,01]
[08,07,06,05]
[12,11,10,09]
[11,15,14,13]

Allows the view to flip whatever has been rendered on the Project Matrix (think of it as flipping normals, and what that does to a model's phong shading with culling off; it's almost the exact same deal)

when you Transpose a matrix the same thing happens really, only it is flipped from top-left to bottom-right so it's a flip on both axis rather than just one. As all of these positions are basically realtive floats from the 0,0 point in the world/identity matrix.
This is why the dramatic changes.

(for Shaders A Level math is REALLY a plus)


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5700 60.18 | DirectX 9.0b | CMedia 8620 | Windows XP Professional
_Gouki_
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: England
Posted: 30th Apr 2004 18:36 Edited at: 30th Apr 2004 18:41
Hi all,

Just a note on the Ocean Shader. The evaluateWave function uses the xz position of the vertex in it's calculation which means you need to be careful with the size of the mesh you use (add a new plane xz object in fx composer to see what I mean). A width/height of 100 works well (adjust tesselation to suit whatever you are doing obviously). Also the wave array values are set in the vertex shader, you should only need to pass in the waveFreq and waveAmp params.

Darren
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 30th Apr 2004 23:43
@Raven:

You must have misunderstood.

The ocean vertex shader displaces the vertices of the model. It can actually displace the vertices from the bottom of say a sphere or a cube so that they pop out the top, and when that happens, you will see the effect scrolling 'the other way' because you're looking at the back side of the object.

This can't happen with a plane.

Nothing to do with any of the matrices the shader needs to function.

And I think you have a typo in your example inverted matrix.

E Unibus Plurum
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st May 2004 00:49
Ideajuice... it will not matter with the Ocean shader because what it does is works from the World Matrix as a base, and collapses all vertices flat, so unless you sphere is uneven the ZBuffer will keep backfaces in check as movement isn't done per vertice but per matrix position.

The same goes for the texture generation, this is done via the View Matrix NOT as part of the model, so you will get the same results regardless.

The only thing truely affected by the model is the SinWave complexity. As there are 2 waves going on, the SinWave (which is also done in pixel form so it is really just an accentuation of the pixel one) and the Bump Wave.

Everything else is affected by the Matrices and Shader Constants.



if anyone fancies they're a dab hand at getting shaders to work; then getting this one to look right should be a peice of cake for you

I would not that using a sphere WILL NOT work for this one, you get extremely different results.
The Quad Array is 200 planes making a cube from front to back (this is important!) ... the texture is a palette, of 16 colour pixels.
(on the yellow scale)

i'll post what i should look like when i can remember my ftp info; stupid beta drivers killed Windows last nite
but it's a bunch of particles similar to the PS2 opening effect.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Rob K
Retired Moderator
21
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 1st May 2004 00:53 Edited at: 1st May 2004 00:55
Hi folks. Just a heads up. This thread has the potential to be extremely useful - but any arguing and I will delete the offending posts.

@Raven

Your ocean shader link gives a 404 Not Found error.

BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games. - Plus URL download, win dialogs.
Over 140 new commands
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 1st May 2004 02:03 Edited at: 1st May 2004 02:03
@IdeaJuice

Thanks for the tips about the Ocean shader. I really wish I had some newer hardware so I wouldn't have to guess about what was going wrong.

Second post:

You must have misunderstood.

He does that a lot.

I wouldn't waste too much time trying to reason with him unless you get a kick out of arguing with him. Raven isn't exactly the rational sort.

And I think you have a typo in your example inverted matrix.

He got it completely wrong actually. If your interested in how inverting a matrix works I'll provide this little mini-tut here to go over the jist of it.

In order to calculate the inverse of a matrix you need to divide the classical adjoint of the matrix by its determinate. For this example I'll be using an abbreviated version of Raven's matrix to save myself the typing.

[01, 02, 03]
[04, 05, 06]
[07, 08, 09]

Also, I'll be using a certain notation to denote row and column. r1c2 means row 1 and column 2.

While r3c1 means row 3 and column 1. Not to hard to figuare out really.

Note: Only square matricies can be inverted and not all square matricies can be inverted. If the matrix has a determinate of zero you can't invert it(because you'd be dividing by zero).

Now the classical adjoint of a matrix is defined as the transpose of the matrix of the cofactors. So first we need to find the cofactors. This is a bit tricky. The cofactor of any given row and column in a matrix are the signed determinate of the minor of that matrix. For example, take r1c1.

To get the minor of the matrix we for r1c1 we exclude r1c1 and get this matrix:

[05, 06]
[08, 09]

Basically we delete r1c1 and got the above. For r2c3 we would delete row 2 and column 3 and that would be are minor matrix for that row and column. Pretty easy. Now for the determinate.

Now to get the determinate of a simple square matrix like the above we multiple the top left value with the bottom right value and subtract from that product the product of the top right value form the bottom left value. In other words, this:

05*09 - 06*08

The result is -3. Now we need to do this for every row and column. I'll spare you the agony of seeing me work all of this out for each and every value and just list the resulting cofactor for our example matrix.

[-3, -6, -3]
[-6,-12, -6]
[-3, -6, -3]

Now for the final step in getting the classical adjoint of our matrix. Transposing the cofactors. Now to transpose a matrix you basically flip it along the top-left to bottom right diagonal. So
if you had a matrix like this:

[11, 12, 13]
[21, 22, 23]
[31, 32, 33]

The transpose would look like this:

[11, 21, 31]
[12, 22, 32]
[13, 23, 33]

As luck would have it, the transpose of our cofactors is exactly the same as our cofactors. So I'll skip listing that here. So now that we have the classical adjoint of our matrix we can move over to the final step: finding the determinate of our original matrix so we can divide the classical adjoint of the original matrix by it.

Finding the determinate of a 3x3 matrix is a little different from the method I listed for the 2x2 matrix.

A quick reminder. This is our original matrix:

[01, 02, 03]
[04, 05, 06]
[07, 08, 09]

To get the determinate we do this:

01(05*09 - 06*08) + 02(06*08 - 04*09) + 03(04*08 - 05*07)

In diagram form it would look something like this:



Basically, we are multiplying like diagonals together and subtracting the top left to bottom rights from the top rights to bottom lefts.

So the determinate of our little example matrix is 12. So if we divide our classical adjoint matrix by our determinate we get this our inverse:

[-1/4, -1/2, -1/4]
[-1/2, -1, -1/2]
[-1/4, -1/2, -1/4]

Now if my math is right that ought to be the inverse of our example matrix.

@Raven

:: sighs :: sorry neo, but you have a serious problem and you need to sort it before you bother trying to teach people.

Your arrogance is starting to annoy me. For that past year you have demonstrated nothing but ignorance and false beliefs about shaders. That amount of misinformation that you have stored in that little noggin of yours could fill a warehouse. And to top that off you have the nerve to say that I have a problem? *grits teeth* The only serious problem I have is you.

If RobK didn't put a ban on arguing in this thread I'd really rip into you about that and all of the flaws in your post. I suppose I'll have to save it for a later date.

@_Gouki_

Just a note on the Ocean Shader. The evaluateWave function uses the xz position of the vertex in it's calculation which means you need to be careful with the size of the mesh you use (add a new plane xz object in fx composer to see what I mean). A width/height of 100 works well (adjust tesselation to suit whatever you are doing obviously).

Thanks for filling me in on what was going wrong. I don't have VS and PS 2.0 capable hardware so my answers were a bit of a shot in the dark.

Also the wave array values are set in the vertex shader, you should only need to pass in the waveFreq and waveAmp params.

Okay. Thanks for the correction. I was basing my guess that the array values weren't being set off the fact that Peform Checklist for Effect Values was returning a hook value of 0 for wave.


@Rob K

Hi folks. Just a heads up. This thread has the potential to be extremely useful - but any arguing and I will delete the offending posts.

You know I had about 8 paragraphs that really ripped into little black bird and his mistakes. I thought I'd post it later when I had finished up some work on Part II of my series but then I come back and find this. Bummer.

*sigh*

Well I'll have to disagree with the ban on arguing. If someone starts posting lots of misinformation *cough*Raven*cough* I think its in the best interest of this thread that it is corrected. This is an important technical resource and false information can be damaging to the progress people make with shaders.

But its ultimately your call.

On a side note:

What exactly would construe "arguing"? If someone made an error in a shader they posted and someone else pointed out that error would that be construed as arguing? I'm wonder to what extent can mistakes be corrected without falling into the category of "arguing".
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 1st May 2004 03:03
Uhm,

I don't really know what you guys mean with the inverse, but to my knowledge, the matrix

[1 2 3]
[4 5 6]
[7 8 9]

has no inverse at all.

So I'm wondering. With the inverse of a matrix A, do you mean A^-1, so that AA^-1 = I?

In that case the matrix above has no inverse and what Raven does also seems wrong. So what are you all talking about?

Kevil
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 1st May 2004 03:14
I think they mean a matrix that when multiplied by the original from which it was derived yields the identity... but I don't spend a whole lot of time trying to really understand what they are saying.

E Unibus Plurum
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st May 2004 04:06
Arrgh... have you ever done any kind of college math Neo?

oki lets go slow on a 3x3 for everyones benifit Hmmm...
we use something called Kramer's rule to achieve this;

to simplify this into DBP thinking i'll use a matrix.



We use the Kramer to figure out how much we Multiply the matrix by to inverse it;

as what we do next is ...


This allows are values to now be under 1.0 ... this is important, but I did A Level math 4 years ago so i can't remember why.

Now to finish off the inversion we Multiply and Add (MAD) the Kramer to the values, and then Multply the entire Vector by the Matrix outcome.



And ther you have your inversed matrix... basically
|m| = |m|^-1

it's not really that hard at all


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 1st May 2004 06:33
@kevil

So I'm wondering. With the inverse of a matrix A, do you mean A^-1, so that AA^-1 = I?

Yes.

So what are you all talking about?

How to get the inverse of a matrix, of course. I picked a crappy example to go by but I thought it would be clearer. Guess I was wrong about that.

@Raven

Arrgh... have you ever done any kind of college math Neo?

Yes. Lots. But that was a while ago.

we use something called Kramer's rule to achieve this;

Curiosity compels me, but why on earth didn't you state that previously? Your explaination here doesn't line up with your previous explaination at all. In fact, it's not even close. Whatever happened to this?:
Quote: "When you inverse the matrix what this does is basically flips it;
from:
[01,02,03,04]
[05,06,07,08]
[09,10,11,12]
[13,14,15,16]

to this:
[04,03,02,01]
[08,07,06,05]
[12,11,10,09]
[11,15,14,13]
"


By the way, if you are looking for my method I believe that here best describes it:
http://planetmath.org/encyclopedia/MatrixInverse.html



Basically, we are dividing the transpose of the adjoint matrix by the determinate of the original matrix.

Quote: "In order to calculate the inverse of a matrix you need to divide the classical adjoint of the matrix by its determinate. "


My method is correct, its just my example that was bunk.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st May 2004 08:23
No what i explaind and what i said before fit quite well...
The essence of what is going on is the same in terms of the fact that the vectors are reversed; although technically this is done on alternating floats with a realative power at work;

I guess the simplest explaination is your normalising the Matrix; Making sure it is pointing in the correct direction.
But the layman explaination is your flipping/reordering it the opposite direction.

The math i'm using, i'm doing from memory.

Quote: "Basically, we are dividing the transpose of the adjoint matrix by the determinate of the original matrix."

Erm... not quite. This has nothing to do with a Matrix transpose; It's a simple Dot Production of the Vectors against the combined Colomn multiplied by the difference Ratio of the current given value.

Grr, i really need to draw this out to explain it better.
The names given to these aren't done so because they sound right;
Inverse comes from the fact your Inverting an invert in the simplist of terms i A=1 : A=~A : 0=A ... that is it in the simplest form.
Transpose comes from the fact your transforming & imposing values, a transform would be A=1 : A+=A : 2=A and the impose come from the fact that your then imposing another figure onto this A=1 : A+=1/A : 0.5=A

obviously this is all much more complex that this; but thats really what is happening underneath it all.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 1st May 2004 09:59
@Raven

No what i explaind and what i said before fit quite well...

???

How? The code you supplied above does not reverse the order of any of the numbers. It adds up the rows and stores them in a Kramer matrix. Then it sets all of the values to their reciporical. Then it does some weird multiple and add thing along with a dot product thrown in. How does that reverse the order?

Erm... not quite. This has nothing to do with a Matrix transpose; It's a simple Dot Production of the Vectors against the combined Colomn multiplied by the difference Ratio of the current given value.

Yes quite. I linked to an article on Math Planet that said as much. I think you have the inverse confused with something else.

Grr, i really need to draw this out to explain it better.

Take your time. I can be a patient man.

Inverse comes from the fact your Inverting an invert in the simplist of terms i A=1 : A=~A : 0=A ... that is it in the simplest form.

???

I have no clue what you just said. Inverting an invert? If an Inverse is Inverting an invert than where exactly did the original invert come from and what do you call the operation that inverted it?

Talk like this is bound to leave one cross-eyed.
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 1st May 2004 10:07
THE FX FILE FORMAT - PART TWO - CARTOON SHADING IN DBPRO

The goal of this tutorial is two-fold. The first goal is to provide the reader with a firmer grasp on the cartoon shading abilities of DBPro so each developer can create a more personalized look to their cartoon shaded models. The second goal is to explore the concept of assigning media to a shader dynamically.

To that end, I present to you the cartoon shader that DBPro uses internally:


This shader and its media can be found under Help->examples->basic3D.

Now to highlight the important bits.

Since we want to use whatever media we would like with this shader lets take a look at the media required by this shader.



This code can be found at the top of the .fx file below the constants.

The "string XFILE = "default.x" means that it will use the model "default.x". The model isn't really all that important for our purposes so we'll ignore it for now.

The next two lines are the most important. The textures toonshade and toonedge determine how the model will be shaded. You can find these in the same folder that you can find the cartoon.fx file. Lets examine them in detail.

The toonshade texture is shade.bmp and opening it up in paint you can see it is a single pixel in height and 16 pixels in width.

Note: You are going to have to zoom in a bit on it to get a good view.

Now you are probably wondering why the image is only 1 pixel high and the answer is of course that it doesn't need to be any higher. What happens is that the shader takes the dot product of the light vector and the normal of the vertex and the result is a single value. That value is used to look up a pixel in the shade.bmp.

So the shade.bmp is basically a one dimensional look up table. The closer to the light a paticular vertex is the further to the right in the texture the value is looked up.

You can change shade.bmp to hold whatever color ramp that you want. Just keep in mind that all pixels below the first line will be ignored.

The next texture is the toonedge. As you could probably have guessed this texture determines the color of the edges of the model. Its listed as edge.dds but that is incorrect. The edge.dds image is a 1 by 128 image that is just a single color: white. The example that came with DBPro that showcases the Set Cartoon Shading on command uses the edge.bmp texture instead.

The edge.bmp texture is 32 by 32 image. It consists of a gradient that starts on the right with the color white and goes to the left to the color black. Now it doesn't need to be 32 by 32. It can be just 1 by 32 as edge.bmp is a look up table just like Shade.bmp. The values for it are determined by taking the dot product of the eye vector with the normal of the vertex. The result is a single value used to look up which pixel should be multipled with the current pixel.

You are probably not going to want to modify the edge image other than to maybe make it a 1 by 32 image. However, there is nothing stoping you from trying out different values if you want the edge of your image to be shaded differently.

Now that we have covered the needed textures, lets examine how to load and apply them seperately from the shader.

Note: Before we begin, make sure that the shader and its media are in the same folder as your project. The following code will be based upon this assumption.

The first line of our source will be this:


The zero at the end of the command tells DBPro to use the existing textures on the model and not the ones specified in the fx file. This is different from our usual approach of leaving a one at the end of the command seeming how we want to assign the media seperately from the shader.

After that we will load in our images and create our test model:


At this point I'd like to point out the advantage of loading in media seperately from the .fx file. If we loaded media through the .fx file, i.e. left a one at the end of the load effect command, we would be stuck with that media for whatever we applied it to. Loading the media in seperately from the .fx file would allow us to use whatever media we wanted to. We could even use different media for different objects all with the same shader.

To use our current shader as an example, we could load in multiple shade images, that may or may not be named "shade.bmp", to give a different color to a variety of objects. We wouldn't be able to do that if we loaded in the hardcoded media. The only way we could achieve an effect like that is to have seperate shader files each with a different shade image and that could be pretty wasteful of both space and time.

For simple demos, the hardcoded way is probably easier, but for games that have varying texture requirements the dynamic way is the way to go.

Now we have the most important part to do and that is assigning the loaded textures to the shader. Its surprisingly simple to do and it involves the texture object command. Insert these two lines into your DBPro code that you have so far:


The first number, 1, is the object to be textured. The second number is the stage index to which the texture is being assigned. After that is the image number.

Now in order to determine the proper texture stage index we need to look back at the shader code.

Under the vertex shader assembly is a series of render states. This section of code looks like this:


The two that we are interested in are the Texture[0] = <toonshade>; and the Texture[1] = <toonedge>;.

The number in brackets is the texture stage index. So for the toonshade texture we would assign a 0 and for the toonedge texture we would assign a 1. Its as simple as that.

Unfortunately, not all shaders use the Texture[n] state command. Only the shaders that use assembly usually do. So for HLSL shaders most of the time you'll need to do a bit more work. For the shader being used, you'll have to look in its input parameters for a variable or a variable of a structure that contains the TEXCOORDn semantic. From there it will take a little investigative work to figure out which texture is assigned to which. Usually you'll need to look for the tex2D function or its derivitives in the pixel shader. You'll see a variable that contains the tex coords to be used and a sampler state name. With the name of the variable and the specific texcoord semantic assigned to it all that is left to do is find the sampler state specified by the sampler state name.

Sampler states are usually declared above the function somewhere. They are usually easy to find because they start with a keyword like sampler2D or samplerCUBE followed by the name of the sampler. In them you'll find a Texture = <whatever>; and the "whatever" is the name of your texture.

Now that we have assigned the textures to their appropriate stages, we can assign the shader to the object.



After that we have a little while-loop that exits when the space bar is pressed. The code from here on out is pretty standard fare so I'll just list it as it needs no real explanation.



But the cartoon shader that comes with DBPro is rather limiting. You can only shade the object one color and there is no option to apply a texture to it. So you end up with a rather uninteresting monochrome object. We can do better.

As an added bonus, I will add some additional code to DBPro's cartoon shader improving it. It will now take an additional texture in as a base texture so you can detail your model even more.

Add this code beneath the first technique:


And add this code up at the top beneath the two texture declarations for toonshade and toonedge:


Now we only have to add a few lines of code to our existing DBPro source to get it to work. The first line will of course be a load image command after all of the other load image commands. It will load in our texture that will be used as base. For this example we will be using the marble.bmp texture that came with DBPro. It can be found in the same directory as all of the other media that we have used so far.


Next we will assign the texture to the object. We will assign a texture stage index of 2 to our base texture. Place this code just below all of the other texture object commands:


The last line we will need to add will switch the current technique, which doesn't accept a base texture, to the new technique that will. Place this under the set object effect command:


The final version of the source can be found below. Note: This source will not run the old version of the shader but the new one only. Also, the new version of the cartoon shader is still named cartoon.fx in the source though you can change that if you want.


For future work, you can always modify the existing code to switch back and forth between shader techniques or other shaders. Since applying the texture object command to an object will wipe whatever shading is being done to it, you can simply set up the texture stages for the new shader or technique with the texture object command and apply whatever shader you want or none at all. There is no special command needed to stop an object from being shaded other than using a texture object command on it.

That concludes the second tutorial of the FX FILE FORMAT series. I hope that this has been an informative experience that answers many of the questions surrounding cartoon shading in DBPro.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st May 2004 10:10
No doubt the link to Math planet explained as much; i just released in words what I had done above because I don't understand why you believe Transposing is part of the equasion.

My sentance looks confusing because i forgot a comma

Quote: "your Inverting; an invert in the simplist of terms."

the sentance makes sense with that. i'm currently talking to several people about something, so my posts don't exactly have my full attention.

It might not make sense to you right now, but the invert isn't a case of ... ~1.0 = -1.0, basically what the equasions do is flip the positions of things in the Matrix.

Use the equasions I wrote out and explained; put in values one end and then record the outcome. you'll see what i mean,
that is why i wrote it out in DBP code you know; it wasn't just for kicks, it was so you can all have a working version of the code to see what is going on as no doubt everyone knows how to print the values from an Array.

And if you don't trust my math then use the math from your online source. (i have a library by a lass called Tina which has the equasions in C if you'd like that...)


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 1st May 2004 10:26 Edited at: 1st May 2004 10:41
@Raven

i just released in words what I had done above because I don't understand why you believe Transposing is part of the equasion.

Because the link to math planet says it is.

My sentance looks confusing because i forgot a comma

That would explain it.

Use the equasions I wrote out and explained; put in values one end and then record the outcome.

I'll do that by hand and see what I get. I know that there are several ways to calculate an inverse but I don't believe it results in this:

Quote: "from:
[01,02,03,04]
[05,06,07,08]
[09,10,11,12]
[13,14,15,16]

to this:
[04,03,02,01]
[08,07,06,05]
[12,11,10,09]
[11,15,14,13]
"


The inverse of a matrix multipled by an original will produce an identity matrix. The process you describe above doesn't produce that result.

Update:

I fixed your code so it would work. I still don't get meaningfull results or anything that would even closely resemble your original explaination. Here is the fixed code:
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st May 2004 18:18
Hmm, weird; the DP should've achieved the same result as
(A.x*K.x+A.y*K.y+A.z*K.z) ... but it doesn't seem to be.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 3rd May 2004 04:24
I made a slight error in my code. I did a dot product of vector2 and not vector3. Here is the fixed version:

However, the results are the same. The first two rows are all zeros while the last row contains some numbers.
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th May 2004 05:47
I'll be gone for about a week so unfortunately I won't be able to update this thread for the time being. When I get back I'll see what I can do about getting part III in my tutorial series finished and up on the forum. It should be the best one out of the series yet.
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 5th May 2004 10:43
@Final Epsilon

I actually got around to running your example code.

One of your problems is definitely that the backfaces of the sphere are popping out the top.

The other problem is that the effect is pinching together in the center because the geometry of the sphere is such the the vertices are not evenly distributed. You should notice that the waves and texture are bigger toward the outside and get smaller toward the center, and that makes for a less convincing effect.

The textures also move in a circular pattern around the center.

I substituted a subdivided plane for the sphere, and the effect looks great. There is no Z-Fighting, the textures are evenly scaled across the entire surface, and the waves move in one direction across the surface instead of circling around the center.

E Unibus Plurum
Supremacy
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location:
Posted: 8th May 2004 10:59
im sorry to tell you guys..but......raven is right....so your arguing is pointless neophyte, anyway you win becaues this shader really works, but has i said, raven was right about g-force and atari cards.

I will make urban chaos 2, ive already concepted the story, its my dream, i wont to go to muky foot
Supremacy
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location:
Posted: 8th May 2004 11:12
one more thing neo or raven, that ocean picture of raven in page 2, how do i do that from scratch ? i havent read all the thread, only the flame stuff, llllllllooooolll

come on guys, you both the best

I will make urban chaos 2, ive already concepted the story, its my dream, i wont to go to muky foot
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th May 2004 13:09
The Ocean Shader technically are several effects combined into one smart little package.

1) Sine Waves; DarkBASIC Professional can actually do this natively quite fast. (there are examples in the snippets section)

2) Bump mapping; This uses a premade map to add the roughness to the waves, make them stand out more. The bump mapping acts as the texture which you can do in DarkBASIC Professional quite simply, when you combine it with the water colour this produces the ocean look. Infact it does it faster in the shader than natively in DBP as your just using a standard DOT3 N-L pattern.

3) HDRI / Cube mapping; This gives the waves the appearance that light from the scene is actually hitting it, by using the depth of the bump map combined with the Sine Wave hieght. This way you can create a nice artificial world light.

4) Reflection; This uses the HDRI as a base to cube map, this time rather than using the colours to depth your blending them with the texture in the XYZ space (a second texture map) using the brightness of the effect in total as the height map.

The end result is a semi-realistic ocean shader.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Eldar
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 9th May 2004 04:45
To Mustra: Yes I'm sure he was right about the atari cards ..... But on the matter of ATI he was dead wrong. r200 supported ps 1.4 and nv25 didn't. End of story.

And thanks for all the work you have put into this Neophyte, now I can finally use all shaders I have been coding in FX composer. Keep up the good work .

3.1 ghz Pentium 4
Geforce FX 5800 ultra @ 535/1300
DX 9
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 9th May 2004 05:42
Quote: "that ocean picture of raven in page 2, how do i do that from scratch ?"


Here is the ocean shader modified to work in DarkBasic. Call it Pocean.fx to go with the example.



Here is some DB sample code to instantiate it:



The example uses a model called "slab.x". It is too large to post inline here, but it is simply a plane that has been subdivided into a grid. The more subdivisions, the better the effect looks, but of course the more memory it uses and the slower it will run.

The only changes to the shader were to change all occurences of "ResourceName" to "Name" and to change this line:

Quote: "float4x4 viewInverseMatrix : ViewInverse < string UIWidget = "none";>;"


to this:

Quote: "float4x4 viewInverseMatrix : ViewIT < string UIWidget = "none";>;"


so as to avoid having to unneccessarily compute and set the View Inverse transform from within DarkBasic.


Have fun.

E Unibus Plurum
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 9th May 2004 11:12
Eldar if i were you i'd stay out of stuff that doesn't consern you.
I ignored the comments from that user quite obviously as i simply ran down what the shader contained and didn't respond to what he said.

What goes on between me and Neo has very little to do with whatever technology story you wish to believe; there are personal grudges here.

I personally have begun to hate Neo just like i hated Simple ... and for almost identical reasons as well.
Guess time will tell if I am right about this use how I was about Simple, eh?

It's amazing how much power an internet search engine appears to give people around here, and how much respect they get for using it.

If i were you and you want to actually learn about shaders, i'd pay far more attention to Ideajuice or Bulleyes.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Eldar
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 9th May 2004 17:52
I'm merely correcting what I saw as a mistake, if this interferes with your personal crusade against Neophyte, so be it. And as to your second statement, I know how to code shaders, I just needed to learn how to port those shaders to DBpro.

3.1 ghz Pentium 4
Geforce FX 5800 ultra @ 535/1300
DX 9
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 9th May 2004 18:25
Eldar, if you want to know howto get a shader into DBP then i'd suggest you ask someone with more experience on the matter.

Bulleyes for example. Or perhaps even the guy who happened to the first to get them working before DirectX9 update was out, or who had the first custom shader working in DBP, or has helped numerous other people to get thier shaders sorted out.

But i guess the fact of who that is might've passed by some people in this thread.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Eldar
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 9th May 2004 21:18
Fair enough. In that case I do have a question, is their any way to do a z-only render for shadow mapping ? (I know darkbasic has shadowmapping but it is insufficeint for my purposes)

3.1 ghz Pentium 4
Geforce FX 5800 ultra @ 535/1300
DX 9
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 10th May 2004 10:36 Edited at: 10th May 2004 14:02
Well you can't actually do it within DarkBASIC Professional, unfortunately don't have access to the rendering pipeline - not without creating a parrallel one which is messy.



that however will do what you need within the shader itself. i made it as a PS/VS 1.1 so it'll work on all cards; It'll output the depth to main texture, you have to make sure to set the Ambient and Diffuse colours lighter than black else it'll do nothing.

a good combination is Ambient RGB(32,32,32) and Diffuse(192,192,192) that'll give you a good range and allow objects to stand out.

That should be the base for ZDepth you use for producing AA, MotionBlur or Field of Depth.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 10th May 2004 16:56


That is directly out of the nVidia Effects composer SDK. It's called 'deepColor.fx". It does exactly what you wanted.. output the Z depth values directly to the screen as grey levels.

It 'just works'

All you need to do is change the values of Hither and Yon to correspond to the min and max distances you need. Set them to your cameras min and max range. Probably good candidates for doing 'set effect constant' from inside DB.

Unfortunately, you would have to set this shader effect on every single object in your scene in order to get a full render of the z buffer. There is no way really to set one effect and have it affect your entire scene.

What it does is transform the input vertices into world space, then it takes the Z position only of the transformed vertex, scales it by the min and max distance you set in Yon and Hither, clamps the result between 0 and 1, computes a gamma corrected value for this (the example is using a gamma of 1.0 which will leave the output value unaffected) and then scales this result to fall between the min and max color using the lerp function (linear interpolation).

Because min color is black and max color is white, this gives you exactly what you need for your shadow mapping, but you could play with different colors for those to get novel effects.

No pixel shader is needed since by default the pipeline will automatically interpolate between the colors set for each vertex by the vertex shader.

Enjoy!

E Unibus Plurum
Eldar
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 11th May 2004 02:37
Exactly what I needed. Thanks Raven and Ideajuice. One last question
how would I pass the results into the shadow shader?

3.1 ghz Pentium 4
Geforce FX 5800 ultra @ 535/1300
DX 9
Ideajuice
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 11th May 2004 03:22
Shaders have the ability to render into textures instead of to the screen, but I'm not sure how to access and retreive such a texture from within DarkBasic. It's created on the fly inside the shader during one 'pass', and normally it's also used by the same shader in a second or third pass.

I also beleive that many of the built in effects in DB use something called the FVF (Flexible Vertex Format) method, and this method is an incompatible and earlier version of the techniques that are now done with shaders.

The right way to do this would be to incorporate what this vertex shader is doing with other shaders that also light and texture the models. Since you have to set a shader on every model in your scene to render this Z effect, it's not that big a step to have each models shader also do the texturing and lighting and then scale the result by the result that comes from this one.

For example;



that is our old friend the ocean shader which I have added the depth shader into so that the farther parts of the ocean darken.

To make this work, I added the output of the Z shader, which was a color, to the structure that lists what the outputs of the Vertex shader are. Then in the pixel shader, after it has done all of it's normal calculations, I multiply the color it computes by the color computed by the Z-Depth shader.

You could do the same thing with any other shader assuming you don't make it too complex for the video hardware to handle. Add the depth calculation to the vertex shader, store the resulting color into the VS output structure, and then scale the color computed in the pixel shader by the value you've stored.

Hope this helps.

E Unibus Plurum
Eldar
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 11th May 2004 03:45
I meant after you do render all models from the lights perspective useing your shader and grabbing the screen as a bitmap, how would you feed that bitmap back into the next pass?

3.1 ghz Pentium 4
Geforce FX 5800 ultra @ 535/1300
DX 9

Login to post a reply

Server time is: 2024-05-07 09:57:24
Your offset time is: 2024-05-07 09:57:24