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: 16th Feb 2010 20:42 Edited at: 16th Feb 2010 20:52
I haven't come across the phrase "dynamic function pipeline" - unless it refers to shaders.

I'm not sure what the "fixed" refers to. I assume it refers to the fact that, before shaders, you were limited to the "fixed" functions available in DX such as the 8 texture blending stages, the render states, etc. Shaders allowed you to change anything you wanted to (within rather wide constraints).

But I'm guessing, as usual.

Edit

Quote: "Is that teh dynamic function pipeline allows you to do dynamic conditional shading? "


Possibly, but I suspect it's more along the lines I suggested above. But I don't know for sure (rushes off to do a Google ...).

Edit2

Just looked in a couple of books ("Book? Book is stupid" ) and it seems the distinction is between the the "fixed function pipeline", i.e. DX states etc, and the "programmable pipeline", i.e. shaders - which I suppose you could call "dynamic". I suspect the "conditional" thing is something quite different and depends on your graphics card.
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 16th Feb 2010 20:57 Edited at: 16th Feb 2010 21:12
Yes thats is my question. I confused, programmable with dynamic.
Just fixed my mistake above

[EDIT] I think teh difference is pretty clear in teh following articles, and is different from what im saying

http://code.google.com/apis/o3d/docs/programmablepipeline.html

http://en.wikipedia.org/wiki/Shader
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Feb 2010 21:24
Yes.

[Weird: I'd have put money on the fact that I'd copied and pasted your wikipedia link but up popped the other one. Perhaps my blood sugars are getting low ... ]
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 17th Feb 2010 00:50 Edited at: 17th Feb 2010 00:51
The fixed function pipeline is basically how you render things with native directx commands. State changing, blending, lighting, stuff like that (anything that has to do with final GFX output). Shaders, are dynamic, they allow you to do whatever you want. Keep in mind however that the FFP is optimized (years of refinement), and the shaders you create are only as good as you can make them. Also, think of the FFP as one giant shader, that you can basically turn flags on and off with, using D3D commands.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 18th Feb 2010 07:46
Hello guys,

is it possible to create a metal shader, to reflect environment ( objects in scene )? i've seen evolved's glass shader, changed some code to remove refraction, now it just reflects the skybox, here's evolved's shader:


so what should the reflection shader do to reflect everything in the scene, not just the skybox? also, this shader reflects the skybox just as it is, how can i make something like alpha for the reflected color?

oh and, this is just for learning purpose, not for using in a program or such

thanks in advance

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 13:29
Quote: "so what should the reflection shader do to reflect everything in the scene, not just the skybox?"


Nothing.

Your DBPro program needs to supply the shader with suitable cube map images. This is usually achieved using 6 cameras and combining the 6 images into a cube map which will be one of the textures applied to the object with the reflective surface. I'll try to dig out a demo which shows Lee's method and my method which uses Dark Shader commands. I prefer mine, Lee prefers his.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 14:12 Edited at: 18th Feb 2010 18:08
Here's the cube mapping demo. It's a modified version of one that Lee put in a Newsletter (I think ).

Here's a screenshot:



Lee's method runs at about 200 fps on my machine, the Dark Shader (DS) method runs at about 185 fps. On the other hand the image quality of the DS method seems better - but I don't see why, might be a glitch on my machine. Perhaps some of you could report your findings?

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: 18th Feb 2010 14:17
Screenshot for previous post using Dark Shader commands.

Attachments

Login to view attachments
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 18th Feb 2010 14:18 Edited at: 18th Feb 2010 14:19
well, I certainly like the dark shader method better, considering the statue is black with Lee's...

my graphics card is a geforce 6200, a little bit outdated.

[edit] actually, something else is up, there's no reason for cube mapping not to work, ive used it before.

Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 18th Feb 2010 14:51
GG,
I see same FPS in both images are they the same?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 15:34
Quote: "are they the same"


The images should be - but are not on my machine. I don't know about the fps though - since the camera method is different one might be faster. The DS method creates and then deletes a temporary camera so that could be one reason for a slight slowdown.

thenerd

Try reducing the image resolutions used for the cameras.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 18th Feb 2010 17:01
woah, cool, thanks for the help Green Gandalf, tho, it's a pain to convert dbp code into dgdk ( which i use ), so mind making an exe?

by the way, that shader kinda confuses me, can you comment each line explaining what are we doing in it?

thanks once again

Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 19th Feb 2010 01:00
Hey guys,

