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
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2004 02:13
"The only shaders you can't get to work right now are the ones that generate procedural textures."

Do you mean blending multi textures together? I know how to do that. What do you mean?

All you need is zeal
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 19th Jul 2004 02:55
@Zeal

"Do you mean blending multi textures together?"

No. I mean a shader that generates a texture then uses. Like the metallic flakes shader discussed earlier or a wood or marble shader. Like these ones for example:

http://www.ragehdtv.com/developer/samples/dx9/HLSL_NoFX.html
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2004 04:36
Ah ok. Hey neo while I have your attention maybe you can help me with this shader im working on. Im trying to blend different textures together based on the rgb values of a blend map. Works great for blending based on the red value of the blend map, but ive been unable to get the fourth texture to blend in based on the green value. After that works id like to add a 5th texture and blend it in based on the blue value. (perhaps ill even add a 6th and blend it based on alpha, who knows).

Thanks again to ideajuice he deserves credit for this shader

All you need is zeal
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 19th Jul 2004 08:42
Sure. I could give it a go later on. Right now I have some programming to do however.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 20th Jul 2004 03:28 Edited at: 20th Jul 2004 03:29
Hold on neo might have a different task for you . Here is the problem...

Im applying this shader to a huge terrain chunk, so in order to get any kind of detail out of my textures I have to shrink them down dozens of times. This looks ok up close, but as you look out into the distance you notice very quickly those 256x256 textures are being mipmaped into a single pixel very quickly (because they are scaled so small). Thus, while the chunk looks very detailed below your feet, it starts to blend together as a SINGLE SOLID COLOR farther out.

Now, im guessing this is just unfortunate result of shrinking/scaling a texture that many times and mipmapping. So, I started thinking, maybe it would be best to do a base low res map (maybe 256x256 of grass and dirt stretched over the entier object). Then, rather than using one detail map to add detail to the entire chunk, perhaps we (by we I mean you neo ) could revise the shader so that it blends different DETAIL MAPS together. That way we could have a detail map for grass, one for rock, ect... This seems like it would solve the problems from my original method (no more single solid colors filling the distant areas).

What think?

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 20th Jul 2004 14:43 Edited at: 20th Jul 2004 14:44
After giving it some more thought, it should be a simple matter of first getting a % based on the red value of blend map (texture 0). Then multiply that by the first detail map (texture 2). Now we should have a black/white value 0-255 that we can (add/multiply?) to texture 1. Sounds correct in theory right? Or am I missing something?

Also ill still need to figure out how to repeat the process 3 more times for the green, blue, and alpha channel.

Thanks a ton for any help!

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 21st Jul 2004 12:51
Hmm it seems I AM missing something. I tryed modifying the shader to work as a detail mapper and im running into a slight problem. If the red value on the blend color map is 255 then the detail map doesnt just effect the base texture it replaces it! So you get a grey detail map with no color, icky. So how should I modify this line to 'darken' the base texture?

//tex 1 is the color blend map (used to tell which detail map will be used), 2 is the base texture layer (low res colors for grass/dirt) and 3 is the detail map itself.

float3 blend = tex2D(Sampler1, Tex);
return ((tex2D(Sampler3, Tex3) * Diff + Spec) * blend.r) + ((tex2D(Sampler2, Tex2) * Diff + Spec) * (1. - blend.r)) ;

All you need is zeal
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 22nd Jul 2004 09:58
@Zeal

I'd like to help you out, but unfortunately I'll be gone on vacation for eight days starting tomorrow without a computer. So I probably won't be able to help you finish that shader in time before I leave.

That being said I can think of a few quick pointers:

1. Try to break up that last return statement into smaller statements. That thing is WAY too long. I'm having trouble reading it.

2. If you are trying to blend textures I suggest looking into the "lerp" instruction. It linearly interpolates two colors based on a third value. Which seems to be exactly what you are aiming for.

If you still haven't solved it in eight days, I'll see what I can do to help. Hopefully, you'll have it working by then though.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 23rd Jul 2004 11:45
Well I read up on the lerp command and its nice, but doesnt do anything new. The problem is I dont want to just interpolated two colors, I want to darken one based on another, based on the intensity of the color map. Thats where im stuck.

All you need is zeal
ALPHA ZERO PRODUCTIONS
20
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Mom ! I forgot where we live !
Posted: 23rd Jul 2004 18:05
i feel stupid

Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 30th Jul 2004 13:43
Well I made a little progress. I got the shader to darken the base texture according to the color map. It still looks a little off, but I think thats because its adding EVERY color above 0 (greys, ect..). Anyway, im now starting to think of my next problem.

