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 / [STICKY] Learning to write Shaders

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2006 18:40 Edited at: 1st Nov 2006 19:51
Quote: "Next i think you should start explaining what certain functions do and how to use them."


That is the intention - some time before I reach Hell with any luck ...

[Edit: changed original zip file name so it is less misleading. I take your point. Thanks for the feedback by the way.]
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2006 22:19
Here's a simple animation using a shader.

The X,Y and Z coords and normals of the object are modified by the vertex shader. The pixel shader just outputs the colour as modified by the lighting.

Attachments

Login to view attachments
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 2nd Nov 2006 05:55
Hey, on the HDR Shader, the object shines a white color. How would I change the color of that to like blue?

Take heed, never take advantage of the things you need, never let your self be overcome by greed. Walk a strigh line, pick up your speed and try. Everyone deserves a piece of the pie By: Shaggy

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Nov 2006 19:20 Edited at: 2nd Nov 2006 20:06
Depends what you want to do exactly. For example the following simple change to the HDR.fx code will just blur the blue component. All I have done is replace the float Brightness by a float4 so you can blur each colour component separately. See attached screen shot taken from Evolved's demo with the edited shader.



If you want all colour components blurred - but blurred as blue, then you need to do a bit more work. I'll see if I can make some simple changes for you later this evening.

[Edit: Oops - replaced PNG file with JPG.]

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Nov 2006 20:01 Edited at: 2nd Nov 2006 20:08
Ok, here's another way of doing it. This might not be what you want because it destroys the red and green components of the base image - but it does give a bright blue blur.

Change the "tweaks" to:


and the pixel shaders to:



A typical screenshot is attached.

This is just a quick fix and I am sure there are better ways of doing it, by adjusting the weights instead perhaps. My solution requires additional instructions in the pixel shader which is bad news for fps. Perhaps someone else would like to have a go?

[Edit: Oops again - forgot to check PNG vs JPG sizes before posting. Here's the JPG screenshot.]

Attachments

Login to view attachments
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 2nd Nov 2006 22:01
Quote: "Here's a simple animation using a shader."


Thats neat. I didn't know shaders could do those kind of things.

Now for the questions.

1. What is WorldInverse?

2. What does the f in this part do?:

float4 ambiColor = {0.4f, 0.4f, 0.4f, 1.0f};
float4 liteColor = {0.8f, 0.8f, 0.5f, 1.0f};


4. I saw that you can access parts of a float4 by using
.x, .y, and .z. What about the fourth part?

5. What does the dot function return, and what are the parameters for it?

6. Do the sine and cosine functions use radians or degrees?

7. What is different about vs_1_1 and vs_2_0?

Thats it for now. Thanks for all the help you've given me

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 2nd Nov 2006 22:30
1) Well it's quite hard to explain if you don't know about matrices... basically a way of changing something between different coordinate systems.

2) The 'f' is just a way of saying 'float' I think. I'm not actual sure, I just got into the habit of puting it at the end of every float in C!

3) Where was 3?!

4) .w of course.

5) It returns the dot product of two vectors: http://en.wikipedia.org/wiki/Dot_product

6) Radians

7) Quite a lot. Basically, you can do a lot more stuff in 2.0, but old cards don't support it. Not sure of the absolute specifics, but I know that you can execute way more commands.

-= Out here in the fields, I fight for my meals =-
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 3rd Nov 2006 03:09
Cool. Thanks! The first works, but I have a few questions.

1. float4 Brightness <> = {0.0, 2.0, 0.0,1.0};
a)I see the first three are RGB, but whats the last nubmer do?
b)It looks like the larger the nubers are, the larger the area they fill get, is that right?

2. How would I make it in my db code let me choose what color to make those values? Like maybe use different functions or something. (I know nothing of Shaders)

Take heed, never take advantage of the things you need, never let your self be overcome by greed. Walk a strigh line, pick up your speed and try. Everyone deserves a piece of the pie By: Shaggy
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2006 01:35 Edited at: 4th Nov 2006 11:05
Quote: "but I have a few questions."


1. a) The fourth number is the alpha component usually used for transparency level, but, like the others, can be used for anything you like.
b) Yes and no, if I've understood the shader correctly. The width of the blur is really fixed by the variable "blurwidth" (a clue in the name there). However, making "Brightness" larger will make the brightness of the blur greater, so barely noticeable parts of the blur will become more obvious. This will make the blur appear wider until the blurwidth is completely blurred. Hope this makes sense.