I hate to post something so trivial, but I've been staring at this forever and can't see what I'm doing wrong. I'm trying to convert the angle between the normal and the viewing vector into a texture coordinate. It works fine until I move the object.

I'm pretty sure I'm using the wrong transformation for something, but it's been ages since I've done this stuff and it's all a little hazy. Here's my shader code:



And here's a screenshot of what's happening. All three spheres should be highlighted like the middle one.



I've included the project and everything necessary to run it if anybody wants/needs it as well. Thanks in advance.

-Frank

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: 19th Feb 2010 01:55 Edited at: 19th Feb 2010 01:56
It's too late for me to look into this properly tonight, but the following jumped out at me. Shouldn't both the normal and view vectors be float3's not float4's? I think you just want the xyz components for direction vectors - especially when you are normalizing them.

Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 19th Feb 2010 02:10 Edited at: 19th Feb 2010 12:13
Thanks GG,

That didn't fix the main problem, but I hadn't even realized I'd done that until you pointed it out.

-Frank

[edit]

It appears I fixed it. When I was calculating wNormal I was multiplying the incoming normal by the world matrix. It seems I need to multiply it by the world inverse transpose matrix instead. I've forgotten why that is, but it seems to have worked. Now I just need to actually buckle down and learn this stuff instead of guessing.

Also, if you spot any other errors let me know. The math is coming back to me, but much of this shader stuff still seems like magic to me.

Oh, and here's a screenshot of the shader in effect on an army of the Colonels from FPSC:



Cheers, and thanks for the help and support!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2010 12:27 Edited at: 19th Feb 2010 12:48
Edit

Comments deleted because I misread your texture stages. Will post back after I've had a closer look.

Edit3 ()

I think your confusion with floats was the main problem - unless I've misunderstood what you are trying to do. Is this any better?





Edit4

Final edit I hope.

Are you sure that image is right? Do you want the fading on the edges of the spheres to look exactly the same regardless of the spheres position in the screen? If so, then you need to modify the view vector before using it.

Attachments

Login to view attachments
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 19th Feb 2010 13:16
Hello guys,

i'm really wondering how textures works in shaders,in the shader posted above by pharoseer,


here, you tell the shader that will have a texture? ok, how does it know what texture are you talking about? i mean, we didnt pass an image name or something, how does it know? is it modified inside you program?

The Slayer
Forum Vice President
15
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 19th Feb 2010 14:11 Edited at: 19th Feb 2010 14:14
Quote: "This is usually achieved using 6 cameras and combining the 6 images into a cube map which will be one of the textures applied to the object with the reflective surface."