Im using this shader on the 4 'center' terrain chunks so they are always surrounding the player/camera. Problem is, you can see a defined line along the border of the 4 shaded/non shaded terrain chunks. So I was thinking I could do two things...

1.) Manipulate the 'blend' map image via memblocks so that it only had colors in a radius around the player. The rest of the image would be blank so the shader would perform no blending.

2.) Somehow tell the shader to only perform blending in a small radius around the player. This would have to be done in the fx file itself, and I have no idea where to begin there. Perhaps could I use black fog?

It seems like option 1 would be easier, but slower than option 2. Any advice would be very much appreciated.

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 4th Aug 2004 04:25
Think ive run into a new problem (what a surprise). Im kinda torn now, so I could use some advice. You see, if I 'splat' detail textures onto a low res base texture (with colors for grassy areas, rocky areas, ect) then the splated areas will be much darker than the non splatted areas. This is making me think maybe I should go back to square one and just try and splat the textures themselves.

Whether I decide to splat textures or just detail testures, I still have the same problems as above. While the shader 'works' ok I guess, I still need a way to 'fade out' the effect around the player. Otherwise there is a very defined line along the border of the shaded and non shaded objects.

ALSO I have a request for you mr neo. Since you said you ran into some problems with the next tut, do you think you could put together a simple water fx for us? Please make sure it works with profiles 1.0. Something like the water in Baldurs Gate Dark Alliance 1/2 (a simple sin wave but really cool ripple effects on the texture itself).

Keeping this thread alive as always

All you need is zeal
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 4th Aug 2004 04:59
@Zeal

"2.) Somehow tell the shader to only perform blending in a small radius around the player. This would have to be done in the fx file itself, and I have no idea where to begin there. Perhaps could I use black fog?"

Well, I've just gotten back from vacation recently and haven't really had the time to look this over but I think that this is the best approach for you problem.

I think there is a distance function that's part of the standard library for shaders that will help you with what you need. You could pass the player's position in through a constant(if 3rd person view) or just use the eye position(if 1st person view) and test against each vertex.

" I still need a way to 'fade out' the effect around the player. "

I was looking into something similar for a spot light shader of mine and I might be able to come up with something that could help. However, its kind of different from your shader and I never did get it working. I'll see what I can do later.

"ALSO I have a request for you mr neo. Since you said you ran into some problems with the next tut, do you think you could put together a simple water fx for us?"

I was thinking about doing this myself. There have been a lot of requests lately for a water shader of sorts. I know that there was one that ran on the profile you want that was posted earlier. So I'll see if I can dig that up and explain how to implement it. If I can't find it, I'll just make one of my own.

I'm kind of busy right now so it will have to wait a little while. Hopefully, not too long though.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 4th Aug 2004 05:16
Glad to have you back neo hope you had a nice vacation!

Yeah there was a 1.0 water effect posted awhile back, ive included it in source. However its kinda crappy (no offense to the author). The sin wave seems ok (although it looks like at certain angles you can see some gaps in the mesh), and the texture itself doesnt seem to animate at all. Looks like this one is done with all fancy lighting...

Anyway, the type of water id like to see is pretty basic. I also think its the best water 'style' ive seen in any game (for its simplicity at least). Just want a simple sin wave with a translucent 'ripple/watery' effect on the texture. If youve ever played Baldurs Gate Dark Alliance, D&D Heroes, Champions of Norath (all console games), youd notice they all use a water effect like that. According to Raven....

"The water is extremely simple and hell you don't even need shaders for it... the Water is a simple Sin Peturb, there are some examples around the forum of doing this with matrices; DB Std actually had one showing normalisation which you could borrow.
If you apply the technique to a memblock mesh (Kevil made the dba for this) ... then apply a reflection shader to it."

If that helps any.

Oh and please do let me know if you find a good way to 'fade out' an effect.

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 4th Aug 2004 05:17
Whops here is that 1.1 water effect if anyone wants it..

All you need is zeal
Preston C
20
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 4th Aug 2004 09:18 Edited at: 4th Aug 2004 09:26
Quote: "Yeah there was a 1.0 water effect posted awhile back, ive included it in source. However its kinda crappy (no offense to the author)."


I'm that author, and yes its crappy. But it was back when I wanted TGC to give up the shader pack from DBDN and give it to the community, and back then I didn't know much about shaders (I made this shader by modifying the bubble shader that came with DBP).

...and I still don't know much about shaders. Right now I'm just screwing around and modifying a few shaders here and there. I've managed to get the Simple shader included with DBP to invert the color of the texture and a whole bunch of other things, and thats about it.

Cheers,
Preston

[Edit] Also, heres the post I posted it at if you're curious:
http://forum.thegamecreators.com/?m=forum_view&t=24922&b=2