2. You pass parameters to the shader from DBPro by using "set effect constant float", "set effect constant vector" or "set effect technique". There may be one or two others which I've forgotten. For example, to pass the colour yellow as the blur colour rather than blue, you would do something like the following:



The variables vecNum and effectNum are just the vector and effect numbers that you decide to use in your DBP program.

Have a look at the examples posted earlier on this thread. I'm sure several of them have examples of "set effect constant", etc.

[Edit: amended the red and green colour values to be 2.0 in each case.]
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 4th Nov 2006 10:20
Dammit too slow.



-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2006 11:04
dabip

My apologies. I should have written:



Serves me right for not testing such a simple thing before posting. Sorry.

The "2"s are needed to force the blur to be bright - the shader automatically clamps any colour components to the range [0,1] if any values are outside the range after the pixel shader has calculated them.

I've amended the original post to avoid misleading anybody else.

Chris K

Quote: "Dammit too slow."


Judging by the evidence, I was too quick
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 4th Nov 2006 12:44
I actually need some help with a shader, so I thought I'd post here for everyone to learn from.

I'm trying to get a caustic effect, you know the kind of dancing light you get at the bottom of a swimming pool.

I've already got a good set of animated caustic textures (attached, 5 mb), It's just a case of applying them.

The thing is, I want to apply them to the entire under water 'scene' - every object that is underwater.

The shader should basically drop the caustic texture down onto the whole scene, I guess you could just set each vertex's UV to it's x/z position.

It also should only texture the 'top' of the scene, polys with a negative y normal shouldn't be affected.

Also, it should put the caustic texture over anything other texture s currently on there.

Would it be a good idea to make a new object that is made up of the meshs of every other object, the just apply the caustic to that?

-= Out here in the fields, I fight for my meals =-

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2006 01:37
Perhaps use a cube map with only the "pos Y" image textured - then perturb the normals before looking it up? Then apply this shader to each object. Just a thought.
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 5th Nov 2006 02:56
Thanks Chris for ansering my questions

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 5th Nov 2006 15:59
Quote: "2) The 'f' is just a way of saying 'float' I think. I'm not actual sure, I just got into the habit of puting it at the end of every float in C!"


Yep, that's correct. The .f denotes a float. Technically speaking, f is the field of fraction bits, but I believe that it is also a way of being able to tell a float value from a double

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2006 23:27 Edited at: 6th Nov 2006 13:26
Here's another shader demo for you all to play with. It creates a translucent blue glow around the edges of an object. You can experiment with the code to get different glow colours.

[Edit: Ignore the comment in the header text of the *.dba file about comparing with DBP standard texturing. That comparison was deleted from the uploaded version.]

Attachments

Login to view attachments
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 7th Nov 2006 11:35
Hi
I'm a newb to shaders.... Is it possible for a shader to change the uv coordinates of an object? Specifically to make the whole uv map match the camera... (with perspective)


Portfolio: http://mike-inel.cgsociety.org/gallery/
Website: www.Altiz-Studio.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Nov 2006 12:34 Edited at: 7th Nov 2006 12:51
Quote: "Is it possible for a shader to change the uv coordinates of an object?"


Yes. You can set them to anything you like - but they will be wrapped, or clamped, or mirrored to the range [0,1] before the final texture look-up takes place. You set the feature you want (wrap, etc) in the sampler code as in some of the examples posted earlier on this thread.

Quote: "Specifically to make the whole uv map match the camera... (with perspective)"