@Green Gandalf, I did some experimenting on your code (if you don't mind?), and it seems that you don't need all six camera's?? I changed the for/next loop to this:



And the sync mask just before the last sync mask, I changed to this:



And the result is the same, so WHY make six camera's if you don't need them?

Cheers

Slayer rules!!! Yeaaah, man!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2010 14:20
Did you use the other method by mistake, i.e. usingdarkshader=1 rather than 0?

Your code doesn't work if you try to use it.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2010 14:25
Quote: "how does it know what texture are you talking about? i mean, we didnt pass an image name or something, how does it know? is it modified inside you program?"


Answering your questions in turn:

1. The DBPro code in Pharoseer's download says:



That's telling DBPro to assign image 1 to stage 0 and image 1+i to stage 1. DBPro then assigns the stage 0 texture to the first texture declared in the shader, stage 1 to the second and so on.

2. We did pass textures to the shader as described in 1.

3. Yes - see Pharoseer's dba file.
The Slayer
Forum Vice President
15
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 19th Feb 2010 14:32 Edited at: 19th Feb 2010 14:34
Quote: "usingdarkshader=1 rather than 0?"


Yeah, I see what you mean.

So, usingdarkshader=1 , is Lee's method, and usingdarkshader=0, is yours?
When I set usingdarkshader=1, I get 130 FPS, and the other method I get 223 FPS. So, the one using the six camera's, is faster?? I thought that shaders where better to use when it comes to speeding up the games?

Thanx

And cheers

Slayer rules!!! Yeaaah, man!
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 19th Feb 2010 14:37
@GG,

I compared your code to mine and realized I'd changed everything to float3 except in the a2v struct where the normal was still a float4. I'm guessing using the world inverse transpose (worldIT) might have corrected for this? Using worldIT is normally meant to correct for non-uniform scaling issues isn't it? Not sure how it would have helped, but apparently in my case it did.

Also, I'm not explicitly casting the world matrix as you do in the following line:



Are there potential side-effects to not doing so or is it more of a best practices thing? Either way, I think it's a habit I'll adopt. I think it makes the code more readable.

As for your understanding of what I was trying to do, you seem to have hit the nail on the head. Your picture is exactly what I was shooting for. I'm happy that it's working now and thanks to you I have a better understanding of what I was doing wrong. Thanks again for your help.

-Frank
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 19th Feb 2010 15:27 Edited at: 19th Feb 2010 15:47
@Green Gandalf
Alright that makes sense, thanks dude!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2010 15:37
Pharoseer

Quote: "I'm guessing using the world inverse transpose (worldIT) might have corrected for this?"


I very much doubt it - WorldIT is merely the transpose of the inverse of the world matrix. The world inverse matrix is used if you want to work in object space rather than world space coordinates which, as you say, you might occasionally need to do if the effect is tied to the original scaling.

Quote: "Not sure how it would have helped, but apparently in my case it did."


Which - the worldit matrix or the solution I suggested?

Quote: "I think it makes the code more readable."


Yes, I find it helps to reduce errors too.

I'm not sure what happens when variables get defined as float3 in one place and float4 somewhere else. I assume that the three floats sometimes get aligned with the three you want but not necessarily. Could be that the whole set of input/output structures get misaligned, but I'm not sure. Best to be safe and be consistent.

Quote: "Thanks again for your help."


You're welcome.

The Slayer

Quote: "So, usingdarkshader=1 , is Lee's method, and usingdarkshader=0, is yours?"


No, the other way around. I used Dark Shader.

Quote: " So, the one using the six camera's, is faster??"


Apparently. As I said in an earlier post I'm not sure why:

Quote: "since the camera method is different one might be faster. The DS method creates and then deletes a temporary camera so that could be one reason for a slight slowdown."


Shaders usually slow things up because people use them to do something the standard fixed pipeline can't - but in this instance both methods use the same shader. The difference is the way the cube map is constructed.
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 11th Mar 2010 16:44
hey. i am working on a space exploration game. it includes at least the nearest 50 galaxies, hundreds of stars, planets and other satelites and asteroid fields, nebulae. also, you are able to land on (or fly around on) planets and explore them. you can take scientific readings and there is some combat

i have much of it done, but i haven't spent any time on finalized graphics yet, as i know nothing about making shaders but need to learn. all teh models and textures are placeholders

so i have two questions. 1. how long would it take to learn the core basics of making shaders? EG if i need to be able to make a transparency shader (since DB transparency appears...crazy) for glass and clouds and nebulae and corona (stellar atmosphere) and atmospheres... a shader to make my stars really shiny and lava-y and cool... shaders for buildings and vegetation and geography of planets... shaders for planets themselves (EG i would like an Earth that has a nighttime side shader and a nice looking sea shader etc)

i don't need my game to be as graphics intense as current games. but from what ive seen the difference between a shader game and a game without shaders is so huge that it'd be easily worth the time to learn how to use these, especially since wandering around the universe is a big part of my game and beautification is thus pretty important to gameplay.

my second question is either A) where can i find a really useful (but not too long) document to get the basics i need, andor B) anybody want to spend an hour or so with me and teach me? feel free to hop on board with the project, too. of course, i'd send what i have so far so you could check it out and see if you want to help, andor C) should i just use pre-made shaders that are already out there? are there more than enough for my purposes, and are they free?

i lied, i also have a third question. i have DarkSHADER... will this let me create shaders, or is the product basically just a set of premade shaders and nothing else?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Mar 2010 01:18
Quote: " i have DarkSHADER... will this let me create shaders, or is the product basically just a set of premade shaders and nothing else?"


I think I can safely answer that at this hour. I use Dark Shader all the time for testing and debugging my own shaders. Fine tuning usually takes place after testing in the Dark Basic application itself - but initial development is almost invariably in Dark Shader first. I sometimes look at the premade shaders for ideas, but mostly I develop my own now. Every shader I write is tested in Dark Shader before being used by DBPro - you'll be surprised how many trivial "improvements" fail because of a stupid missing semi-colon. Best to give DBPro a shader that compiles if nothing else.

Quote: "my second question is either A) where can i find a really useful (but not too long) document to get the basics i need"


See the suggestions Chris K included in the first post on this thread. I find the MS DX9 SDK docs very useful now - but would probably have been put off if I'd started with those. It's well worth spending some time with a good book - and there are many on shaders around now. Look at the reviews before getting a copy.