Intel Celeron 1.3 Ghrz 512MB Ram NVIDIA GeForceFX 5200 128MB
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 4th Aug 2004 10:12
@Zeal:
I'm beginning to get pretty nifty with shaders now - I've recently figured out how to use cubemaps and, even better, how to use the dependent read things with the phase marker!

If you're still having trouble with your terrain shader, I'd be more than happy to have a go at making one for you. Although, you'll have to explain exactly what you want, since your earlier posts are a little confusing!

Here's what I think you're trying to get:

You have a large terrain, broken into chunks. You have a base texture map that covers the whole terrain and provides a base colour for grass, rock, snow, etc. You then apply a detail map, which is tiled several times over the whole terrain. There are many different details maps, up to four, it seems. The intensity of each detail map is determined by a blend map, with each colour channel affecting a different detail map. The blend map is, like the base texture, stretched out over the whole terrain.

Is this right? Correct me if anything's wrong, and I'll make you the shader, so Neo can get on with his next tutorial.

@Alexy Vlasov:
I can do gloss and environment maps now! If you're still interested, I can make you that shiny shader that you wanted!

@Neopyte:
Good to hear from you again, Neo! I was worried this thread would disappear soon...

Anyway, perhaps you could impart me with some of your shadery wisdom: I'm currently driving my GUI through a vertex shader, since buttons and windows fade, blur and glow a lot. Now, I don't have a problem with the shader itself - it's working fine - the problem I've got is that the shader needs to be loaded for each button at the moment. You see, the state of a button is being controlled by a float4 vector, which is different for each button. So, I was wondering if you knew a good way to pass this data into an object without setting any of the constants? Perhaps through assigning the data to texture coordinates?
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 4th Aug 2004 14:55
"You have a large terrain, broken into chunks. You have a base texture map that covers the whole terrain and provides a base colour for grass, rock, snow, etc. You then apply a detail map, which is tiled several times over the whole terrain. There are many different details maps, up to four, it seems. The intensity of each detail map is determined by a blend map, with each colour channel affecting a different detail map. The blend map is, like the base texture, stretched out over the whole terrain."

Yup that about nails it. Ive included the current version of the shader im working with. It kinda works (blends the first detail texture in based on the red value of the blend texture). However, there are a couple problems with it...

1.) I think there is something inherently wrong in my blending calculation ((detail1.r*blend.r) * (tex2D(Sampler2, Tex2) * Diff + Spec)). Just doesnt look right, and im sure im in for trouble when I try and blend more than one texture...

2.) It currently only blends one texture based on the red value. I keep running into problems when I try and add a 3rd/4th based on the green/blue values of the blend map.

3.) Once 1 and 2 are solved, I need a way to 'fade out' the effect in a radius around the camera. You see, right now there is a very defined line along the border of the center chunks with the shader, and those without. Thus I need the shader to fade out (so youre just seeing the base color map) as you look out into the distance.

If you could solve any of those problems I would be very grateful!

Thanks in advance!

All you need is zeal
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Aug 2004 16:08
Forgive my ignorance but how would I go about utilising the fx files in your 'source box'?

I tried copy/pasting to a text file, saving as effect.fx but when I tried to load it in with LOAD EFFECT I was told the file does not exist!

So ... that's obviously not how it's done.

Please share the secrets of your DarkWIZARDRY with us

Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 5th Aug 2004 03:21
Yeah whops thats my bad, I forgot to add a ; at the end of my blend calculation, thus the shader is 'broken'. When you try and run a shader with a syntax error you get a 'shader does not exist' error in dbpro. Try this new one with a ;... Although remember you still need a object with a fvf format that supports 3 textures.

But youre on the right track, all you do is copy and paste the text into a file, save it as .fx, and load it in dbpro. Thats all assuming the author didnt make a goober syntax mistake.

All you need is zeal
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 5th Aug 2004 06:26
@Zeal:
1) I'm not really sure, but the problem could be in the part detail1.r * blend.r. Perhaps it would work if you tried detail1 * blend.r instead...

3) Why do you only apply the shader to the chunks around the player? Is it because you get a tiling pattern or something? I can certainly get around your problem by testing the distance between the eye position and each vertex, then scaling the blend map accordingly within the shader.

There are a couple of things I'd like to ask, though, before I actually get down to work:

What are you doing about lighting? Will the terrain be lit within the program, or would you like me to make some shader-based lighting for you?

Also, about the detail maps, am I correct in assuming that each map is a greyscale image that darkens the terrain it's on? If so, can't all the detail maps be combined into the channels of a single texture? Say, the red channel is the rocky detail map, green is the grass detail map, etc?

