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
DARKGuy
16
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 20th Nov 2006 04:30 Edited at: 20th Nov 2006 04:32
Greetings!

o.o I notice this is a very useful thread about those shiny cool glowy stuff we call shaders (?) but I have a small question about all this stuff ^_^;

I tried going to http://vvvv.org/tiki-index.php?page=pixelshader_for_newbies but it gives me a 404 error. Does Anybody know any good pixel shader tutorials like that one? ^_^;

And also, some basic shaders for people to start off practicing with would be nice too - GG's ones are some nice ones, even though I can't even understand the everything-to-one-color shader, I'd like to improve it to use shading so there could be a black-and-white effect which I'm searching for (and it could be improved for making a nightvision view, just for practice!). A small motion blur and/or water example will do too, and they're useful! ; and enough to practice with them too (at least, I would o.o; ).

Aaaaand well xD if anybody knows about a black-and-white shader, motion blur and water compatible with PS 1.1 I would be really, really glad as I'm searching for those - and will learn, too ^_^;

Thanks in advance, and keep up with this shader thread!


"As sudden as I arrive, as sudden as I leave."

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

You need to start somewhere.

Quote: "even though I can't even understand the everything-to-one-color shader, I'd like to improve it to use shading so there could be a black-and-white effect"


Might be a good idea to understand that simple shader before moving on. Which bits do you need help with? I'll try to help if I can.

When you say "black and white effect", do you mean grey scale or high contrast?
Syncaidius
15
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 22nd Nov 2006 14:30
hey Green Gandalf, I dont know if this wod of information from MSDN is any use to people:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/HLSL_Tutorials.asp

It has loads of information about writing Shaders. It has tutorials on the the most basic things, right down to the more advanced stuff.

Im goint to start taking a look at this information and see if I can write my first shader.

Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Nov 2006 00:33
Yes, there's some useful stuff there (I think it's in the DX9 SDK as well). But you can't use all of it in DBPro yet - for example, DBPro doesn't support procedural textures at the moment.

Don't forget to look at the Ultimate Shader Thread 2 on the "Old Stickies" thread on the main DBPro list - several tutorials there.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Nov 2006 16:29
@DARKGuy

You asked:

Quote: "Aaaaand well xD if anybody knows about a black-and-white shader, motion blur and water compatible with PS 1.1 I would be really, really glad as I'm searching for those - and will learn, too ^_^;
"


I've got a working, but not fully tested or tweaked, version of a bloom shader for PS1_1 if that's of any interest.