Quote: " how long would it take to learn the core basics of making shaders?"


Not sure I can answer that - depends on how good you are at 3D maths. The MS DX9 SDK has a good section on that - and it's free (all you need is lots of patience while it downloads).
CSGames94
16
Years of Service
User Offline
Joined: 27th Dec 2007
Location:
Posted: 1st Apr 2010 22:25
Hey Guys,

Been building a team to work on a new football game for the pc, and I'm in need for someone that is very good with shaders to help with the game's graphics. Here are some links to the main thread and the website for the game.
http://football-freaks.com/forums/index.php?showtopic=31674&st=0
http://csgm.webs.com/cflsimulationfootball.htm

Thanks!

The Pokemon Engine is still alive.
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 10th Apr 2010 05:17 Edited at: 10th Apr 2010 05:27
Hey guys. I'm currently learning shaders. First thing i'd like to ask is, is there any way to access object number from within the shader? Or a way to attach extra data variables to your object that gets sent to the shader?

What I want is a shader that has many lights, and only use the closest, say 8 lights to each object, for that object. I'd calculate which lights to assign to each object in DBP, then i'd want to pass to the shader the position, colour etc of all the lights, and for each object, a list of which 8 of these to use. I'd also like to pass say an ambient light gradient vector for each object.

The problem is, i can't see how to access object ID from inside the shader. I could maybe cheat by using some unused data that the shader can access but doesn't have to be used for it's intended purpose, like object diffuse or something, but that would be pretty inelegant.

I could use a different effect for each object, but that would require a lot of loading, and also presumably it would take up more memory.

If somebody has the solution, please tell. No real hurry though. I have plenty of shader stuff still to read.

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 14th Apr 2010 04:47
Anyone know if there's any way to copy shaders? I want to be able to send object specific info to the shader, so need separate (but otherwise identical) shaders for each object.

Trouble is, because it seems shaders are compiled at runtime, loading them is hella slow. If I want 200 objects, it'll take a minute to load their effects! A "copy effect" command would be very useful. Any DLLs avaliable for this? Or do I just need to update DBP?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Apr 2010 16:32
I usually do this using a special "lookup" texture - just store the info you want per object in a separate texture per object and you're done (almost).
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 14th Apr 2010 19:29 Edited at: 15th Apr 2010 06:42
Aha that's cunning. Thanks. I'll give that a bash. BTW your example shaders in this thread have been really useful.

I got a simple diffuse directional light/ ambient skylight shader working. Compared to default vertex lighting on a standard DBP sphere, it looks way smoother.

Edit: I've added a point light. And it looks totally sweet!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Apr 2010 13:32
Sounds good. Any chance of letting us see it?
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 15th Apr 2010 18:48
Here's my fx file. You might recognise some of the comments.

I'd post my DBP test prog but it's a mess and needs media.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Apr 2010 20:31
Quote: "You might recognise some of the comments."


Yep. Glad you've found some of the demos useful.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 16th Apr 2010 09:11
i am using the infamous LAVA shader that came with one of the dbpro demos.

i would like to set an alpha value to make it somewhat semi transparent. setting the alpha of the object does nothing, so i suppose that the only way is to change the shader code. am i right?

i have no experience with shaders, so would this involve just changing a couple of lines, or a total re-write?

thanks a lot
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 16th Apr 2010 09:13
dbpro 7.5 will introduce new commands to make fullscreen shaders possible with just a couple of lines of code.

will this make more generic shader code (like the ones found on the nvidia site) work AS IS, without changes? Or will this never happen in dbpro?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Apr 2010 15:03
Quote: "so would this involve just changing a couple of lines"


Probably.

Post the shader and I'm sure someone will suggest suitable changes.
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 16th Apr 2010 19:47
I think you need to change some code in DBP. IIRC, you need to set alpha mapping on for the alpha texture channel to work.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Apr 2010 20:43
Or do you mean set object transparency?
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 16th Apr 2010 21:11
set object transparency does not work as i already mentioned
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 16th Apr 2010 23:05 Edited at: 16th Apr 2010 23:16
I realise I misread the original question!

The pixel shader outputs the colours of the pixels, including the alpha value of each.

I'd say put the alpha as a "tweakable" (declare it at the start of the shader like

float my_alpha =1.0f;

then at the end of the pixel shader, do something like

Colour.a = my_alpha;