If not, how about bumpmapping instead of detail mapping? Bumpmapping's quite easy to do, and would look quite swish too!

One last thing - I'll have to write the shader in ASM, since I don't know HLSL! I'll make sure I comment everything, so it shouldn't be too hard to understand.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 5th Aug 2004 14:28 Edited at: 5th Aug 2004 14:32
"What are you doing about lighting? Will the terrain be lit within the program, or would you like me to make some shader-based lighting for you?"

Funny you should ask about lighting. I REALLY want to say screw vertex lighting and do all my lighting via lightmaps. I really like the extra control you have (mainly for casting shadows) with light maps. BUT as you know dbpros light mapping uses the first textures uv coords, thus does not work.

I was just going to ask if it would be practical to write a simple lightmap shadder and apply it to ALL (256) terrain chunks. Do you think this would be too slow? Should I just wait for U6 to fix dbpros light mapping? Would dbpros lightmapping really be any faster than a simple shader anyway? Assuming I do use lightmapping, please feel free to get rid of all that lighting code in my shader (although if I apply a simple lightmap shader to all my chunks, they will need a fog effect).

"Also, about the detail maps, am I correct in assuming that each map is a greyscale image that darkens the terrain it's on? If so, can't all the detail maps be combined into the channels of a single texture? Say, the red channel is the rocky detail map, green is the grass detail map, etc?"

THATS A GREAT IDEA! Yes the detail maps are just greyscales so I could cram 4 into one! Clever thinking! And if you think you could add bumpmapping that would just add to the coolness factor, go for it!

*edit oops missed one...

" Why do you only apply the shader to the chunks around the player? Is it because you get a tiling pattern or something? I can certainly get around your problem by testing the distance between the eye position and each vertex, then scaling the blend map accordingly within the shader."

I only apply the shader to the chunks near the camera for efficiency. Since you cant really see the detail as you look far off into the distance, there is no need for the shader to be applied to far off chunks. I always assumed this would save precious frames, but if you think you can 'scale' the shader so that it doesnt have to work very hard when rendering distant chunks, then by all means go for it.

Thanks again for your help I really appreciate it!

All you need is zeal
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th Aug 2004 15:47
@Ninja Matt

"You see, the state of a button is being controlled by a float4 vector, which is different for each button. So, I was wondering if you knew a good way to pass this data into an object without setting any of the constants? Perhaps through assigning the data to texture coordinates? "

You could pass the value into a texture coordinate(or the diffuse value or something) assuming you had access to them. Unfortunately, we don't have the ability to do that(yet). There is a work around using memblocks, but I don't think it is worth the hassle.

I'm afraid untill we have proper access to the objects(or Lee/Mike take one of my suggestions to heart and implement a force draw command) there isn't much you can do.
Luminence
19
Years of Service
User Offline
Joined: 31st Jul 2004
Location:
Posted: 6th Aug 2004 04:42
Is their anyway to use render targets with Dark basic pro?
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 6th Aug 2004 11:00 Edited at: 6th Aug 2004 11:31
@Zeal:
Actually, I don't really know much about light mapping, so I didn't know that it used the first texture's coordinates.

Although, why is that really a problem? I'd guess you'd want the lightmap to follow the same texture coordinates as the base colour map, so one lightmap fills the whole terrain, right? If so, why not just add the lightmap into the colour map, so the colour map contains all the shadows that are needed? Of course, the only slight hitch is that multitexturing doesn't work when you're using a shader - the textures have to be combined in the shader itself.

If that's wrong, could you please explain to me what you need with the lightmap?

If that's right, and the lightmap is going to be placed on the terrain in a similar way to the blendmap and colourmap, then it shouldn't be too hard to put something together!

For now, I'll work on a basic terrain shader that includes a single directional light. That'll give you an idea of what the blending and detail will look like without making the shader too complex. After that, I'll add bump and lightmapping, so you can choose which one you think is the best.

One last thing, about the texture coordinates: which set corresponds to each texture?

@Azur3:
Unfortunately, I don't think there is. The best you can do at the moment is to use an extra camera rendering to an image, much like the Glow shader I posted a couple of pages ago. That is, of course, unless they've fixed render targets in one of the latest patches. I'm sticking with 5.2 for now, so I wouldn't know if they've fixed it!

@Neophyte:
Fair enough, I'll just hack something together until we've got better object control then.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 7th Aug 2004 03:43 Edited at: 7th Aug 2004 03:50
"Although, why is that really a problem? I'd guess you'd want the lightmap to follow the same texture coordinates as the base colour map, so one lightmap fills the whole terrain, right? If so, why not just add the lightmap into the colour map, so the colour map contains all the shadows that are needed? Of course, the only slight hitch is that multitexturing doesn't work when you're using a shader - the textures have to be combined in the shader itself."