Do you still need a black and white shader? If so, let me know what you mean exactly and I'll see if I can come up with something.
DARKGuy
16
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 23rd Nov 2006 17:37
I tried following that MSDN tutorial, but I couldn't understand it nor how to make it work in DBP (also, DBP has some stuff that can and can't support, neither I'm sure if the .fx structure is the same one that must be followed for DBP shaders, so...) the Ultimate Shaders thread has some nice stuff in there, but I haven't got time to check the whole thread lately... I was without internet three days ago (that's why my late reply :/ ) and yesterday it just came back so yeah :/

Hmm, long time ago, there was a shaders thread... I dunno where it is oO I think it died or something, but it was really useful, complete with examples and code snippets, just like a tutorial of sorts o_o;

@Green Gandalf:

That bloom shader would be useful to test, the one in the Ultimate Shaders Pack works (though it says HLSL Rendering example or something like that which does some kind of similar effect) but I'd like to see this one

About the black and white shader... yup, what I mean is something like this, though:



That's when you're a Night Elf in WoW and die, you become a whisp and the screen becomes b/w (however, if you turn off the shader effect, it's just the same scene but the skysphere gets changed to a swirl of dark cyan, which, mixed with the b/w effect, gives some nice, nice results


"As sudden as I arrive, as sudden as I leave."

Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Nov 2006 22:52
@DARKGuy
Quote: "Hmm, long time ago, there was a shaders thread"


There are several, the main ones being: "The Ultimate Shader Thread" which died a couple of years ago because of a flame war. That was quickly followed by "The Ultimate Shader Thread 2" which I mentioned before - and is still going I think. That's the one with all the tutorials (although many of those were resurrected from the first thread I think). There's also "The Ultimate Shader Pack" on the Work In Progress list - but that is mostly a collection of shaders from the earlier one plus some others. There are isolated threads which discuss shaders elsewhere, like on the main DBPro list.

Quote: "That bloom shader would be useful to test, the one in the Ultimate Shaders Pack works (though it says HLSL Rendering example or something like that which does some kind of similar effect) but I'd like to see this one "


Just finished testing the first version of it - but I'm not happy with it for four reasons.

First, it's just as slow as a PS2_0 version similar to Evolved's - the main difference is that my PS1_1 version produces the blur by displacing geometry several times (once for each pass) whereas the PS2_0 version does several displaced texture lookups within each pass. The bottleneck is the total number of texture look-ups you need for a decent blur/bloom which is the same in each case (25 in my versions). If DBPro allowed intermediate render targets the number of lookups required for a decent blur could be reduced significantly.

Second, the code is untidy and relies on repeated "cut, paste and edit" rather than looping. It ought to be possible to use a loop for several similar passes - but I don't know if that can be done.

Third, the geometry displacement doesn't work quite as I expected which suggests a misunderstanding of something on my part.

Fourth, the zdepth/transparency stuff is wrong.

I'll try fixing these before posting it, but if I can't I'll post it anyway in case someone else has any ideas.

Quote: "That's when you're a Night Elf in WoW and die, you become a whisp and the screen becomes b/w (however, if you turn off the shader effect, it's just the same scene but the skysphere gets changed to a swirl of dark cyan, which, mixed with the b/w effect, gives some nice, nice results"


Sounds like you want the whole screen display to go from full colour to grey scale, except perhaps for bits like the sky. Will give it a go - but I suspect the shader will need to be applied to several objects at the same time, i.e. trees, rocks, terrain, players, etc, which is OK unless you want other shaders to be active at the same time. There might be a way of post-processing the screen using shaders in DBPro, but the method escapes me (except for the method of taking a screenshot with a DBPro camera and processing that - now there's a thought ...).
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Nov 2006 18:14
@DARKguy

Had a go at your greyscale/cyan thing. Here's my first attempt plus demo program. All it does is fade the colours of the affected objects in the scene to a uniform colour scale after you click the mouse, e.g. different shades of cyan in the example. You can change the target fade colour in the DBP program. It works best with PS2.0.

Shader connoisseurs might like to note that the shader also compiles and runs under PS1.1 and PS1.4 - but doesn't work correctly. Anyone know why? Curiously, on my machine it runs fastest on PS1.1 and slowest on PS2.0. The compiled asm code provided by FX Composer looks rather different for the three cases (as you might expect) - haven't worked out the key differences yet though.

Attachments

Login to view attachments
Overdroid
17
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 26th Nov 2006 10:09
Hey GG, shader guru that you are, I have a question for you. Is it possible to use a shader with a lightmap?
Thanks in advance,
Overdroid.

"If you want an audience, start a fight."
- Gaelic Proverb
Chris K
16
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 26th Nov 2006 10:58
What does that even mean?

What are you actually trying to achieve?

-= Out here in the fields, I fight for my meals =-
Overdroid
17
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 26th Nov 2006 11:57
I'm creating a level, which is lightmapped. I also want to have a shader effect on the level itself. So far all my attempts to use both have failed. Does the shader have to be written specifically to be used with a lightmap? Or is this even possible?

"If you want an audience, start a fight."
- Gaelic Proverb
Chris K
16
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 26th Nov 2006 12:34
A lightmap is just a texture isn't it? So I will work, yes.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Nov 2006 19:53
Quote: "So far all my attempts to use both have failed."


Give us a simple example and we'll try to sort it out. Note, though, that several people including me can't get shaders working correctly with advanced terrain objects, so if you're trying to do that I probably can't help. Hopefully someone who knows how will enlighten us all (Rich, are you listening?).
Overdroid
17
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 27th Nov 2006 00:01
Here's an example with the code and the shader I'm using (Ninja Matt's Grass shader). The model is the same, but the one on the right has the shader - lightmap dissapears. Also, I have added a one to the load mode for the shaded object. Behavior is the same.

I'm pretty sure it has something to do with the shader itself creating the lighting effect on the object, but I really no nothing about shaders.

"If you want an audience, start a fight."
- Gaelic Proverb

Attachments

Login to view attachments
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 27th Nov 2006 06:32
I'm in need of help implementing Ninja Matts NormalSpecular21 shader. First of all I want to say that I'm not the programmer, just the graphic artist of the group. But since our coder has been on field for quiet some time I a had to tinker a little bit with the code myself. So my knowledge is quiet limited in this field, but i'm a fast learner ...I guess
Our coder had implemented the internal bumpshader. As we weren't satisfied with the wet look of the Shader I had to implement Green Gandalfs Shader myself since our coder was not around during the week.
It was more or less "Plug and Play" getting Gandalfs shader into the code but I wasn't able to get any of the Normal Shaders to run.

Now everything works fine with Gandalfs Shader, our only problem is that we seem not to be able to use Lightmaps. But that's a different story.
Anyway if I load the level with NInja Matts Shader all objects are plain white. Maybe I haven't set the effect constants right or something else. I would highly appreciate if somebody could take a look at the code, it's pretty messy though since i played around with it quiet a bit. It would also help our coder since it's his first time to work with Shaders.
Many Thanks !






And this is how it looks with Gandalfs shader
http://i61.photobucket.com/albums/h56/soclose_2006/ggbump.jpg
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Nov 2006 22:26 Edited at: 29th Nov 2006 12:55
@Irradic

I'll get to your query as soon as I can.

In the meantime, here's a demo "game" which uses a version of my flashlight shader with Advanced Terrain. I've prepared this in response to queries on the main DBP list about getting shaders to work with A.T. but decided this was a sensible place to post it.

You can move around the terrain and the flashlight moves with the camera.

The terrain texturing is all done in the shader and doesn't have any lighting yet (except for the flashlight itself). The program runs at about 20-50 fps on my machine depending on where you are.

The "game" consists of trying to catch 10 "sheep" which wander aimlessly around the terrain and return them to their "corral" (which is a rectangular region of the terrain close to your starting position). The snag is that the "sheep" wake up and escape again after a few seconds. The game ends when all 10 sheep are back in the corral - that part of the program is currently untested, I've only managed 6 or 7 before being distracted by something else. You catch the "sheep" (more like bloated floating backward facing turtles really) by getting close to them and left-clicking the mouse. You then return to the corral and right click to release them once you are inside the corral. However, you can only carry one sheep at a time - they are quite heavy you know.

Advanced Terrain connoisseurs will recognise some of the media, the terrain though is mine.

If anyone wants to try this but finds the file too big to download (it's about 2 Meg), I can prepare a smaller version without the sound and with cruder images (e.g. jpg's).

You will probably need upgrade 6.2 or later for the program to run correctly.

Edit: Attached a tweaked version of the code and shader. The shader now has two techniques, one for Advanced Terrain, another for standard objects - so the "sheep" are affected by the flashlight as well. Adjusted a few other things to improve the effect, e.g. toned down the skymap, shortened the flashlight's range, reduced the flashlight's beam width. The flashlight beam is still distorted if you get too close to a low poly object - well, what do you expect for free?

Attachments

Login to view attachments
Airslide
15
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 28th Nov 2006 00:40 Edited at: 28th Nov 2006 00:44
Ah, downloading now, thanks Green This hopefully will give me the oppurtunity to make the nightime level in my game, taking advantage of some nifty military equipment

EDIT: It works, but it seems a bit - well, the terrain seems a bit too lighted, and gives the flashlight a minimul effect. I'll mess around with it and see what I come up with.

Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 28th Nov 2006 05:42
Thanks Green, hope you can work it out.
Overdroid
17
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 28th Nov 2006 09:53 Edited at: 28th Nov 2006 19:08
I agree, the terrain is pretty bright, but it's still hard getting sheep (those darn sheep!).

Anyone have an answer for my lightmap/shader question? Does the example help?

Chris K? You seem to know a lot about the art of shaderizing - perhaps you can illuminate my problem. Pun.

Anyway, I'm off to bed.

Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Nov 2006 10:29 Edited at: 29th Nov 2006 12:58
Quote: "It works, but it seems a bit - well, the terrain seems a bit too lighted, and gives the flashlight a minimul effect. I'll mess around with it and see what I come up with."


There are three things you can adjust easily (I didn't include "tweaking" code in the demo this time):

1. the effect constant "lightBrightness"
2. the effect constant "lightAttenuation"
3. the 1D flashlight image "FlashLight.png".

I think I set lightBrightness to 4 and lightAttenuation to 0.005. The constant "lightAttenuation" must be in the range 0 to 1: 0 gives no attenuation with distance, whereas 1 gives full attenuation (i.e. no light). You get full attenuation at a distance of 1/lightAttenuation, so the value I've used gives full attenuation at a distance of 200 world units - which is, as you say, rather high for a terrain that is 765x765 units in size. Try a value of, say, 0.02.

The flashlight beam width is rather high. You can easily change this by modifying the image file "FlashLight.png". The right-hand pixels in the image correspond to the centre of the beam, and the left-hand end corresponds to the outer parts. So just make the bright bits not extend so far to the left - and perhaps brighten some of the right hand pixels at the same time.

Anyway, the main point of my example was to show that it could be done and I'm glad you both got it working.

On the "game" aspect, I forgot to add that you can hear the "sheep" breathing as you get close to them, so you might be able to catch them with your eyes shut - but finding your way back to the corral might be tricky ...

Edit: posted a tweaked version of the code and shader.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Nov 2006 11:09 Edited at: 29th Nov 2006 11:43
@Irradic

Just had a quick look at your query about Evolved's normal specular shader, but can't match your code to Evolved's shader. Which shader are you using? I've got "NormalSpecular21.fx" from the Ultimate Shader Pack, but it doesn't have a technique called "NormalSpecular" as in your code snippet below. Also, I notice the FX file name is different. Is there a new version around?



Could you post the FX file you are using? Without seeing the code the only thing that occurs to me is that your code snippet above only seems to apply a texture to Stage 0, whereas the "NormalSpecular21.fx" shader requires textures for Stages 1 and 2 as well. Since you have loaded the effect with flag 0, you will need to apply all the stages in your DBP program. So if your FX file uses something similar that could be the problem.

Edit: Just had a quick look at Evolved's example code and it seems the problem may be in his DBP program. His DBP code contains the following:



If you look at his shader "NormalMap21.fx", you'll see that it doesn't contain a technique "NormalSpecular", so the set effect technique command has no effect - the program just uses the first technique in the shader instead (which works fine).

However, Evolved's file directory contains another shader, "NormalMap22.fx", which DOES contain a technique called "NormalSpecular". However, to use that shader, you need to specify all the texture stages in the DBP program - if you don't, you just get white images, which is what happens with Evolved's demo if you try to use the following:

.

So, in summary, I suspect you're a victim of a bit of confusion in Evolved's demo program which is easily fixed. Post me the FX code you're using and I can probably sort it out for you.
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 29th Nov 2006 16:56 Edited at: 29th Nov 2006 19:17
First of all thanks a lot for looking into the code Green.
Yes I was using the Normal Map Shaders of Ninja Matt, the NormalSpecular.fx shader is actually the NormalMap21.fx shader.
No changes have been done.
Concerning the main source code. The program currently loads the diffuse map into stage 0 and the normal map into stage 1. Other stages are not used at the moment.
Our coder implemented this search function which first looks up for the maps and then loads it to the object.
So it first searches for the color map, loads it to stage 0 and then searches for the normal map and loads it to stage 1.
The fx file is being loaded after the application of the texture to stage 0, afterwards the normal map is being loaded. Maybe that's another problem ?

Now the strange thing is that i have this normalmap21.fx shader which is different though from the one which is included in the shader pack.
Take a look


This is what I currently have in the FX folder under the name Normalspecular.fx

Now I don't really mind which one will be used, the Shader which I just posted or the NormalMap22.fx Shader.
I just want the program working with Normalmaps and Specular maps.
I've been spending hours over hours the past days trying to get this to work. I'm at the point were I'm really starting to get frustrated since it leads to nowhere and I'm just an GFX Artist and no programmer.
Well...thanks a lot for the time Green. Would be really great if you could work something out.

[MOD EDIT]I've fixed your code tags for you IanM
QuothTheRaven
17
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 30th Nov 2006 00:49 Edited at: 30th Nov 2006 00:49
Hey, the lightmap based flashlight shader is no lonver avaliable on Evolved's forums, can someone host it here pretty please? (including zip file w/example?)

Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Nov 2006 01:51
@Irradic

As I said, I can't see a technique called "NormalSpecular" in that code you've just posted (that's such a large file, it's easier to include it as an attachment to your message - copying it from the screen is a pain). Anyway, it's late, and I'll have another look at this tomorrow. I'm sure there's a simple fix.

Cheers for now.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Nov 2006 16:51
@Irradic

I think I've found the problem. My comments follow:

1. DBP now supports the semantic CameraPosition so you don't need to explicitly pass it in
a vector from DBP. Just change the following line in your shader
float4 EyePos : EyePos;
to
float4 EyePos : CameraPosition;
and remove the following line from your DBP code
set effect constant vector 1,"EyePos",3
(you might be able to remove some other lines as well unless you use vector 3 for
something else as well).

2. As I mentioned before, the effect file doesn't contain a technique called
"NormalSpecular". The only ones I can see in the FX file are:
"Lights2", "Lights4" and "Lights8". I guess you are using the first of these. The following
line in your DBP code does nothing at present:
set effect technique modellcount,"NormalSpecular"
and I think you can delete it (it was in Evolved's demo too).

3. I'm not sure your code is calling the effect correctly. You load the effect as
effect number "modellcount" in the following lines:



but refer to it (I assume it's supposed to be the same effect) as effect number 1 in
the following part of your code:



This will work if modellcount happens to be 1.

4. After a lot of experimenting, I noticed two more problems with your DBP code.

The important one is that the following effect constant references:

"LIGHT1POS"
and
"LIGHT1COL"

must be replaced by

"Light1Pos"
and
"Light1Col"

The capitalised versions will not be recognised as the ones in the effect. When
I corrected those, my test version of your code worked. That's the sort of annoying
error that's in front of you all the time but you can't actually see it!

Another possible problem you should think about is the value you've used for the
fourth component of the Light1Col vector - I need your models and media to check that
(it's used via constant c12.w in the shader as part of the light attenuation
calculation).

I've included the test code and media that I used - I've made minor changes to
Evolved's code so it works with DBPro and FX Composer - the main code is unchanged.

Hope all this helps.

Attachments

Login to view attachments
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 30th Nov 2006 18:23
Thanks a lot Green. I will try to follow your instructions and hopefully manage to implement the shader.
Atm our demo is around 15mb, I will provide you with a link once we have uploaded the latest version.
I really appreciate your help. Thank you
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 30th Nov 2006 21:31
OK, thanks to you I managed to load the level properly with the NormalSpecular Shader. As you said changes have to be done to the light attenuation, i've been trying to adjust the values, however this is as good as it gets. Maybe you can figure out the right values, or probably you have to adjust the shader ? Anyway I'm getting 50-60fps with this Shader, compared to over 200fps with your Bump Map shader Gandalf. Guess that's due to the fact that we devided the level into smaller objects, our Coder told us that's better for the performance.
Anyway, we've been considering your Bumpmap1.0e Shader Gandalf, since the performance and visual quality is really good. However
we would like to know if it is possible to use Lightmaps wih your Shader. What would be the best way ? We can't bake them directly to the textures since we are mainly using tiled textures.
Also it seems that the bump effect breaks at some areas of the level.
Anyway here is the link [href]www.toxicon.ch/demo/shooter.rar[/href]
Thanks
Terrorist Zero
13
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 1st Dec 2006 00:06
I've run into problems. My map's very dark, it's supposed to be, so I've whacked in the glorious flashlight shader by Evolved. Saying that, it's been messing me about with the lightmaps, since the light's being dark in dark areas, and light in light areas. I've seen a post on the forums on it, but the guy didn't get the answer, so if ANYONE knows how to solve it, then please lead me in the right direction. I've already tried editing the FX file, but still no luck, that is unless the textures/lightmap are physically swapped.
Also for some reason the flashlight stuff/example from the Shader Pack doesn't run for me, I just get black screen, so it's not of much use to me.

www.tornupgaming.com
The home of free games and game projects.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Dec 2006 13:57
@Irradic

Glad I was able to help.

I'm also glad to hear that my bumpmapping shader is working well.

It should be possible to include lightmaps quite easily - with some performance loss of course. Just add another texture stage in DBP and corresponding extra texture declarations and sampler in the FX file. Then decide how you want to apply the map to the object's image - for example, does the lightmap correspond to a single point or directional light source, is the light source fixed or dynamic, is the lightmap in world, object or texture space coords, etc, etc? I'm not sure, but if the light source is fixed (a street light perhaps) it might be better to use DBP blendmapping. But it sounds as if you've tried that route. The shader route gives more flexibility of course.

I spent some time optimising those shaders so I'm not surprised they run faster than Evolved's, but optimising for speed meant some compromises with the visual quality. Also, Evolved's shaders include more features which inevitably slows them up a bit.

You mentioned:

Quote: "Also it seems that the bump effect breaks at some areas of the level."


Was that with my shader? Can you give me a simple example? Or is that in the download? (I won't be able to look at that till tomorrow probably.)

@Terrorist Zero

Your problems with Evolved's flashlight shader sound familiar to me - but I thought Evolved posted an amended version which worked. It was either on one of the Ultimate Shader threads or perhaps a thread about flashlights. Have you tried a search? Anyway, I should have it at home so I'll see if I can find it later today.
Airslide
15
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 1st Dec 2006 16:10
Thanks Green, prehaps I can have the flashlight in my game after all

Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 1st Dec 2006 16:40
After converting the textures into DDS I was able to win around 60FPS. The current fps of the Scene with the NormalMap Shader is around 120-140 at 1280x1024 (your shader still tops it with almost 300fps). Well it was to expect that all the textures would drag down the performance. The scene consists of over 20 objects, times 3 for the amount of textures.
If you run the demo you'll see that the lighting of the NormalMap Shader isn't correct. Maybe you have an idea what I have to change.
Concerning the Lightmap, we just opted to render it in 3dsMax and blend it with the other Textures. If you could give me some advice in this matter I'd be thankful (what do I have to add to your shader etc).
About the breakage of the effects, well I would say it's not a fault in your shader since it occurs in both Shaders. Maybe it's something concerning culling or an error in the object.

I really appreciate you taking the time answering my questions.
Terrorist Zero
13
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 1st Dec 2006 20:04
Yeah I've searched loads and loads, but still nothing, that's how I found the other guy with problems.
It's a shame that the shader coming with the shader pack won't work for me, and I'm still trying to grasp some of the concepts of the code, I really don't see why there should be two map's loaded at the same time. Oh well, it'll come to me in time.

Incidentally, I've also tried your simple flashlight shader green gandalf, using my map. It's horrid lol, the place is black unless you go up to a wall, which it then bends the textures anyway. I thought I'd say that pointless piece of knowledge. Could be because I'm still learning code atm anyway.

Thanks Green Gandalf, and hope for a solution to my problem soon!

www.tornupgaming.com
The home of free games and game projects.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Dec 2006 22:54 Edited at: 1st Dec 2006 23:19
OK, everyone. Several questions here and I won't have time to answer them all now. So, in reverse order,

@Terrorist Zero

Most of these shaders, including mine, have various input parameters that you need to tweak for your particular application, i.e. things like attenuation factors, light positions or directions and so on - and we're all guilty of not including detailed instructions.

That remark is particularly relevant to your difficulties with my flashlight shader. If everything looks dark you probably need to adjust the "lightAttenuation" or "lightBrightness" effect constants (I'm talking about the shader "GGFlashLight v3.fx" that came with the Advanced Terrain demo I posted a few days ago - I think I posted some guidance there). The other problem is in the design of the shader - it works better if you are not too close to a small number of "polys" (triangles in the objects' meshes). If I get time I'll try to sort that one out. I haven't had a chance to look for Evolved's flashlight shader yet (only just finished cooking and eating supper) - but I expect it needs various "tweakables" to be properly set as well.

@Irradic

I'll get to your queries as soon as I can, but I'll probably have a go at someone else's first since I've managed to help you already.

@Airslide

I'm assuming you're thanking me for what I've already done ...

QuothTheRaven

Your flashlight query is on the list.

Overdroid

I never got around to looking at your grass shader query - do you still need help on that one?

Cheers for now all of you, I've got to start planning my weekend ...

Edit: OK, one item off the list. Here's the version of Evolved's flashlight shader that works for me - his original zip file which I downloaded from somewhere (it's NOT the version in the Ultimate Shader Pack). Just tested it again in case I'd interfered with his code. It's fair to say that it looks MUCH better than mine and I'd recommend it. You operate the light by pressing and holding the "F" key. Then press and hold again to turn it off.

Attachments

Login to view attachments
Seppuku Arts
Moderator
15
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 2nd Dec 2006 15:04
With Evolved's water and bloom shader, how would I go about getting them to work together, at the moment they cause each other problems.

"Cut down the gods if they stand in your way" - Hakamoto Tsunetomo
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Dec 2006 19:52 Edited at: 2nd Dec 2006 20:00
@Irradic

Had a look at your lighting query. I changed the code so it used my shader because I'm more familiar with it. I think I can see the problem (but not the cause yet) - is it the fact that some objects are lit on the wrong side as in the attached screenshot? Or are you concerned about something else?

I'm having problems working with your demo because the fps is only about 6 on my machine . I'll have another go later with only a few of the objects loaded - it might be easier to identify the cause of the problem then.

Possible causes that occur to me at the moment are:

1. a bug in my shader - but you say Evolved's has the same problem (I'll look at that again) so that seems an unlikey cause;
2. the normals in some of your objects are wrong, e.g. wrong sign (I might be able to check that theory).

Edit: (forgot to comment on the lightmap issue) Not sure about that one - depends on what sort of lightmap you are using. If it's the sort of lightmap that consists of several separate images put together in one image I probably can't help - but if it's just another texture for each object (like the normal maps) then it should be easy to add to the shader.

Attachments

Login to view attachments
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 3rd Dec 2006 04:10
Yes exactly that is the problem. For example, as you can see some walls are properly Bump mapped then suddenly the effect breaks at a part of the wall. I'm sorry that it only works with 6FPS on your machine, I checked the file and noticed that it's not the version with the DDS files yet. It should have given you some performance boost. But yes as a work around you can just remove some object for the meanwhile.

Conerning the Lightmap, it's just another texture for each object that I would like to add to the other textures.

Thanks again Green.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Dec 2006 15:05 Edited at: 3rd Dec 2006 15:08
@Irradic

Quote: "For example, as you can see some walls are properly Bump mapped then suddenly the effect breaks at a part of the wall"


Hmm. I'm a bit confused now. The problem I was referring to was that THREE of the red pillars are lit on the wrong side - so when everything else is lit from the north those three are lit from the south. I hadn't noticed problems with the walls - except for some of the sign objects on them. Could you take a screenshot of the problem and draw a red circle around the problem area so I can see what the problem is exactly?

Anyway, I think I've identified the problem with the lighting orientation of some of your objects. The answer proved interesting and highlighted a misunderstanding on my part of how shaders work. My new understanding of the situation is as follows - and apologies in advance if I'm wrong (I'm still learning about shaders myself).

The problem is consistent with the vertex "winding order" being wrong in some of your objects. This refers to the fact that each polygon has 3 vertices, a b and c say. If these are ordered in the object's mesh data as 'a b c' rather than 'a c b' the normals will be reversed in the shader. I had assumed till today when I started investigating your problem that a shader would use the normal data supplied by the DBP object mesh data. It doesn't. This is easily tested by changing the object's normals and comparing the effect on (1) standard DBP lighting and (2) a shader lighting effect. I found that DBP lighting is altered in the way you would expect - but the shader lighting isn't. Hence the shader must get it's normals from somewhere else. There may be a way of telling the shader to use the mesh normals, but I don't know. The only other source of data that could be used is the vertex position data - hence the possible relevance of the winding order. Anyway, the problem can be fixed in one of two ways:

1. use your modelling application to make sure that all objects have the right winding order for all the polygons (this isn't always easy - when I used Milkshape, for example, and added polygons to the mesh, it was easy to get the winding order wrong sometimes so isolated polys would appear black or something);

2. modify the shader.

I've tried option 2 with your objects and it works fine (see attached FX file "Bump v2.fx"). All I have done is add another "tweakable" float to the effect constants (I called it "reversenormals") which you should set to 1.0 or -1.0 depending on whether the normals need to be reversed.

The problem with both these solutions is that they are messy - you need to check each object in turn - but it can be done. The ideal solution would be to use the objects' vertex normal as in DBP lighting. If I find out how this can be done I'll post the answer.

Quote: "I'm sorry that it only works with 6FPS on your machine,"


I've adjusted the camera movement settings which simplifies viewing somewhat. The good thing about having a slow machine is that if a shader works on mine then it should work very well on someone else's!

Quote: "Conerning the Lightmap, it's just another texture for each object that I would like to add to the other textures."


OK, I'll try to come up with something.

Edit: inserted a missing word.

Attachments

Login to view attachments
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Dec 2006 16:26
@Irradic

Quote: "For example, as you can see some walls are properly Bump mapped then suddenly the effect breaks at a part of the wall."


I think I see what you mean - see attached screenshot. Looks like another problem (but might not be) - possibly connected with the normal map this time.

Will investigate.

Attachments

Login to view attachments
Terrorist Zero
13
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 3rd Dec 2006 17:33 Edited at: 3rd Dec 2006 17:56
Cheers for all your help Green Gandalf!!!
I've basically got the flashlight working now, apart from the fact that the two map files keep colliding (that horrid texture clash, where it can't decide which one to show) and messing up horribly whatever I do, I'll keep trying though, I'm bound to get it at some point, and I know it's to do with the actual .dbo file/textures, it's got to be haha.

EDIT: Ok after testing my maps directly with the flashlight code you've given me it turns out its doing the same thing, therefore it's to do with the export from 3D World Studio and its DBO files. I've already tried exporting as a .X and editing in notepad to add all 3 lightmap files, but it makes them into a tiled texture, and fades them to show the proper textures. Any help appreciated, but it's basically a case of trial and error.

www.tornupgaming.com
The home of free games and game projects.
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Dec 2006 18:26
@Terrorist Zero

Did you try the version of Evolved's flashlight shader that I posted a couple or so posts ago?

Regarding your question, I think I need some code and media to try out. Without that I'd be guessing what the problem is (and perhaps even with it as well ).

@Irradic

Your problem is throwing up all sorts of weird things. I've looked at your "paintedwall.X" object in some detail. I tried putting the textures in the shader itself - and it seemed to work for the whole wall, except for one odd thing. The shader uses the plain tiled wall image "paintedwall_color.jpg", i.e. no red stripe, but the displayed image in the program has the red stripes (these are set in the ".X" file). So, curiously, it has picked up the normal map and look-up image for stages 1 and 2, but has used the X file textures as the base texture. Only explanation I can think of is that it has something to do with limb numbering and texturing. I'll see if set limb effect works better.

It might be worth you checking the textures you've specified for the walls and whether you've been numbering them consistently.
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 3rd Dec 2006 18:31
You are really putting a lot of time into this. I can't thank you enough. I have attached a picture showing the Bump problem I was talking about. On the picture you see a corner, a part of the left wall has no bump effect to it, right though we can see the bump effect. However this problem is not present in the normal map shader. Our 2nd artist who created this level is using C4D, he's looking into the vertex welding problem. You have seen our object loading function, it fetches automatically all .x files in the folder. Applying the constant to a specific object would be indeed messy. We'll have to see what we can do.

Cheers ! And thanks again

Attachments

Login to view attachments
Irradic
13
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 3rd Dec 2006 18:46
Concerning the textures. Yes I know that textures have been assigned through the moedelling program. The program seems to prioritize those textures over those which are loaded in the code.
Our scheme is following, if the object is called wall.x, the program will search for wall_color.dds,wall_n.dds and wall_spec.dds. Now the downside to that is that you could only assign 1 color texture to the object. However through the 3D application we were able to apply different texture through poly selektion. The program is still loading color textures through code, because at the time our coder programmed the application there were no textures assigned through any modelling program.
If possible I will remove the code which looks up and applies the color texture to stage 0.
Terrorist Zero
13
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 3rd Dec 2006 20:33
Yeah, I said i'd used your copy of it.
I'm uploading a copy of the map I'm trying to use right now, it's about 3.5mb, and includes the .dbo file which has the lightmaps, and only one texture, which i've deleted out of the folder, and it also includes the "null" map which is a .X and uses all the textures for the level.

By running the map using the code from the shader version you gave me a few posts ago, it has the exact same problem as my game does, so testing it using that code would have the same effect.

Here's the code I use (taking the relevent code from different parts of the overall code) to load up and use the shader on the map.



Ok, uploaded the media, so here's the link:
http://www.tornupgaming.com/Portfolio/DarkBasic/Flashlightmapmedia.zip

I'm sure it's to do with the textures, so I'll continue tweaking the files, but any help is most appreciated, and thank you Green Gandalf for your help so far!

www.tornupgaming.com
The home of free games and game projects.
headcrab 53
14
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 3rd Dec 2006 22:35
How could I change one of the lights to a spot light in 3 of Evolved's 4 Lighting Shaders from the Ultimate Shader Pack? ((2) Normal Mapping SM1.4, (3) Normal Mapping SM2.0, and (4) Parallax Mapping SM2.0)


Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Dec 2006 23:27
@Irradic

Quote: "You are really putting a lot of time into this. I can't thank you enough."


Thanks for the thanks! I'm quite happy doing this for various reasons:
1. I enjoy the challenge.
2. I usually learn something about shaders, etc, myself in the process (although at the moment I'm discovering how much I don't know ).
3. It's fascinating seeing what people manage to do with their worlds. Your "station" level is EXCELLENT.

Quote: "On the picture you see a corner, a part of the left wall has no bump effect to it, right though we can see the bump effect."


I'm not convinced that's really a problem. I think the wall on the left is only being lit by the ambient light level. If you look closely at the tiles on the right you'll see that the bright parts are the left hand edges of the tiles. That means that the light should be coming from the left, i.e. from BEHIND the left hand wall. Hence the left-hand wall won't get the bump-mapping or specular part of the effect. If I'm right, the left-hand wall should be completely black when you reduce the ambient light to zero (it's one of the constants you can pass to the shader). One of the problems with this sort of simple shader is that it takes no account of the shadowing effect of objects - hence your right-hand wall is still lit even if the light is coming from behind the left-hand wall. Remember, it's a DIRECTIONAL light in this version of the shader - so surfaces facing North will be lit by any light which has a South direction component even if the surface faces a brick wall.

Quote: "However this problem is not present in the normal map shader."


Interesting. I wonder why? I'll have another look. I vaguely recall adding a crude fix to one of my bumpmapping shaders to stop the back-facing parts of an object from being lit - doesn't seem to be in this one though. Odd.

Quote: "You have seen our object loading function, it fetches automatically all .x files in the folder. Applying the constant to a specific object would be indeed messy. We'll have to see what we can do."


Yes, that was a nice feature. However, it seems to be inefficient. For example, you load the same effect several times using the same values for the effect constants but with a different effect number. You should be able to load the effect once and apply it to each textured object. [HOWEVER, I tried that with your models and the program crashed with one of those annoying Windows errors (the Send/Do not send error report one). Will try again in case I made a silly error somewhere.] The advantage of doing it your way is that you CAN very easily specify different effect constants - either have a separate effect file with it's own constants set correctly (you've almost done this already) or have a simple text file for each object containing such extra information. No doubt there are other ways. Actually, I think there must be a simpler solution - but I don't know what it is.

Quote: "Our scheme is following, if the object is called wall.x, the program will search for wall_color.dds,wall_n.dds and wall_spec.dds. Now the downside to that is that you could only assign 1 color texture to the object. However through the 3D application we were able to apply different texture through poly selektion. The program is still loading color textures through code, because at the time our coder programmed the application there were no textures assigned through any modelling program.
If possible I will remove the code which looks up and applies the color texture to stage 0."


Yes, I'd worked that out and it seemed odd that some of the objects had textures specified in them and others didn't - and some were text .X files and others seemed to be binaries. I have no idea whether your proposed action will help matters or not (my experiments suggest it will - but I might have been lucky ).

Anyway, enough for now. I doubt I'll do much more on this today.

Thanks for letting me look around "behind the scenes".
Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Dec 2006 23:39
@Terrorist Zero

Quote: "Yeah, I said i'd used your copy of it."


That's the problem: my copy of MY flashlight shader, or my copy of EVOLVED's flashlight shader? I've posted both recently.

Quote: "By running the map using the code from the shader version you gave me a few posts ago, it has the exact same problem as my game does, so testing it using that code would have the same effect."


Er, what would be the same as what? Could you be just a bit more explicit about whose shader you are talking about, whose shader you are currently using, etc? I'm getting just a bit confused.


Anyway, it's getting late so I'll download your stuff now but look at it tomorrow.
Chris Franklin
14
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 3rd Dec 2006 23:53
Sorry to go kinda off topic i set a room on irc up for anyone with shader troubles even tho i haven't got a clue on shader's myself

so it might help alot of people #shader is the room on irc.devhat.net

On topic:
Nice to see everyone helping each other

Airslide
15
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 3rd Dec 2006 23:58
Quote: "I'm assuming you're thanking me for what I've already done ..."


Uh - ya, I kinda missed a whole page

Green Gandalf
VIP Member
15
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 00:05 Edited at: 4th Dec 2006 00:14
@headcrab 53

Quote: "How could I change one of the lights to a spot light in 3 of Evolved's 4 Lighting Shaders from the Ultimate Shader Pack? ((2) Normal Mapping SM1.4, (3) Normal Mapping SM2.0, and (4) Parallax Mapping SM2.0)"


What do you want - blood?

Have you considered using one of the flashlight shaders (mine or Evolved's) and just modifying the code a bit - and the lightmaps?

Seriously though, I'll have a quick look and see if a simple change is possible - but probably not before Wednesday though.

Some of Evolved's shaders are written in asm rather than HLSL and it takes me much longer to understand someone else's asm code - and several are written for PS1.4 and Evolved is already pushing the instruction limit for those. Instant results aren't likely.

Just so everyone knows where they stand, I'm going to try to help people in the following order (but simple requests might jump the queue ):

1. Terrorist Zero (hasn't had much detailed help yet).
2. Irradic (but probably not much more that I can do for the present).
3. Seppuku Arts (I might need more info though).
4. headcrab 53 (ditto - but I probably have enough to get started).
5. Overdroid (I think I'm still waiting for a response from him).

Cheers for now.

Edit: One blotted copy book so far - Terrorist Zero, could you sort out your download, please? The attached screenshot should speak for itself.

Attachments

Login to view attachments
headcrab 53
14
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 4th Dec 2006 00:15
Quote: "@headcrab 53

Quote: "How could I change one of the lights to a spot light in 3 of Evolved's 4 Lighting Shaders from the Ultimate Shader Pack? ((2) Normal Mapping SM1.4, (3) Normal Mapping SM2.0, and (4) Parallax Mapping SM2.0)"

What do you want - blood?

Have you considered using one of the flashlight shaders (mine or Evolved's) and just modifying the code a bit - and the lightmaps?
"


I'm using those shaders to light the world in my game. I need one light to be a spot light for a flashlight and five others to be pointlights like they are now. Click on the picture in my sig to see my WIP. That should provide more information.


Login to post a reply

Server time is: 2020-05-28 23:18:13
Your offset time is: 2020-05-28 23:18:13