DBPro / Learning to write Shaders |
| Author | Message | ||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
USE THIS THREAD TO POST ANY QUESTIONS ABOUT SHADERS --------------------- ------------------------- This thread was originally started at the beginning of the nVidia competition, when we learnt that it would be marked heavily on use of shaders, and everyone realised they didn't have a clue how to write or use them. Over the course of the competition, many of the community took the plunge and came up with a fairly decent knowledge of how to write shaders for use in DBPro. This thread, therefore is fairly invaluable to anyway wanting gorgeous graphics in their game, hence its new home, at the top of the DBPro board. It is probably the best place to ask questions if you are trying to learn - currently there is a fairly good tradition that people who have been helped to learn have stuck around to help others, it would be awesome if that could continue. Enjoy! ------------------------- --------------------- UPDATE. ----------------- Some helpful info from GG on where to find good docs: *************************************************** Three that I've found useful are: 1. "Programming Vertex and Pixel Shaders" by Wolfgang Engel. [He has written several other books that I haven't seen and has a website with a few tutorials.] 2. "Shaders for Game Programmers and Artists" by Sebastien St-Laurent. 3. "Microsoft DirectX9 Programmable Graphics Pipeline" by Kris Gray. [As is usual with Microsoft this book was better at convincing me that there was a lot I didn't know than actually telling me something I wanted to know. But it did explain some things I hadn't appreciated before.] All three books come with CD demos, etc, but I haven't seen the CD for book 3 (it's a library copy and the CD has sprouted legs). I particularly like the first two books and their demos. But I find "RenderMonkey", which I think both books use, a nightmare to use. However, RenderMonkey has some nice FX demos and, if you have the patience, you can rewrite the FX files for use in DBP. FX Composer is a free shader resource which you might find useful. I've also found some useful, but limited, HLSL tutorials using Google. *************************************************************** Original Post: OK, so I guess a lot of people are going to be in a position like me, where they really need/want to learn to write shaders for this competition. I know there's going to be a tutorial in the next newsletter, but I guess that's going to be more getting them to work with DBPro than how to actually write them. So any advice from anyone as to what tutorials to read? Absolute beginner we're talking here. I've got Render Monkey and I know C++ (the shader language is basically C isn't it?) -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Image All
User ![]() Joined: Fri Dec 30th 2005 Location: I can feel my hair growing |
|
||
| Back to top |
|||
|
sett
User Joined: Sun Sep 19th 2004 Location: somewhere in my mind... |
They can be written in C++, I think. Or you can use RenderMonkey or the NVIDIA Shader composer. ![]() Windows XP,pentium IV, 3.0 MGZ, 1024 mb memory, 256 mb ATI Radeon PCIE X700 Pro 'sett squadron back on the assault' |
||
| Back to top |
|||
|
Lukas W
User ![]() Joined: Fri Sep 5th 2003 Location: Norway |
you can try this tutorial: http://vvvv.org/tiki-index.php?page=pixelshader_for_newbies i may have a closer look at shader programming too. though at the moment Evolveds shaders and the DBPro Shadow shader is good enough for me. |
||
| Back to top |
|||
|
Raven
User Joined: Wed Mar 23rd 2005 Location: Hertfordshire, England |
I'll try to explain them here a bit as tbh there aren't many decent online tutorials. Alright we.. firstly I'd suggest using FX Composer for Shaders. It fully supports any DirectX Shader Card, Shader Model 1.x / 2.x / 3.0 as well as supporting Software 1.1. When you add to that functionality the ability to load, link and/or use up to 255 Shaders at any given time with a visual thumbnail of what they do and an option of adding them either as a Screen or Object Effect, then you have a fairly powerful tool. You can also preview real-time, recompile quickly, change variables on-the-fly, view current samplers loaded / output. Along with the main C-Style Coding Window. All of which is customisable to your own preference. So you have a fairly powerful creation utility at your disposal. However another good point is that it provided help information on DXSAS1.0 Compliancy, something DBP now has meaning shaders theoretically can be used without any editing as well as exporting to be compatible with Ashli (so you can load/use in Maya/Max/XSI for model development means) On the whole it makes shader development a damn sight easier, especially from a coding point of view. Now I think I'll cover what DBP doesn't support. Inline Functions : Useful technique used for creating samplers each time the function is called. While there is a way to do this, it is only supported by outputting the Shader as ASM, but DBP HLSL doesn't support this yet. To output ASM from FXComposer then click on Shader Perf and select your card.. Your card MUST support shaders to use Shader Perf. So those of you using it in Software 1.1 mode (like I am right now you can't access it). Scripting : This can be useful for having shaders run slightly differently based on what is going on as well as controlling the function order better. Can increase performance and functionality under the right circumstances, but DBP doesn't support this and don't see why it ever will tbh as for most games it's pointless. Shader 3 : Technically yes this is supported, but only the most basic implimentations that can revert back to 2.0.. so don't even bother using it. Again this is a feature that can be used with the ASM shaders, but the complexity of sorting out SM3 in ASM is honestly not worth the benifits over 2.0 HLSL. Only use that as a last resort. There's a number of other things to look out for when making shaders for DBP, but I don't have a lot of time right now to explain them all. Mostly it's semantic stuff. Intel Pentium-D 2.8GHz, 512MB DDR2 433, Ati Radeon X1600 Pro 256MB PCI-E, Windows Vista RC1 / XP Professional SP2 |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Cheers everyone. Raven's sold me FX Composer, I'll download it. It sounds basically the same as Render Monkey but maybe a bit better. -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
@Chris K Yes, I agree with virtually everything Raven said, FX Composer is very good - definitely worth the wait while it downloads from NVIDIA. Also, it's MUCH easier to use than RenderMonkey (except that you have to write all the code yourself, but on the other hand, the shaders you will want here will be quite short really). Also, the FX files exported by RenderMonkey usually need editing before they work in DBP - but RenderMonkey does have some nice examples which you can adapt. If you have questions, post them here and someone will probably help you. I will certainly try to help if I can. I think you get points for discussing your work here - so keep the questions coming. |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Awesome. There are some RenderMonkey example that I'm determined, eventually, to get into DBPro, but I'll be ecstatic to get anything that I've written working. ------- I know what you mean about the wait. 11kb/s? What is this 2001? -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
sett
User Joined: Sun Sep 19th 2004 Location: somewhere in my mind... |
does the sample shader that are already here are 100% royalitie free? ![]() Windows XP,pentium IV, 3.0 MGZ, 1024 mb memory, 256 mb ATI Radeon PCIE X700 Pro 'sett squadron back on the assault' |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Those that I've posted on the main DBP board and the WIP/Ultimate Shader Pack certainly are - and I think most, if not all, in the Ultimate Shader Pack are too (but you'll have to check). |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Does a shader loaded into DBPro do anything for you? For example, would it automatically set view_projection_matrix or whatever, to the right value, or do you essentially set all the shader's variables yourself? -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Quote: "For example, would it automatically set view_projection_matrix or whatever, to the right value, or do you essentially set all the shader's variables yourself?"
DBP passes various variables to the shader such as the worldviewprojection matrix and cameraposition as in the following snippet from one of my bump mapping shaders (see attached file for the complete code): + Code Snippet I'm not sure what the complete list of such variables is. That's the sort of information that is hard to find. One thing to note is that shaders produced in RenderMonkey often refer to the viewprojection matrix rather than the worldviewprojection matrix. You usually need the latter for use in DBP (and FX composer). There will be some other related changes as well. The following variables, taken from the same shader, are variables you would usually want to vary in your DBP program: + Code Snippet The values given are just default values used by the shader. To change those values in DBP you would use commands such as set effect constant vector and set effect constant float. Hope this helps. |
||
| Back to top |
|||
|
dab
User Joined: Wed Sep 22nd 2004 Location: You Temp Folder! |
Where are the shaders located? Edit: The Download That is. I can't seem to find it in any of the Ultimate Shader Threads. Edit2: Found it. http://forum.thegamecreators.com/?m=forum_view&t=79849&b=8 (Thread) http://cordierfr.free.fr/UltimateShaderPack1.0finale.zip (Shaders) Uhh. I'm too lazy to fill this in right now. When I get the nvidia game further into working, I'll add a post to it. |
||
| Back to top |
|||
|
sett
User Joined: Sun Sep 19th 2004 Location: somewhere in my mind... |
How can I have the fire sahder from the fx composer shader gallery. They say that the sample come with fx composer but there is no sample at all. ![]() Windows XP,pentium IV, 3.0 MGZ, 1024 mb memory, 256 mb ATI Radeon PCIE X700 Pro 'sett squadron back on the assault' |
||
| Back to top |
|||
|
Michael S
User ![]() Joined: Sun Apr 2nd 2006 Location: Why do you ask? |
|
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Basically a tiny little program that runs on an individual pixel (or vertex), to produce an effect. They are written in a language specifically designed for GPU hardware, so they are incredibly fast at doing things that would take a long time on a CPU. ----------- Thanks GG, helped a lot. -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
In the Fresnel Water shader, what does the clipping do (set camera clip)? It appears to do nothing, is it just an optimisation? ------- Oh wait I get it now. It's so refraction camera only sees stuff below the water, and the reflection only sees stuff above the water. -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Raven
User Joined: Wed Mar 23rd 2005 Location: Hertfordshire, England |
Probably just an attempt at optimisation, as shaders work based on the screen-size. The smaller, the better they perform. I mean you're no doubt going to expect more 3D work at 1280x720 than you would at 640x480, however let's say you have a normal mapped plane in the center of the screen that takes up 100x100px With a 3D Texture, all it would do would be to stretch it across the surface meaning you end up with a blurred 1:1 at the higher resolution. A shader however will work in the additional pixel space making the normal mapping much better, and you'd end up with a 1:1 at 640x480 and 2:1.3 at 1280x720 Hopefully that makes sense. Intel Pentium-D 2.8GHz, 512MB DDR2 433, Ati Radeon X1600 Pro 256MB PCI-E, Windows Vista RC1 / XP Professional SP2 |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
? Umm, what? I already figured it out. ^^^ I had nothing to do with what you said... It just sets the draw distance, essentially, of the cameras. ----------------- Is 1280x720 720p widescreen? ie. 360 standard? -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Gamefreak
User Joined: Sun Jun 20th 2004 Location: Cyberspace |
Is there anyway to update my shader version, like to 2.0? My graphics card doesn't support a lot of the shaders in the pack. |
||
| Back to top |
|||
|
Google Ad
AdBot Joined: Aug 26th 2002 Location: Everywhere |
|||
| Back to top |
|||
|
MadrMan
User Joined: Sat Dec 17th 2005 Location: 0x5AB63C |
|
||
| Back to top |
|||
|
Raven
User Joined: Wed Mar 23rd 2005 Location: Hertfordshire, England |
Quote: "I had nothing to do with what you said...
It just sets the draw distance, essentially, of the cameras." :shrugs: I was taking a guess, as I didn't have the USP to check. Do now, and the Fresnel Shader looks like the NVIDIA ASM one converted to HLSL. Seems a very silly way of doing it as performance is being lost by letting DBP do aspects that should be internal to shaders. Still does the job I suppose. Quote: "Is 1280x720 720p widescreen? ie. 360 standard?"
Something like that, yeah. It's a resolution that's been around before HD though What I ment above is that the rendered pixels for the texture, on the first example it's 1:1 meaning 100x100px output, then it's stretched over the surface. For the shader example 640x480 is the original size so again it's 100x100px, yet 1280x720 is larger so the shader rather than doing it's 1:1 does a 2:1.3 (in relation to the screen ratio) so the texture ends up being 200x130px rather than stretching. So it's doing alot more work with the fill-rate but also on the gpu itself. This is also true when considering a shader like HDR or Bloom. Generally a way around it is to use a shader quad (shader created quad that sets the screen sampler size output) that way no matter the resolution the shader doesn't slow down... on the negative side no matter the resolution the shader output will always be the same, which can mean HDR might end up being a much lower quality aspect than say Normal Mapping. Also a better solution for the Fresnel Water, or any Reflect/Refraction is to use the Shader itself to determine the clipping surface using an emissive level, which will allow anything above the water to be classed as something different to below. another (and tbh easier method) is to use a cubemap (or even single camera dp reflect vector from eye) passed by dbp for the reflection and use the scene itself for refraction. Either method will provide much quicker and more impressive results. ^_^ Intel Pentium-D 2.8GHz, 512MB DDR2 433, Ati Radeon X1600 Pro 256MB PCI-E, Windows Vista RC1 / XP Professional SP2 |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
@sett (and anyone else interested) Quote: "How can I have the fire sahder from the fx composer shader gallery. They say that the sample come with fx composer but there is no sample at all."
Here's a fire effect shader plus demo DBP program in a zip file you might like to try. You need a ps2 capable GFX card. When you run the program, just press "2" to get the fire effect. Let me know if you have questions or problems with this. |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Has anyone managed to get other shaders working with the Fresnel water? I think it takes complete control of what goes into the backbuffer, basically. I can't get HDR to work with it, and I think it's because of this. The 'post' effects like HDR need to work on the image once it's had the water effects put in. -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
headcrab 53
User ![]() Joined: Thu Jul 14th 2005 Location: Cyberspace |
|
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Ummm, it's the Fresnel Water shader. It's in the shader pack, called, wait for it, Fresnel Water. --------------- I managed to get bloom working with the water. It doesn't work on the actual water, which I kind of expected, but it still looks good on the rest of the enviroment -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Turoid
User Joined: Sat Nov 1st 2003 Location: The Netherlands |
Hi guys, I was playing around with the shader pack to see if I could manage working with shaders for the nvidia comp. Now here, I made a plain and moved with the camera around it. As you can see in the far right corner it seems that it just dissapears when the camera comes close to it, but not in the other corners? I hope this is fixable actually.. I guess there's nothing wrong with the shader. Click the download butten for the video. Thanks |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Had a quick look. I see what you mean. Will try to reproduce the problem myself (shouldn't take long). I suspect it's an object culling issue - but I'll check. P.S. Thanks for posting here. It would be great if everyone else with competition related shader queries did that. Then everyone benefits. |
||
| Back to top |
|||
|
Tinkergirl
User ![]() Joined: Tue Jul 1st 2003 Location: United Kingdom |
|
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Sorry, couldn't reproduce your problem. The following code worked fine for me: + Code Snippet I changed the shader slightly so it explicitly declares the textures - shouldn't be relevant to your problem though: + Code Snippet |
||
| Back to top |
|||
|
Turoid
User Joined: Sat Nov 1st 2003 Location: The Netherlands |
I used the inbuilt DB plain primitive, but I rotated it and fixed it's pivot. [EDIT] I tried making a new project with the same code and it seems that it works fine therE? ?? :S |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Here's a simple reflection shader plus demo program people might like to play with. The cube map was made from images taken with cameras in another DBP application. You can move around using the up/down keys and mouse to change direction. |
||
| Back to top |
|||
|
Cave Man
User ![]() Joined: Tue Aug 22nd 2006 Location: North Carolina, US |
Thats a nice shader. I've got a question. What does the mul function do? ![]() |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
The mul function is used to multiply a vector by a matrix - often used in shaders to convert from one coordinate system to another. For example, position coordinates of a vertex are input to the vertex shader in object or model coordinates (the same ones you would see in a mesh in DBP. However, other things like camera position are passed in "world" coordinates, and to show things on the screen you need "view" coordinates (i.e. relative to the camera) and finally a "projection" to the screen coordinates. Hence shaders will often refer to 4x4 matrices such as WorldViewProjection which is a combined matrix giving the transformation of object coordinates to the screen, i.e. object -> world -> view -> screen projection. Hence the following code snippet from my reflection shader is transforming input object coordinates into output screen coordinates. In the shader I have given the matrix WorldViewProjection the shorter name wvp for convenience. + Code Snippet Hope this explains a bit. |
||
| Back to top |
|||
|
dab
User Joined: Wed Sep 22nd 2004 Location: You Temp Folder! |
@Green Gandalf Your reflection shader doesn't do objects in the scene. Only the outside, cube. 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 |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Yeah that's for speed. Not everyone has a computer fast enough for real time reflections, these are prerendered. It looks very good for how cheap it is. -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Quote: "Your reflection shader doesn't do objects in the scene. Only the outside, cube."
Yes, as Chris K says, that was done for speed. Real-time reflection rendering of the whole scene using set camera to image, etc, can slow things down enormously. Of course, you have to stop somewhere anyway - in a real-world version of my shader you would want a potentially unlimited sequence of reflections of one object in another. But how would you get that? To get visually interesting effects and acceptable game speed you need to make a few compromises or approximations. I think several of the shaders in the Ultimate Shader Pack could do with reworking for speed with that in mind. Quote: "Thats a nice shader."
Quote: "It looks very good for how cheap it is."
Thanks, guys. I'll keep posting simple shaders like that in case someone wants to use them. [Edited typo.] |
||
| Back to top |
|||
|
Cave Man
User ![]() Joined: Tue Aug 22nd 2006 Location: North Carolina, US |
Thanks Green Gandalf. Can you make a simple shader that just turns all the pixels one color so i can learn? Thanks. ![]() |
||
| Back to top |
|||
|
Chris K
User Joined: Tue Oct 7th 2003 Location: Lake Hylia |
Here you go Cave Man: Shader (save as MyFirstShader.fx): + Code Snippet DBPro code: + Code Snippet -= Out here in the fields, I fight for my meals =- |
||
| Back to top |
|||
|
Green Gandalf
Valued Member ![]() Joined: Mon Jan 3rd 2005 Location: Cornwall UK |
Quote: "Can you make a simple shader that just turns all the pixels one color so i can learn? Thanks."
Try the attached. I'm going to add to this in response to questions on this thread - time permitting of course. Thanks for the nudge - I've been meaning to do this for a while. [Edit: someone beat me to it while I was tinkering with the code! Serves me right for being too fussy!] [2nd Edit: Changed the name of the zip folder so it doesn't refer to "Tutorials". That will come later when I've added explanations and more examples. There's only one shader in there at the moment. More will follow.] |
||
| Back to top |
|||
This is a multi-page thread older than 30 days.
Go to the last page to check if you can reply to it.
Go to the last page to check if you can reply to it.
Forum Search
Enter a word or phrase to search our Forum for:
|
|



