Well something I should have mentioned earlier, my terrain is huge. There are 16x16 chunks (objects), and each chunk is 500x500 meters in size. That gives you roughly a 3.5km viewable distance, and I MAY even make it bigger. So, each chunk doesnt have its own texture (that would be 256+ textures JUST for base colormaps), but rather 4 or 8 chunks will share one color map. Looks kinda blury but thats where the 'detail splatting' shader comes into play.

THATS also where we run into the lightmaping problem, because the lightmap would also be stretched over several chunks (it must share the same uv data as the colormaps), thus would need to be an INSANE resolution to get any kind of detail. Also, id really like to have different light map resolutions for the chunks closer to the camera, (high res for close, low res for far, so I can get more detailed shadows up close ect...) thus I cant really combine the colormap and lightmap into one texture (*edit well maybe I can hmm...). I suppose having one texture per chunk would solve the uv problem, but I was told that that many images (256+)might hurt performance, true?

*edit About combining the lightmap and colormap into one texture. You see, I really want to manipulate these lightmaps in realtime via memblocks. Kevil wrote a great shadow casting program that did just this, in REALTIME. Check it out...

http://forum.thegamecreators.com/?m=forum_view&t=22229&b=6

Perhaps I COULD combine the base color and lightmap into one texture... I mean if I was using a 256x256 lightmap for a couple chunks I might as well add some color and make it my base colormap too. What think?

"One last thing, about the texture coordinates: which set corresponds to each texture?"

Well feel free to change them (ill bet youll have to), but right now the object texture layers are as follows...

Texture layer 0 = 'blend' map with rgb representing what detail texture will be used. Only used as a reference.
Texture layer 1 = 'base' color map with underlying colors for grass, dirt, ect...
Texture layer 2 = 'detail' map (right now its just a standard greyscale detail map, but could be converted to a 4in1 rgba detail map). This is used to darken/detail the color map.

All you need is zeal
Catalyst
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 10th Aug 2004 16:33 Edited at: 10th Aug 2004 16:34
Okay you shady folk here, how about this one: Rendermonkey. It spits out .FX files, but I think I remember hearing tale that they are not regular .FX files and they don't work in DBP. Is this true, or is there some clever way of getting them to work? When I try loading a Rendermonkey made .FX file, it just says the effect does not exist and spits me out of the program before it even starts. I've reached a level of programming experience to know that this means that something is wrong, and with a bit of luck I might even know what that thing is.

EDIT: I suppose it may be helpful to note, the Ambient Occulsion, Motion Blur and Normal mapping are the three that I would be most happy in knowing how to make them work.
Catalyst
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 10th Aug 2004 17:40 Edited at: 10th Aug 2004 17:59
And just to add more questions, here's another shader I'm trying to make work. It's a normal mapping shader I found some guy posting, and it seems pretty simple. Though I still don't understand that much about shaders, it seems like it should be possible to make this one work in DBP.


Anyone see a way to make this code work? When I try to run it, it says "Effect does not exist", just like the Rendermonkey effects.

EDIT: On this one, I think it has something to do with this:

float4 texColor = tex2D(colorMap);

That's how his code was written, but shouldn't there be some other info in the tex2D area after colorMap?
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 11th Aug 2004 03:00
Wow a normal mapping shader that works on 1.1 profiles cool! I think neo should do a in depth tutorial on this one, just not till after he finishes that water shader tut . Hows that comen neo?

All you need is zeal
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 11th Aug 2004 13:24
@Catalyst:
Yes, normal mapping is quite possible in DBPro. In fact, I've currently got several normal mapping shaders up and running, even ones that use texture dependent reads to fake bumped reflections. Unfortunately, the ones I write are in PS 1.4, since I don't understand PS 1.1-1.3 yet!

As for RenderMonkey - I think it's a fantastic tool, and is far easier to use and navigate than FX Composer. The thing is, it doesn't yet export .fx files correctly, so it's pretty useless to us until it does. Also, it's very limited as far as to constant matrix input: off the top of my head, I remember that it doesn't support any world matricies, only view and projection.

@Zeal:
So sorry, Zeal! I haven't had a chance to make your shader yet! I was a tad busy over the weekend, so I never got a chance to sit down and do any programming, not even on my own projects!

If everything goes well, and I get some decent free time tomorrow, I'll have your shader done then. I'll keep you posted!
Catalyst
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 11th Aug 2004 13:40
Hey, no fair. I'm trying to get just one normal mapping shader up and running and you come along with several of them.