Yes - but I believe you need to capture the camera's image in your DBP program (i.e. set camera to image etc) and then use that image as one of the textures for your object. I think some of Evolved's shaders had examples of how to do that, possibly the water, HDR or Bloom shaders, not sure though (don't have them here). Will get back to you later when I get home if you haven't found them.

But be warned - I think realtime capturing of an image and using it in the shader may slow down your application.

[Edit: Afterthought. Have a look at the fresnel water shader which javaguy was discussing on the main DBPro list (search for "fresnel water"). I think that used realtime rendering with a camera for the reflections. You'll have to check though.]
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 7th Nov 2006 13:38
About the uv map matching the camera, well I think what you said isn't not what I had in mind... I was hoping of making a shadow mapping technique... But thanks for the info though, they're useful! I guess i'll have to learn how to program shaders...

I have another question though... What's the difference of HLSL and ASM? Are they significantly different from each other? (In coding) Are they both supported by dbpro? Which of them is better? Or correct me if I misunderstand any of these things... (heheh)

And in any way, are there any tutorials about shaders for newbs that are really related to dbpro? I find most of the tuts for beginners really different from each other... (makes me confuse...)


Portfolio: http://mike-inel.cgsociety.org/gallery/
Website: www.Altiz-Studio.com
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 7th Nov 2006 14:40
Quote: "What's the difference of HLSL and ASM?"


One is a high level language ( ), one is Assembly ( )

-= Out here in the fields, I fight for my meals =-
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 7th Nov 2006 15:12
Which means one's easier ( ), and ones faster ( )

Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 7th Nov 2006 19:22
Could someone pretty please explain to me how to use the bloom shader in the ultimate shader pack?

All the camera stuff and the tone.fx and lots of the rest went right over my head

"One man, one lawnmower, plenty of angry groundhogs."
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Nov 2006 22:54
Quote: "Which means one's easier ( ), and ones faster ( )"


HLSL is certainly MUCH easier, AND in my experience is just as fast as ASM code unless you code carelessly. FX Composer compiles HLSL to ASM for you so you can see what the ASM code looks like. The few occasions I've thought the ASM code could be improved it turned out that there was an obscure rule limiting the number of certain registers that could be used in a single ASM instruction. In HLSL you don't need to think about such things. My guess is that it is MUCH easier to write inefficient code in ASM than in HLSL - because there is no compiler to optimise your ASM code.

Shaders, especially pixel shaders, tend not to have many instructions so it is usually clear where code optimisation is possible. For example, don't do something more than once if you only need to do it once. Sounds obvious, but you sometimes need to reorganise your calculations to achieve this. Pruning one instruction in a pixel shader can make a big difference to the performance of an application - because that one instruction may be executed many millions of times a second.
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 10th Nov 2006 08:41
Hi, I have another question... Is it a reasonable to but a GeForce 8800? link And what does Geometry shader really do?
Their technical briefs are more of shader topic so I don't understand most of them...


Portfolio: http://mike-inel.cgsociety.org/gallery/
Website: www.Altiz-Studio.com
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Nov 2006 10:31
Apparently an 8800 is as good as TWO Crossfire-d 7950XTs, which is pretty impressive.

-= Out here in the fields, I fight for my meals =-
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 10th Nov 2006 10:49 Edited at: 10th Nov 2006 10:51
Only DBP doesnt support any of that new-fangled technological stuff, so there's not much point if you want to buy it just for DBP. It will however be quite good for playing games

@GreenGandalf: I agree that difference would be fairly minimal, however this could increase with the size of the shader, because compilers are generally not superb at optimizing asm code, which is possible in asm. That said, you'd want to code one heck of a shader to see a noticeable difference

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Nov 2006 13:53
Quote: "because compilers are generally not superb at optimizing asm code, which is possible in asm"


What do you mean?

I think you have to do ALL the optimising yourself when you write in asm code. I agree it can be worth checking the compiled HLSL code (which is in asm) to see if any savings are possible.

However, my experience is that most of the difficulty with shaders is getting something working correctly in the first place - and that is MUCH easier in HLSL for most people.

An interesting question is whether the compiled code produced by FX Composer is functionally the same as the compiled code produced by DBP. I have no idea - but have used the working assumption that they are.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Nov 2006 14:02
Just to be an ass, technically, I don't think ASM is compiled, it's assembled.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Nov 2006 14:48
Quote: "Just to be an ass, technically, I don't think ASM is compiled, it's assembled."


True, I'm sure.

My question was whether the HLSL code compiles to essentially the same asm code (the "compiled code") whether you use FX Composer or DBP. In FX Composer you see the "compiled code", i.e. the asm code, but you can't in DBP. (I guess asm code is, in turn, assembled into something else the machine can understand - but I have no idea. If it is, then DBP might skip the asm step. Anyone actually know?)

Anyway, the point is: if you optimise your HLSL code using FX Composer's asm code as a guide, can your good work be undone (or even improved ) when DBP gets hold of it?

P.S. I say you can see the asm code in FX Composer. That's not strictly true - you can only see the vertex and pixel shader instructions. You still have to work out how the registers have been assigned to things like constants, etc.
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 10th Nov 2006 15:08
My knowledge of shaders is limited, but for computers, ASM is assembled () into machine code. Each ASM statement is equivalent to one machine code statement, so ASM is really the purest form of coding. This is the reason ASM can be faster than high level code, as compilers don't do 100% perfect optimisation, so it might use a few instructions more here and therem, but to a minimal effect

As for your question, I'm not sure actually, I assume HLSL and ASM get compiled (and assembled) when they are loaded into the shader system. I dont think DBP touches the actual shader data as it should be passed directly to the card, where DBP fills in the other data

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Nov 2006 18:38
Quote: "This is the reason ASM can be faster than high level code"


The important words are "can be". In practice it depends entirely on who is writing it.

Quote: "I dont think DBP touches the actual shader data as it should be passed directly to the card"


Is that true? I thought it was compiled or processed in some way first. Otherwise why the problems with procedural textures and intermediate render targets which are not supported by DBP?

Quote: "I'm not sure actually"


I think that applies to both of us.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 11th Nov 2006 00:18
I think the point is, Dark Basic can't have a texture created that it will recognise as an image in the same way 'load image' works...

Surely the water shaders and HDR shaders create textures in the shader...

Meh I don't have a clue

-= Out here in the fields, I fight for my meals =-
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 11th Nov 2006 00:34
Quote: "I thought it was compiled or processed in some way first"


DirectX compiles HLSL to ASM, but any textures or parameters need to be provided separately. Anything in annotation blocks is ignored by DirectX and is there purely for the program to guess what it should be doing with the shader and what to give it, same with semantics.

In fact I believe ASM will not be supported in future versions of DirectX, HLSL all the way!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Nov 2006 02:31 Edited at: 11th Nov 2006 23:30
Quote: "In fact I believe ASM will not be supported in future versions of DirectX, HLSL all the way!"


Sounds like good news to me.

Quote: "Surely the water shaders and HDR shaders create textures in the shader..."


Yes, but as far as I know you can't access them using shaders written for DBP - only at the final blending stage per pixel. You can probably write a more efficient bloom shader if you could do a horizontal pass on the image, then do a vertical pass on the RESULT of the horizontal pass. This can save a lot of arithmetic operations. This seems to be possible in FX Composer and RenderMonkey both of which allow intermediate render targets, but not in DBPro. I've got an example almost working in FX Composer - but haven't got the intermediate render target initialised properly and can't find any documentation on how to do it.

Similarly you cannot set up a procedural texture in your shader for use later by your pixel shader in DBP - you need to calculate it in your DBP program and then pass it as an image to the shader.

A procedural texture would probably be a very neat way of doing your volumetric cloud shader...

**Edit: I know this is somewhat off-topic because you can't have intermediate render targets in FX files for DBP, but if anyone can help I'd be very grateful. Here is the latest version of my attempt to use an intermediate render target in FX Composer - it doesn't work as expected AND I can't see how it obtains the result it does.

What I expected the FX code to do is two things: in the first pass the base texture is loaded and the green component is removed; in the second pass, full purple is added to the colour of the result of the first pass - so the result should be purple. It isn't - there are white patches where the green component was in the original texture.

What really baffles me is this: how does the renderSample sampler manage to provide the green component for the final image? There is no obvious link (to me at least) to the base texture.

I've obviously either completely misunderstood something (quite likely!) or made one of those "obvious" logic errors that I can't just see.

You need FX Composer and all you have to do is open the FX file in FX Composer, create a new scene from a sphere, apply the effect, AND THEN from the menus, click Build/Compile 2 or 3 times. You should see a purple sphere with some white patches - except I thought it would be completely purple.

Attachments

Login to view attachments
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 12th Nov 2006 14:57
OK I'm having this weird problem with the fresnel water shader. It looks find farther ahead from the camera but for some reason it sort of goes crazy closer to the camera (Image attached). I'm not sure what's going on, the sky is just a big inverted box with a texture on it and the FOV on the reflection camera is set to the same FOV as the main camera.

Attachments

Login to view attachments
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 12th Nov 2006 15:14 Edited at: 12th Nov 2006 15:15
Hi. I have really posted much here, but I just wanted a couple of basic tips/info about shaders (not dbp specific)

My first, and biggest curiosity, is how does the shader/whatever runs the shader know the 'entry point' to the shader? (what piece of the shader to run and when)

For example:


How does it know what to run? It can't be name-dependent of course, which completely alludes me. Meh, it's probably really simple, but I don't see how Unless you are restricted to one 'technique' per shader and it simply runs the first technique it finds....?

EDIT: I'm a C++'er so I understand the actual code, just not how it decides which part to run.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Nov 2006 18:50
The main part of the shader code is just a lot of declarations of constants, structures, functions, etc. The actual call is in the technique part as you imply.

Quote: "Unless you are restricted to one 'technique' per shader and it simply runs the first technique it finds....?
"


My understanding is that only one technique is run at a time. You can specify which one from DBP by using the set effect technique command.

I've also read that DBP will use the first acceptable technique it finds, so a shader author might write several versions of the shader in different techniques using different vertex and pixel shader language versions (i.e. VS_1_1, PS_2_0, etc) and put the most up-to-date techniques first. However, it may be that the DBP program itself has to do the searching - I'm not sure. This feature is supposed to mean that a DBP program working on an older GFX card might not use the first technique it finds. How this relates to the set effect technique command I don't know. It seems plausible that DBP starts looking from the technique you specify - or perhaps you have to do the coding yourself in your program using get maximum pixel shader version, etc. To be safe that is what I would assume.

You CAN use several techniques simultaneously by loading several copies of the shader and giving them different effect numbers. I did that in my simple reflective shader demo a few posts back.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Nov 2006 20:11
@Antidote

I see what you mean. The short answer is that I don't know what's causing the problem without getting my hands on the code and doing some experimenting. But here are a few thoughts anyway.

Evolved's Fresnel water shader had four techniques in it. Do they all give the same problems? Which one were you using?

It's possible you need to "tweak" one or more of the "tweakables" listed in the FX file:



For example, use set effect constant "FresnelScale", myFresnelScale#

where myFresnelScale# is a variable you can tweak in your DBP program till you get the image right.
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 12th Nov 2006 20:31 Edited at: 12th Nov 2006 20:33
OK I figured out what the problem was . I had been using the FresnelReflectRefract technique, but was only updating the reflect camera. I just changed the technique to the reflect and it worked perfectly. Thanks for sorta leading me on the right path Green Gandalf!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Nov 2006 21:06
You're welcome. Glad you got it sorted.

As it happens I tried disabling the two updating options and got results somewhat similar to yours when it was the refract option that was disabled - which was why I asked the question. (I could have said so though - don't know why I didn't .)

In case you're interested, I've had a quick look at Evolved's code and tweaked it a bit to reduce the pixel shader instruction count. I attach the revised FX file. Doesn't make much difference - and still runs VERY slowly on my machine (13 fps!!). One of the changes has altered the image slightly - I think the original was somewhat better. If I get time I'll have another look.

Attachments

Login to view attachments
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 12th Nov 2006 21:16
Yeah, the shader takes up a LOT of system resources. If I turn off refraction and update every other frame I get to 45 FPS.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Nov 2006 13:02
Hi All,

Evolved has just posted a new simpler version of his water shader (with two nice demos) on the Work In Progress/Ultimate Shader Pack thread.

Probably worth a look.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 15th Nov 2006 00:13
From what I understand, installing V6.3 of DBPro has changed the way multi-camera water shaders work and you can not use non-sequential camera numbers. They have to be 0,1,2 for example and not 0,30 and 31 like the fresnel one.

The 6.3 release notes state:

Quote: "
* When a new camera is created it is internally sorted by index (rather than instance order)
* Fixed SYNC MASK bug which caused secondary cameras to wipe out cameras masked out
* Removed the power of two limit on the SET CAMERA TO IMAGE command, supporting newer cards
"


Quite what the first line means in reality is anyone's guess.

Boo!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Nov 2006 11:42
Quote: "Quite what the first line means in reality is anyone's guess."


Indeed. I haven't downloaded 6.3 yet so I can't experiment - but I wonder if it's connected with the sync mask thing?

Anyway, I think Evolved's new version of his water shader should work with both versions of DBP.
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 15th Nov 2006 18:07 Edited at: 15th Nov 2006 18:11
I made my fist pixel shader It's just a black to white gradient using the UV coordinates.

Here it is :



I know it's not much, but it's cool that i made it.

Thanks Green Gandalf and Chris for helping me learn

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Nov 2006 19:46
Nice example. Well done.

I know how satisfying it is to get something working which is your own idea. Keep it up - and keep the questions coming, we'll do our best to help.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Nov 2006 00:47 Edited at: 16th Nov 2006 21:08
Here's another shader to play with. This is another example of a "flashlight" shader. The flashlight shares the player's position in the world (i.e. the default camera's position).

In the demo you can move the camera and the light - but not simultaneously. I hope the on-screen instructions are clear with a bit of experimentation. You may need to reduce the sync rate on faster computers than mine.

The shader shows how to use a 1-dimensional texture look-up. You can replace the flashlight look-up texture with one of your own to see how it works.

The shader was inspired by one of Evolved's shaders, but uses a different method from his.

[Edit: Just realised I didn't include a switch for the light. Serious omission in these environmentally aware days...
Will amend it later today if someone hasn't beaten me to it. Might improve the controls in the dba program as well.]

[2nd edit: OK, added a switch and tweaked the FX code a bit to improve the image for low poly objects - the new FX file is marked "v2". The camera and light controls in the DBP program could be improved - but I think the shader's OK.]

Attachments

Login to view attachments
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 16th Nov 2006 17:35 Edited at: 16th Nov 2006 17:36
That's neat.

I've seen the TEXCOORD parameters for vertex and pixel shaders, but somtimes i see TEXCOORD1 for the normal, sometimes NORMAL for it. Also i don't know what TEXCOORD3 is. Just to straiten things out, can you explain what exactly each of the TEXCOORD parameters are?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Nov 2006 20:03 Edited at: 16th Nov 2006 20:54
Quote: "I've seen the TEXCOORD parameters for vertex and pixel shaders, but somtimes i see TEXCOORD1 for the normal, sometimes NORMAL for it. Also i don't know what TEXCOORD3 is. Just to straiten things out, can you explain what exactly each of the TEXCOORD parameters are?
"


The semantics TEXCOORD, TEXCOORD1, etc, are just references to help the FX compiler understand what registers relate to what variables in your code and what sort of data they contain. So, for example, if your vertex shader outputs a variable with the semantic TEXCOORD2 then this would get matched to a pixel shader variable with the same reference (if there is one), as in the following example:



The compiler will know that the values for MYVECTOR required by the pixel shader are stored in the register TEXCOORD2 which in turn would correspond to values passed by the vertex shader via the variable MYVAR1. There are a limited number of these variables which you can use. I think there are 8 TEXCOORD registers (TEXCOORD0 up to TEXCOORD7) which you can use to pass values from the vertex shader to the pixel shader. Note that the values get interpolated before being accessed by the pixel shader (i.e. the values supplied by the vertex shader relate to specific vertices in your object - the pixel shader fills in all the space in between by interpolating the values from the vertices). (I'm not absolutely sure, but I think TEXCOORD is the sane as TEXCOORD0.)

The semantic TEXCOORD is often used to refer to texture coordinates - but can in fact refer to any numeric data which is why it's often used for things that have nothing to do with textures as such (like an attenuation factor used in a light calculation for example).

For input to the vertex shader, the compiler would assume that TEXCOORD0, TEXCOORD1, etc, refer to the UV coordinates of the various textures declared in the FX file (in the order in which they are declared). [Edit: not quite sure about this. You normally only have one set of UV coordinates for your object and these are accessed via TEXCOORD or TEXCOORD0 as in all my shaders so far. I understand it is possible to set up different UV coords for the different texture stages applied to your model - I assume, but don't know for certain, that you would use TEXCOORD1, TEXCOORD2, etc, in that case. Perhaps someone else knows the answer to this.]

Similarly, the semantic NORMAL attached to an input variable for the vertex shader will tell the compiler that you want it to supply the normal associated with that vertex. Similarly with TANGENT and BINORMAL which are often used in bumpmapping shaders.

On the other hand, the semantic COLOR tells the compiler that the variable concerned contains values that will be used as colour - so the machine automatically clamps the values to the range 0 to 1 in calculations. This is useful when you are trying to force pixels to be bright or dark - you don't need to include code to check that your value is in the valid colour range. Hence, the result of an arithmetic command might be the vector (0.5, -0.1, 0.5, 1.0). If this was assigned to a variable with the COLOR semantic it would be stored as (0.5, 0.0, 0.5, 1.0), i.e. a mid purple colour, the "-0.1" would be "clamped" to zero.

The above is a bit of a simplification, but I hope it gives you some idea. If you have any questions about a particular example, post the snippet here and I'll try to explain what's going on.

[Edited a couple of errors.]
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 18th Nov 2006 16:50
Thanks, i get it now. Sorry for responding so late

Login to post a reply

Server time is: 2024-11-23 19:44:57
Your offset time is: 2024-11-23 19:44:57