Perhaps it's possible to output colour as only a float3, and have the alpha take the default behaviour as you set it in DBP, but i'm just guessing, and it's probably nicer to have it all together in the shader so you can see what's going on.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Apr 2010 00:55
Quote: "set object transparency does not work as i already mentioned "


Yes it does if used correctly - and it is essential.

Have a look at the attached project and see what happens when you comment out the set object transparency line.

The shader is setting the alpha level and alpha blending - but set object transparency is needed to make sure the semi-transparent object is rendered last.

Attachments

Login to view attachments
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 17th Apr 2010 05:51 Edited at: 17th Apr 2010 06:25
I've been playing around some more. Now got (tangent space) normal mapping to work with my current shader.



Took some of the code from an example by evolved. It's got the ambient skylight, a directional light (like the sun), and obviously the blue point light. Not crazy fast, but there are some optimisations i can try. I notice evolved uses a lookup texture for normalisation. Seem unintuitive but maybe i can get some speed there.

Here's the shader if anyone's interested. It may be hella inefficient. If anyone has ideas please say.




I had a eureka moment whilst boiling the kettle - i could make a terrain shader for my game with automatic wrapping off the heightmap, level of detail etc, just by tweaking uv co-ords, and it would be fast and awesome. Then I checked on here and it's been done a million times before. So less braggable, but proof that it's going to work and be awesome.

Edit: just realised i can do shadows from non moving stuff (like terrain or the planet in asteroid worlds) without requiring realtime rendering of the shadow z-buffer thing. I'm totally going to do a shaders version of asteroid worlds. Only trouble is there aren't enough hours in the day!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Apr 2010 13:48
Looks good.

I might have time to look at the shader code later today.

Quote: "I'm totally going to do a shaders version of asteroid worlds. Only trouble is there aren't enough hours in the day!"


I know the feeling. As soon as I realised what you could do with shaders I was hooked.

Quote: "I notice evolved uses a lookup texture for normalisation. Seem unintuitive but maybe i can get some speed there."


I think there's a rough rule of thumb which says if you can save 3 arithmetic instructions then it's worth looking up the result in a texture instead. EVOLVED's normalisation lookup is probably a borderline case - but the basic idea can speed up shaders a lot when maths functions are needed. A good way to tell is to inspect the asm code listing (available in DarkShader for example). These optimisations soon mount up if you have a complicated high resolution scene to render with shaders - the critical area is the pixel shader.
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 17th Apr 2010 18:24
The texture for normalisation is just completely outdated in my opinion. It comes from when the normalisation function wasn't available in pixel shaders.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Apr 2010 18:54
NVIDIA's latest version of FX Composer still includes it.

Perhaps they forgot to delete it?
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 17th Apr 2010 20:11
GG, yes your example works because there is alpha code inside the shader.

the lava shader i have (your own Scrolling Lava shader) does not have any alpha code inside the shader, so i suppose unless i add that to the shader code, there i no hope to set alpha from just dbpro
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Apr 2010 23:01
Quote: "so i suppose unless i add that to the shader code, there i no hope to set alpha from just dbpro"


Exactly. (Although it might be possible using the set blend mapping on command with suitable images . I haven't tried - I find shaders much easier. )

Have a go at adding it to the shader yourself and if you get stuck post back. How were you thinking of setting the alpha?

Hopefully either my sample shader or Dr Tank's comments will give you a clue as to what is needed.
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 18th Apr 2010 05:34 Edited at: 18th Apr 2010 06:43
I found a cool trick that came in useful. If you don't want minimum camrange clipping (where stuff is too close to camera and you can't see it), put

Out.Pos.z=max(0.0f,Out.Pos.z);

in the vertex shader. I guess you could use saturate to avoid max camrange clipping too.

Currently making a shader for my spherical portal thing. Is much smoother than it was, which is cool.

Want to use realtime cubemapping like demoed in last September's newsletter. http://www.thegamecreators.com/pages/newsletters/newsletter_issue_80.html

I downloaded it, and the .exe works fine. However, if i compile a new .exe from the project, the shader is just black. Think I need to update my version of DBP (currently 1.066). Will try that in the morning, after backing up my projects of course! Anybody know if it will be possible to return to my current DBP version if my projects stop working?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 18th Apr 2010 18:04
just rename your current dbpro directory, intall new version, and if you don't like it, rename back your old dbpro directory

Login to post a reply

Server time is: 2024-11-23 23:27:04
Your offset time is: 2024-11-23 23:27:04