If you'd be willing to pawn off one of those shaders you've got, it would be very helpful. I'm not trying to stick to any particular shader version, any will do. I just want something that looks very good and runs fast. If you have a PS 1.4 version that will do that for me, I'd love to see the code.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 11th Aug 2004 14:06
Hey thanks for the update ninja, dont worry about it beggars cant be choosers . Really looking forward to it though.

So are we going to be applying the shader to all 256 chunks and just scaling the detail down for areas farther out? Or are we sticking with my method of just apllying the shader to the center 4 chunks and then somehow 'fading' the effect out? Seems like it might cause some slowdown to apply the effect to all 256 chunks, but youre the expert :o

All you need is zeal
Tartopom
19
Years of Service
User Offline
Joined: 27th Jun 2004
Location:
Posted: 11th Aug 2004 22:19
As Catalyst, I'd like to have the code of the Normal Mapping Shader ..

Thx
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 12th Aug 2004 02:54
I wouldnt mind seeing it either, although id rather see a 1.1 version. I just bought a ati radeon 9800 pro from a friend, so I could plop out my old geforce 4 ti anytime, im just waiting for a new motherboard. However, it would still be nice to continue to use 1.1 as much as possible, just so my game will run on as many cards as it can.

All you need is zeal
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 12th Aug 2004 08:14
@All Interested People:
Well, it looks like there's quite a bit of demand for shaders, even ones which seem pretty simple once you've got the hang of making them (I guess that's the hard part, though!). So, would anyone have any objections to me just posting all the working shaders that I've made, and a little description of each? If I can get my webspace working, I can even get a few screenshots made, too.

In the meantime, I'll post a couple of basic normal mapping shaders a bit later. I've just got back from seeing I, Robot, and I'm a little hungry right now - check back for an edit in an hour or so. I'll have your terrain shader done too, Zeal!
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 12th Aug 2004 11:13
@Catalyst

I see what I can do about getting those shaders working in DBPro.

@Zeal

"Hows that comen neo?"

I haven't started yet. I've been busy with another tutorial that I've been writing and I want to finish that one up first. I'll probably get those shaders that Catalyst mentioned up and running before I finish the water tutorial since I just got my brand new Geforce 6800 Ultra just recently(I can finally tinker with advanced shaders now. Yeah! ).
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 12th Aug 2004 11:38
Cool ninja yeah you should post your shaders. I looked all over the net and couldnt find a good resource for them, we should start our own.

All you need is zeal
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 12th Aug 2004 12:33 Edited at: 12th Aug 2004 12:48
@Catalyst:
Well, here we go - a simple normal map example. It's fairly basic and works off a single point light, without falloff or colour, but it gets the job done, right?

What we've got is the shader itself, a preview picture and, if that's not enough, a small sample program for DB, with included media:


http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/NormalMap10.zip

@Zeal:
I've got a bit of a terrain shader for you now! It's not quite as good as I was hoping, as I couldn't get the fade effect you wanted on the detail maps. They worked fine in FXComposer but, for some reason, wouldn't show up in DB. I'll keep working at it, but this should be enough for you to get an idea of what to expect from future versions:


http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/Terrain10.zip

Also, if we can get something arranged, I'm quite in favour of a DB shader repository. I know just how hard it is to get samples!

As I get round to it, I'll start tidying up and posting more of my shaders. They aren't all great, but I'm sure there's people out there that would appreciate the little touch that they can add. Also, if Neo doesn't mind me hijacking his thread even more, I could even try my hand at a couple of tutorials aimed more towards learning how to program your own shaders; after all, it was only about two or three months ago that I started making them!

Edit:
Sorry, I forgot to explain how the terrain shader works, Zeal! I've got with your first idea, and so I've just done standard detail mapping - no bumpmapping or anything yet! Anyway, texture 0 is the main colour map, texture 1 the blend map, and texture 2 the detail map. The blend map and detail map use all four channels to squash data in, so you could use the red channel for a rocky terrain, the green channel for grassy, etc. Additionally, the detail map doesn't just darken the base colour, it lightens it too. Effectively, the colour value is just biased so, rather than falling into the usual 0 to 1 range, it falls under a -0.5 to 0.5 range. When you come to make the detail maps, just remember that 50% grey will not affect the base colour, while anything darker will darken it and anything lighter will lighten it. I thought you might be able to get some nicer effects if it was done this way.

There's also a couple of constants defined within the vertex shader that you might want to play around with. One is the strength of the detail mapping, so you can make it more or less prominent, and the other is an in-shader alteration to the detail map coordinates. This is actually there because I tested the shader on a plain with only one set of texture coordinates, but I still wanted to see the tiled pattern! In fact, because the shader only reads in one set of texture coordinates, this is the only way to get a tiled pattern! That's something for me to fix in the next version...

Hope you like it, anyway!
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 12th Aug 2004 13:01 Edited at: 12th Aug 2004 13:04
COOL! Very nice work man! Assembly isnt as confusing as I thought it would be, I think I understand most of it. How come you write in assembly anyway? Isnt HLSL 'supposed' to be easier?

Anyway, keep it up cant wait for the next version!

Oh btw im working on combining my light map into the base map now, so that should take care of lighting for us. Back to work...

*edit NUTS all I can do is drool over those screen shots, the shaders dont work on my GeForce 4 TI 4200 . How come youre using pixel 1.4 for the terrain shader? The original shader only required 1.1 and seemed to have enough power to accomplish what we needed.

All you need is zeal
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 13th Aug 2004 06:48
@Ninja Matt

I would be more than happy to create a shader repository, and host your shaders. ^_^

I agree that this would be a great help to the DBP community. Not only could we have our own shaders, but we could also have the code to make ones like Nvidia's FX composer work too! ^_^
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 13th Aug 2004 08:29
gf4 here too any chance you can make it ps 1.1

Once you start down the Dark Path, forever will it dominate your destiny...
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 13th Aug 2004 10:16 Edited at: 13th Aug 2004 11:47
Umm, not really, I'm afraid. PS 1.4 has been streamlined quite a bit from previous versions and is far easier to write and understand, especially the texture address instructions. I'm not really good enough with shaders to write these earlier versions but, if you bear with me, I should be able to pick it up in a few days. At least enough to do some simple conversions, I hope!

Why do I write in ASM? Well, it's just what I learnt, that's why. I've looked at lots of HLSL code and it often succeeds in totally confusing me, even though I'm fairly proficient with Java and C++ (but not good enough with them to write games!). So, basically, for me, ASM is the easier option and, as long as the two remain identical in functionality, I'll be sticking with ASM.

I guess I just like the level of simplicity and control you have with ASM.

So, how old is a GF4? I'm an ATI person myself and my old Radeon 9000 Pro could handle PS 1.4, so I kinda guessed that almost everybody else could use it too. You've got a Radeon 9800 (the same as me) though, so when do you get your new motherboard, Zeal?

Anyway, as I said, I'll spend the next couple of days messing around with PS 1.1, then I'll re-write the above shaders for you!

Update:
Buh-daaaarrrgggghhhh! PS 1.1 is 3vi1! It only lets me use two temporary registers and won't let me swizzle anything but .a and .b! And it's still confusing!

Fortunately, you're in luck, Zeal - I've figured out just enough in an hour to re-make your terrain shader. Here you go:

It should be, functionally, exactly the same as the PS 1.4 version and can be plugged straight into the example program I made. The problem is, because PS 1.1 is daft, I'm using the whole eight instructions just to get this far, while I was only using six in PS 1.4! And, even then, I know a way I could trim that down to four without too much trouble! That means, if you want me to also write some lighting to go with it, we'll be talking about extra passes, and bumpmapping with four detail textures is totally out of the question.

I'm not sure how accurate my sources are, but I've heard that, Radeon 8000+ cards at least, don't actually have true support for PS 1.1-3, but instead emulate it through 1.4 and so run it slower than they should. Just a bit of trivia for you.

Re-made normal mapping next! But, not tonight - I've got a hankering for some XBox gaming right now!
Preston C
20
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 14th Aug 2004 13:23 Edited at: 14th Aug 2004 13:29
Mind if I add a few shaders I've made over the past few days to this growing source of shader glory?

Not much, mostly simple shaders, but I'm sure they'll be useful to someone (working on more as we speak). The list includes:

- Bump Gloss - Simple bump mapping based on the FX Composer tutorial
- Cartoon w/Outline Shader - A Cartoon Shading Shader
- Fur Shader - A shader that creates a simple "fur" effect
- Gloss Mapping - Gloss Mapping Shader
- Las6 Snow - Adds "snow" to a mesh based on its normal
- Smooth w/Outline Shader - Variation of the Cartoon Shader

Pics:
http://www.ppcdesigns.com/public/BumpGlossPic.PNG
http://www.ppcdesigns.com/public/CartoonPic.PNG
http://www.ppcdesigns.com/public/FurPic.PNG
http://www.ppcdesigns.com/public/GlossPic.PNG
http://www.ppcdesigns.com/public/Las6SnowPic.PNG
http://www.ppcdesigns.com/public/SmoothPic.PNG

Like I said, they're mostly simple ones.

You can download the pack here:
http://www.ppcdesigns.com/public/ShaderPack1.zip

Cheers,
Preston

[Edit] Damn url and href tags...ugh...


Fear My Ugly Avatar and Out of Place Signature Image!
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 14th Aug 2004 15:55
*pipes up*

Er, for the lay non-shader users out here, what exactly do you do to get these shaders working? Do you copy the code snippets into a Dark Basic Pro file and save it somewhere? Is it a seperate type of file? And how do you call it for that matter in a program? This stuff seems really interesting, and it's be awesome if someone could make some of those shaders poseted in the EXE a while back, it would really be helpful to the community.

Preston C
20
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 14th Aug 2004 17:50 Edited at: 14th Aug 2004 17:51
Using shaders is actually quite easy with DBPro (and with the examples I've seen, pretty easy in C++ as well).

First you would copy the shader into an empty text file, and save that file as a .fx file. Then you would gather the needed media, put it in the directory with the .fx file, and then you would apply the effect to an object, like so:



And walla, if your card supports the required shader (1.0,1.1,1.4,2.0,etc), the shader has no errors, and all the media was gathered properly, your effect should be applied on the shader. It's not that hard

Theres also a different way that you would use if your shader had some constants you would need set, or if you wanted some debugging info, but we'll get into that another time.

Cheers,
Preston


Fear My Ugly Avatar and Out of Place Signature Image!
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 14th Aug 2004 21:18 Edited at: 14th Aug 2004 21:18
Ah, thank you. Some of the shaders on this page simply produce an entirely black object, or an object with many overlapping artifacts. I've gotten maybe 5 of the total shadersion this thread to work, as well as all of the ones in the download file. I have a Radeon 9800 Pro with updated drivers. I never set any constants, which might be why some don't work, I just set the effect on my level object. I noticed that many shaders only work if there's a texture under it, if the level is a solid color it tends to cause problems. The ones that did work were very interseting, and will probably find a way into my game. I would love to see a glow shader, and a glass shader would be awesome, or some of the ones that were posted in the EXE a while back, those look very professional.

Anywho, carry on with shading!

Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 16th Aug 2004 10:02
More! Yes, More!

Well, sort of. First off, I've got an updated version of the normal mapping shader as posted above, this time for PS 1.1. Functionally, it's exactly the same as the PS 1.4 version, which means you can copy it straight into the example program I made above if you want a quick test, and it should work without any problems! Here you go:



Anyway, that's that. If people want me to, I can make a better version that includes coloured lighting, fall-off, specular reflection, etc.

Now, second-up, is one of the first shaders I ever made, but one that forms the backbone of the GUI for my current game - it's a hologram shader! And, for the peeps with older hardware, it's just a vertex shader, so it'll work on even the most dated video card. As usual, here's the source code for the shader:



The preview picture:


And finally, the example program that the picture was taken from:
http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/Hologram11.zip

Now, I say that it forms the backbone of my GUI, but that's a bit of a lie. I've actually recently upgraded the system to work with normal mapping as well, so I can get more detail, particularly on a spinning globe that I've got, without increasing the polycount too much. I might release this version eventually, but you'll have to wait a bit for that!

More shaders on the way!

@Zeal:
Did you catch the updated terrain shader I made? I put it up in one of my posts as an edit and, since you've been quiet recently, I thought you might have missed it. Let me know if anything needs changing/fixing! Also, I've figured out how to get the detail fade effect you wanted, so I can add that to future versions.

@Clever People:
From help on the earlier pages of this thread, I found out that the last row of the ViewIT matrix holds the camera position. However, has anyone told DarkBasic this? Perhaps I'm doing something wrong, but I've still always got to pass in the camera position with a vector4!

Other thing - don't try to load .3ds files to have an effect applied to them. Doesn't work. Not for me, anway. Looks like the normals come out all messed up or something...
Tartopom
19
Years of Service
User Offline
Joined: 27th Jun 2004
Location:
Posted: 16th Aug 2004 10:19 Edited at: 16th Aug 2004 10:23
Hello

I Just like to know one thing, Don't know if this is possible but ... can we add many lights for the normal mapping instead of one ?

And i like to have the modified version of your hologram shader it's great, as all your works.

Thx for reply.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 16th Aug 2004 15:31
Hey was out of town the last couple days, but im back now. Cool ninja glad to see you were able to get a 1.1 version working! Ill check it out tomorrow but now I gotta go to bed! zzz

All you need is zeal
Try
19
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 16th Aug 2004 18:13
Hello, first thank you guys (Neophyte, Raven, Preston Chaderton, Ninja Matt and...) for your useful stuff.

i was playing with these shaders, and i couldn't find something in the files that can change the bump height (maybe because it's asm)so how can we change the bump height in these shaders?

thanks.(sorry for poor english)

Login to post a reply

Server time is: 2024-05-07 17:05:46
Your offset time is: 2024-05-07 17:05:46