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
valleyman86
17
Years of Service
User Offline
Joined: 15th Dec 2006
Location:
Posted: 9th Jan 2007 18:16
Thank you
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 9th Jan 2007 19:24
@Green Gandalf

That's perfectly alright, look into it whenever you should find the time to do so. I have attached some media that you can use for testing. Thanks

Attachments

Login to view attachments
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 9th Jan 2007 21:31 Edited at: 9th Jan 2007 21:32
Quote: "I posted a fire shader earlier in this thread and also a revised one for Scraggle several posts back."


Actually the revised fire shader (and very good it is too!) was posted in my compo thread.

I was unaware of the lava shader until the recent post about it but now I have tried it in conjuction with the fire shader and the two of them look very impressive together!

I am now trying to get a water shader applied to 3d objects instead of just plains and using an image rather than a camera view. Then I could have a fire and water level in my game. The problem I am having with the water shader is UV mapping. My 3D objects all have different sized UV maps, so I am trying to come up with a way to make them all similar.

If I get it working I will post my results here. Unless of course, someone has already done it and would care to share?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Jan 2007 21:41
Scraggle

Quote: "Actually the revised fire shader (and very good it is too!) was posted in my compo thread."


I think it was posted on 30 December 2006 on THIS thread.

Quote: "My 3D objects all have different sized UV maps"


What do you mean exactly? Different image sizes? Does that matter?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Jan 2007 21:55
@Irradic

Just had a quick look at your media and I might have problems working with them. The alpha map consists of several mipmap layers but the base texture seems to consist of a single layer. A quick look suggests mipmap layer 2 corresponds to your base texture.

I know how to deal with textures that are not mipmaps but not those which are (yet). Does the alpha map need to be in mipmap form? (I probably won't be able to look at this in detail till I've had a look at headcrab 32's query - but it would be nice to have evrything in place in case I get a chance soon.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 9th Jan 2007 21:56 Edited at: 9th Jan 2007 23:10
Quote: "I think it was posted on 30 December 2006 on THIS thread."


So it was! My bad

What I mean by different sized UV maps is when I apply a water shader to the objects some have reasonable looking waves and some look atrocious due to the way the texture 'stretch' across the objects.



headcrab 53
18
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 9th Jan 2007 22:29 Edited at: 9th Jan 2007 23:15
@Green Gandalf

Quote: "Is that still your query?"


Yep. I think that the shaders are for up to 6 lights, and they have a different techniques for each number of lights you can use. Just to make sure it's perfectly clear, they are found here in the Shader Pack:


What I need exactly is one light made into a spotlight to be used as a flashlight and the others the way they are to be used as light fixtures in the level. I need all six lights, though. As it is almost every room has five lights in it and almost all of them are flickering in some way to add to the horror element of the game, so they can't be lightmapped.

(Take a close look at the dot in the background in the picutre showing where the shaders are. Something about the background is peculiar)

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2007 01:06
Scraggle

Quote: "What I mean by different sized UV maps is when I apply a water shader to the objects some have reasonable looking waves and some look atrocious due to the way the texture 'stretch' across the objects."


I see what you mean. All I can suggest is that you work out an appropriate scaling in each case relative to one that works. Then an extra parameter can be added to the shader so that the UV coords are scaled before the texture look-up in the shader. Those images you posted would be a good starting point. Should be easy to fix ... (I'm sure I've heard that before somewhere )
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2007 01:20
@headcrab 32

Quote: "Just to make sure it's perfectly clear, they are found here in the Shader Pack:"


I knew where to find them - I just didn't have them to hand at the time (I was at work in a quiet moment).

Quote: "I need all six lights, though. As it is almost every room has five lights in it and almost all of them are flickering in some way to add to the horror element of the game, so they can't be lightmapped."


Yes they can. Just construct two maps: a main one which shows the lighting without flicker, and another (this could just be the alpha channel of the first map) which stores an "offset" for different areas of the scene. The flicker can then be obtained by modulating the lightmap value by something like sin(time+offset) for each pixel. No need for lots af lights that way - and should make the shader run much faster. You will only need the other lights for the ones that move around - and perhaps not even then. Evolved posted an excellent example with a flashlight and lightmap a while back on this thread (one or two pages back?).

If you know how to construct lightmaps for the fixed lights in your scene you are most of the way there.

Just a suggestion.
headcrab 53
18
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 10th Jan 2007 03:12
The only problem with the lightmap, then, is the normal mapping and specular highlights will no longer work.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2007 13:00 Edited at: 10th Jan 2007 16:07
@headcrab 32

Quote: "The only problem with the lightmap, then, is the normal mapping and specular highlights will no longer work."


Good point. The lightmap will save on the diffuse lighting component because only one calculation is needed rather than one for each light. But the specular highlights using the normal map need to be dynamic as you say. A lightmap would make for a simpler/more efficient shader overall though.

You mention three shaders. Any preference for which one to use? And any reason for not using PS2.0 throughout?

Just had a look at the code of the three shaders and they are written in a way which should make the changes reasonably straightforward. You could probably just use Evolved's flashlight code for one of the lights - the first makes sense unless you will always have the same number of lights, i.e. the vertex and pixel shader routines VS_L1 and PS_L1 - plus minor changes elsewhere.

Edit: Just finished a first draft of the revised SM2 Normalmapping shader with flashlight added. Can't test it yet since I don't have suitable software or media here. It would save time if you could post a sample demo program with media so I can make the changes for the new shader (and test it of course).

All I have done is add another pass and oodles of techniques with Evolved's flashlight (with the lightmap removed). This is a "quick and dirty" solution and if you are using several fixed lights a revised version of the shader will run much faster if lightmaps are used. Also, Evolved's shader has many repeated instructions (i.e. identical code repeated in different passes) which could be streamlined somewhat (I have a vague feeling Evolved has done this already but I can't locate the shader). However that would require a major re-write. If you have a fast PC+GPU you might be OK. My machine will probably give a staggering 1 FPS (assuming the shader runs of course )
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 10th Jan 2007 17:35
@Green gandalf

Sorry I didn't notice that the alpha map has mimpmaps on it. I usually save them with out them. Anyway I have attached the proper maps for you. Thanks again

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2007 21:01
@Irradic

Quote: "Anyway I have attached the proper maps for you."


Thanks. I've downloaded the new file and created the new texture with the alpha channel. Will test it when I've finished sorting out headcrab's query.

For the record, I created the new texture by opening the "...color.dds" texture with DxTex.exe (comes with the free DX SDK download from MS). Then, still in DxTex, changed the view to the alpha channel and opened the "...a.dds" texture onto the alpha channel. Hey Presto - done! Took all of 10 seconds - next comes the more time-consuming mind-bending shader bit... I think we can do something.

DxTex.exe is worth more than its weight in gold.
SirLeon
17
Years of Service
User Offline
Joined: 6th Jan 2007
Location: Greece
Posted: 10th Jan 2007 21:42
For anyone interested, I managed to make evolved's parallax mapping shaders to work correctly in lightmapped models. I modified the shader only a little (check the comments in it).

Next step for someone more experienced in shader programming (GG? ) to modify it to work with multiple lights!

Best regards,

P.S. excellent thread by the way

Attachments

Login to view attachments
headcrab 53
18
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 10th Jan 2007 23:48
@Green gandalf

At the moment, there is an option in the game's option menu that lets you select one of the three shaders to use. I also noticed that the frame rate increases dramatically when you move away from the object with the shader, even though you can still see all of it. Do you know why or how this frame rate increase could happen when you're closer to the object (or even inside it?)

I've attached a small program that loads a small room and one of the shaders I mentioned and lets you float around in it. It places 5 lights randomly and the last one where the camera is. The two normal mapping shaders had the same file name so I added SM14 and SM20 so I could put them in the same folder.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jan 2007 00:44 Edited at: 11th Jan 2007 00:46
@SirLeon

Welcome to the thread and look forward to hearing more from you. Will have a quick look at your download tomorrow.

headcrab 53

I see you've been breeding - are you using parthenogenesis or something more sinister?

Quote: "I also noticed that the frame rate increases dramatically when you move away from the object with the shader, even though you can still see all of it. Do you know why or how this frame rate increase could happen when you're closer to the object (or even inside it?)"


Without actually seeing your game in action I'd guess it was to do with the number of pixels on screen that are being processed by the shader. If you're really close to the object so it fills the screen the fps (using shaders) is usually low and increases as you move away from the object. If the object is so far away it is almost invisible on screen then it will have very little effect on fps. That's one reason why a lot of effort goes into writing shaders with very few pixel (as opposed to vertex) shader instructions.

For example, if you are using an 800x600 screen resolution then an object which fills the screen will have 480000 pixels on screen. If the pixel shader uses 12 instructions then that is 12x480000 = 5.76M instructions just to process the object with the shader - and that is supposed to be happening every sync.

Writing efficient shaders is a bit like writing efficient machine code to perform a simple multiplication or division - because it might be performed a VERY large number of times it is worth removing every unnecessary instruction. That is quite different from our usual DBP programs where an extra operation (or even a thousand operations) per sync has no appreciable effect on performance.

If you run Scraggle's demo game program for example, you'll see several objects with shaders - and some of the shaders are reasonably complicated (like fur) - but because the objects don't occupy much of the screen the fps remains acceptable (even on my old machine).

Quote: "I've attached a small program that loads a small room and one of the shaders I mentioned and lets you float around in it. It places 5 lights randomly and the last one where the camera is. The two normal mapping shaders had the same file name so I added SM14 and SM20 so I could put them in the same folder."


Thanks. I'll try that out tomorrow (it's 11.38pm here and my wife is beginning to breathe down my neck ). The shader compiles now - just need to test it live with your program.

P.S. If the shader works you can have all 6 lights.

P.P.S. And if it doesn't ...

Edited annoying typo ...
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 11th Jan 2007 02:26
Thanks a lot Green Gandalf ! Looking forward to your results.
Gamecreators should consider putting you on their payroll list.
You are great help to all of us. Thanks again
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jan 2007 12:08 Edited at: 11th Jan 2007 12:18
@Irradic

Just had a quick look at the shader you asked me to modify - are you sure it's the one I helped you with earlier? The one you've just posted is one of Ninja Matt's multi-light multi-pass shaders written in asm - and it is a long one. I thought it was one of mine that you were posting when you said:

Quote: "I'm still using the normal map shader you edited for me last time. My question is, how do I go about adding another texture stage, namely an alpha channel ? I have attached the shader so you can take a look at it when you find the time."


Could you check? I don't want to waste time editing the wrong shader - especially one written in asm!!

Edit: just looked at the old files from your earlier query and Ninja Matt's shader is there! I vaguely recall editing one of his shaders for someone. Looks like I'm brain-dead today. I thought the main work I did for you was on one of mine (which you called Bump.fx and was based on my bumpmapping shader GGbump01e.fx). Could you double check to see which one you want (mine hopefully )?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jan 2007 12:30 Edited at: 11th Jan 2007 15:38
@headcrab 53 (aka headcrab 32)

A few posts back I said:

Quote: "If you have a fast PC+GPU you might be OK. My machine will probably give a staggering 1 FPS (assuming the shader runs of course )"


Guess what. Just run your test program with the second shader (before my edits) and the FPS is ... 1 !!!

Looks nice though.

Since my version just adds another pass it will be even slower (if that is possible). Will give it a go though all the same.

Edit: being held up by what seems to be an obscure vector4 bug - will post it on bug board if I can isolate it. Just need a workaround now ...

2nd Edit: OK, problem seems to be that vectors and matrices cannot share the same index value, e.g. following code destroys the vector:


Since I can't find anything in the Help files about this I'll post it as a bug. Now back to your shader query ...

3rd Edit: Not a bug, more of an undocumented feature. See this:

http://forum.thegamecreators.com/?m=forum_view&t=76412&b=15

Now back to work.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 11th Jan 2007 18:48
@Green Gandalf

The Shader you edited for me was Ninja Matts Normal Map shader.
Your bumpmap shader was working perfectly fine.
Unfortunately it is Ninja Matts shader that we need help with.
The reason we finally decided on Ninja Matts shader over yours, although your shader is a lot faster, was that we require a shader with multiple lights. The one that I have from you ggbump01e seems to only have 1 light source. Sorry bout the naming convention, but since I switched from Normal to Bump shader quiet often I renamed yours to Bump.fx, that's where my laziness kicked in.
Your shader with multiple lights, alpha channel and some way to use lightmaps would have been perfect though.
Cheers
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jan 2007 19:54 Edited at: 11th Jan 2007 23:15
@Irradic

You are quite right - my memory is playing tricks. I played around with my shader on your problem in addition to advising you how to use Ninja Matt's shader for you (which I had forgotten) which was why I'd got confused.

Quote: "Unfortunately it is Ninja Matts shader that we need help with."


OK. You'd better remind what you want exactly. Do you need lightmaps as well as alpha transparency?

Edit: I think this shader needs a specular map as well as the normal and base textures. Could you send me the one you're using? I'm beginning to think it would be quicker for me to re-write one of my own multiple light bump-mapping shaders (which in turn were based on one of Evolved's shaders - did you see his multiple light bump mapping shader? It's in section 21 of the Ultimate Shader Pack).


headcrab 53

Got something working - but to be honest your original demo with a point light 6 following the camera was just as good. For some reason that I can't quite put my finger on, the flashlight in my revised version doesn't look much like a flashlight to me. Perhaps I should try to use my own flashlight shader instead (but I'm not happy with that either ) ?

I'll keep at it though and if I get a noticeable improvement on your demo I'll post it.

I seem to be having a bad day - trying to work with too many shaders with similar code written by different people I suppose.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 12th Jan 2007 02:26 Edited at: 12th Jan 2007 02:30
@Green Gandalf

If you could implement Lightmaps and alpha that would just be excellent.
Ninja Matt's shader uses a simple gradient map and the alpha channel of the normal map texture for the specs. I have attached you an spec image with a black to white gradient. The spec map that was included in the media, that i attached in one of my previous posts, was totally black.

I was trying to implement Evolveds Bump and Normal 2.0 Shaders. However both attempts failed. The level was displayed properly however without any Normal Map or Bump effect in both cases. Unfortunately I didn't have the time to look into it again.
Guess it was just a small issue that i overlooked.

Please just pick the more convenient way for you. If editing one of your shaders would be easier and less time consuming then that's definetely the way to go.

Attachments

Login to view attachments
EVOLVED
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 12th Jan 2007 11:12
@headcrab

Iv Slightly edited to the Lighting Shaders pack to include a flash light if you still need it, get it here > http://www.vector3r.com/LightingShaders.zip
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jan 2007 13:55 Edited at: 12th Jan 2007 21:25
@Irradic

Quote: "If you could implement Lightmaps and alpha that would just be excellent."


Quote: "Please just pick the more convenient way for you. If editing one of your shaders would be easier and less time consuming then that's definetely the way to go."


OK. Will see what I can do.

Will probably find EVOLVED beats me to it again.

Quote: "The spec map that was included in the media,"


Was it? No idea how I missed that. Will check when I get home tonight. [Edit: It wasn't in the download - but no matter now.]

[Just spent some time looking over our earlier posts in November. No wonder I was confused yesterday - in November I kept referring to Ninja Matt's shaders as EVOLVED's shaders. Hope no-one other than me was confused by that ... ]


@EVOLVED

Thanks for that revised shader. I'll try it out myself when I get home. Headcrab 53 should find it useful. [Edit: looks very nice.]
SirLeon
17
Years of Service
User Offline
Joined: 6th Jan 2007
Location: Greece
Posted: 12th Jan 2007 16:46
Check the following link if you had trouble (as I had) getting shaders to work with the Dark Lights plug-in.

http://forum.thegamecreators.com/?m=forum_view&t=97389&b=18

Best regards,
Zedane
19
Years of Service
User Offline
Joined: 3rd Nov 2004
Location: Milky Way, Earth
Posted: 13th Jan 2007 01:23
What do the float4's do in the pixel lighting shader?

float4 LightPosition = {150.0f, 150.0f, 0.0f, 1.0f};
float4 LightColor = {1.0f, 1.0f, 1.0f, 1.0f};
float LightRange = 250.0f;
float4 Ambient = {0.1f, 0.1f, 0.1f, 1.0f};
float U = 1.0f;
float V = 1.0f;

LightPosition, what does the 4th value do? I guessed that light color the 4th value would be brightness. And in ambient the fouth value might also be brightness. Also, what do U and V do? Why do all the demo's set U and V to 5 on plains and stuff and on normal objects they do nothing with u and v.


around here.. normal's just a setting on a hair dryer
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jan 2007 01:49
@Zedane

In colours the fourth value usually represents the "alpha" level which is used for transparency etc - but it could represent other things like brightness or specular reflectivity if you wanted it to. You'd have to study the author's code to see how they were used.

In position vectors the fourth coordinate is required for locating the centre of the coordinate system - shaders commonly use four coordinate systems with "centres" or "origins" in different places, i.e. the object's own internal coordinates (object space), the coordinates of your world or scene (world space), the coordinates relative to the viewer (view space) and finally the projection of the view space onto the screen (projection space). The details are somewhat mathematical. When you are only interested in a direction vector (which is the difference between two points in the same coordinate system) you don't need the fourth component. That's why calculations using light directions, normals, etc, usually use float3's.

The purpose of the U and V values you mention will be specific to the rest of the code in the shader - I would guess they are default values for tiling the texture across a surface. Typically a value of one would be used if the texture doesn't repeat, whereas a value of 5 might be used if the texture was repeated 5 times across the surface. I haven't checked to see if that was the purpose in this case.
Zedane
19
Years of Service
User Offline
Joined: 3rd Nov 2004
Location: Milky Way, Earth
Posted: 13th Jan 2007 05:48
Thanks for Explaining this to me! I understood everything except the thing about the fourth coordinate being a locater. In Light Position there are four coordinates entered but three of them are the lights position, how can the fourth one alone tell the thing the center of the coordinate system? I looked at the code and it uses the whole vector as a value, i can't really understand what that does without understanding what that fourth value is.

Thanks for all the help so far,


around here.. normal's just a setting on a hair dryer
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jan 2007 14:48 Edited at: 13th Jan 2007 15:58
@Irradic

Here's a first draft plus demo of a bump mapping shader which:

1. uses alpha mapping with the base texture;
2. uses a specular map with the normal map.

It only uses one directional light plus ambient light at the moment.

My intention is to add a lightmap as a fourth texture - it will be much easier to do this rather than add lots of lights. While this will only give you fixed lights and no specular reflections it allows you to have as many lights in the scene as you like plus shadows (all of which you can prepare using your favourite artistic software - I only have Paint and DxTex.exe ).

I'm not convinced the lighting is quite right at present, but I think it makes sense for you to comment on it before I spend more time on it. The specular map is just black and white stripes on the alpha channel of an edited version of your normal map. I had a bit of trouble with that and had to change the image format to get it to work (hence the large size). It's possible the new color map has the same problem - but it is less noticeable on that.

Let me know what you think.

@Zedane

The fourth coordinate is only used when you are moving from one coordinate system to another - it, as you say, does not on its own tell you where the centre is. For example, when you move from world space to view space in the shader, you need to multiply the full float4 by the View matrix which is 4x4. This matrix does two things. It rescales the XYZ coordinates to their new units and orientation (a bit like a complicated version of turning inches into centimetres) but it also needs to shift the coordinates of the light's position relative to the centre of the view space. This second step uses the fourth component of the light position vector (it's usually just the value unity) and the fourth row and column of the View matrix. Fortunately the software looks after most of these details for you - but there are times when you need to delve a bit deeper.

If I come across a clearer explanation I'll amend this post with a link - I think I've seen one in the DX SDK docs somewhere ...

Edit: Here's a relevant link from the Microsoft web-site

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

If I find a simpler one I'll post it.

Attachments

Login to view attachments
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 13th Jan 2007 16:05
@Green Gandalf

First of all thanks a lot, I didn't expect a result so quick.
I looked into your first draft. And I think you were right about the concerns about the lighting. First thing I noticed was that the specular doesn't seem to be quiet right. I attached a screenshot so you can have a look at it.
Would it be possible to use a gray scale image of the color map ? Just as the ones which are used in 3ds max etc. ? That would offer more control for specular highlights. But anyway that's not a priority at the moment.
I'm quiet ok with the lightmap suggestion, probably it will also be better for the performance.
Would it be possible to use a bloom shader together with this shader ? We are in need for a bloom effect for the neon lights and other displays. I tried evolveds bloom shader lately but it's no longer working. I just get garbage of different colors when compiling his demo.

Thanks again for all your time and help !

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jan 2007 16:55
@Irradic

Quote: "First thing I noticed was that the specular doesn't seem to be quiet right. I attached a screenshot so you can have a look at it."


Your image shows that the specular map IS working (up to a point - see next paragraph). The specular map is a series of wide black and white stripes across the whole image. I chose that specular map because it makes it easier to see where problems are occurring.
It means that whole sections of the object get full specular reflection - or none at all. The bit you've circled shows just this effect - bands of the seat's metal upright have the reflection, other band's don't. The same applies to the seat material itself. Or do you mean something else?

Anyway, I think there IS a different problem with the specular reflection - it doesn't seem to respond to the light's direction correctly. Not sure why for the moment. Might be something to do with the normal map - I'll see what my other bump mapping shaders look like on your media.

There is no reason why you can't use greyscale for either of the two additional maps I've included (the alpha map and specular map) - but you will probably need to change the image format. I think your image format only allowed 1 bit for alpha. I changed it to A8R8G8B8, i.e. 8 bits for each colour channel as in DBP.

Your seats look much better if you use your original normal map - but that just gives a specular map of 1 throughout, i.e. full specular reflection which is no good for testing the shader.


Quote: "I'm quiet ok with the lightmap suggestion, probably it will also be better for the performance. "


OK, I'll make the amendments and test it with a crude lightmap.

Quote: "Would it be possible to use a bloom shader together with this shader ? We are in need for a bloom effect for the neon lights and other displays."


You might like to try adapting one of the glow shaders I posted earlier in this thread. The most recent one was for Peter H (might be on his thread - can't remember now). You would apply the shader to the light itself. Presumably the bump mapping shaders would be used on other objects in the scene?

Quote: "I tried evolveds bloom shader lately but it's no longer working. I just get garbage of different colors when compiling his demo."


Strange. I've just run his Bloom effect from the shader pack and got the attached screenshot. Seems fine - except I don't think it's the sort of "bloom" that you want.

Might be worth emailing him direct with your query.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jan 2007 18:16
@Irradic

Here's a new version with lightmap as well.

Note that:

1. I've added two marker objects to show where the light is pointing. The white sphere represents the light, and the red sphere indicates the direction it's pointing. You may need to move the camera back from the seat a bit.

2. I've used my version of your normal map to show the specular map - just change the dba code to use your image (image 2) for stage 1 if you prefer a better image .

3. The lightmap shows there may be a problem with your UV mapping. You will see that the lightmap is flipped horizontally on two of the seats. This doesn't matter for the textures - but could put your lightmaps and normal maps in the wrong place. In particular I guess it means the X direction of the normal map is pointing the wrong way on two of the seats. I think this would affect both the diffuse and specular light components. This might explain the difficulties you were having a while back with the bump mapping not showing on parts of your station wall.

4. I've used the same UV coords for all the textures - but I can change them easily if you need different ones for different stages. For example, I guess the lightmap would need different UV coords.

Have fun.

Attachments

Login to view attachments
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 14th Jan 2007 05:39
@Green Gandalf

I can't thank you enough. It does everything I wanted it to do. I will ask my co-artist who created the model concerning the UW map problem. Now concerning lightmaps UV coords, 1 UV for all textures should be sufficient. But in case 1 lightmap would be rendered for the whole level, a 2nd UV would be required. Would it be possible to create a uv coord flag in the shader ? One with which I could switch between the usage of 1 or 2 texture coords ?

I checked the glow shader, I very much like the effect. However we are looking for something that reproduces evolveds postbloom shader, however not fullscreen but just for certain objects.
It should only react to bright colors,like the neon tube, the digits on the station displays and other objects that are supposed to be backlit.

I have one more question concerning your bumpshader. Would it be possible to use it on a skinned/animated character ? I'm not able to test this at the moment since my character isn't ready for animation yet.

Thank you !
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jan 2007 12:34
Glad you liked it. I need to put together some more demos for my own use now!

Quote: "Now concerning lightmaps UV coords, 1 UV for all textures should be sufficient. But in case 1 lightmap would be rendered for the whole level, a 2nd UV would be required. Would it be possible to create a uv coord flag in the shader ? One with which I could switch between the usage of 1 or 2 texture coords ?"


The simplest thing to do would be to have separate UV coords for each stage. You can then map them how you like. I guess you will probably need at most two - but it's just as easy (and more logical) to allow separate coords for each stage. I was more concerned yesterday with getting the basic effect working than adding fine tuning. I'll make the necessary changes later today.

Quote: "However we are looking for something that reproduces evolveds postbloom shader, however not fullscreen but just for certain objects.
It should only react to bright colors,like the neon tube, the digits on the station displays and other objects that are supposed to be backlit."


I had an attempt at this a while back (I think I based it on one of EVOLVED's shaders) but didn't finish it off because it was too slow running on my machine. But that, if I recall correctly, is probably not a problem for your machines.) I'll try to find time this week to look at it again (after I've checked the "queue" for other outstanding requests). [Actually, I'm sure EVOLVED or someone has already done this - if I find it again I'll point you at it. ]

[Afterthought: just remembered why I didn't finish it. Bloom shaders can be speeded up significantly by doing a blur pass in the vertical direction and rendering the result to an intermediate texture, followed by a horizontal pass which blurs the result of the first pass. I wrote the code and then realised that DBPro doesn't support intermediate render targets yet. I then moved onto something else. I'll have to use a method similar to EVOLVED's.]

Quote: "I have one more question concerning your bumpshader. Would it be possible to use it on a skinned/animated character ? I'm not able to test this at the moment since my character isn't ready for animation yet."


I have absolutely no idea. All I can suggest is that you try it first on a simple demo object. Could you let us know the results, please?
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 14th Jan 2007 14:52 Edited at: 14th Jan 2007 22:14
@Green Gandalf

Thanks a lot Gandalf !
Speed shouldn't be an issue on our machines here. For slower PC's we will implement an option to enable/disable advanced gfx effects.
I'm thankful for whatever you can do concerning the bloom, once you find the time.

Concerning the animation. I just can recall something about tangent and world space, I can't remember which one belongs to static and animated objects though.
I will look if i can find an animatedskinned character and will post the results here.

[Update]

I had some time today and created a very simple viewer.
I used the the colz.x mesh from the darkbasicpro media files, which also has a couple of animations included.
I implemented your latest shader and ninja matts for comparison.
Both shaders seem to work with animated meshes.

There is one thing I noticed about when using your shader gandalf.
I can't really tell if it's the specular highlights or the lighting itself, but one of those doesn't seem to respond to the light information on the normal map but rather on the underlying geometrie of the mesh. You can't see this in the viewer but it's noticable if you use a moving light in the scene.
Probably it's just the way bump mapping works. That would explain why the pilars in the level still looked "edgy" with your shader but smooth and round with the normal map shader.

I have attached the viewer and media,
there are a couple of different textures included. You can just swap them out for different results.
I forgot to reset the screen resolution in the code. It's set to 1440x900 at the moment, don't forget to change it.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jan 2007 23:34 Edited at: 15th Jan 2007 00:16
@Irradic

I said:

Quote: "I'll make the necessary changes later today."


For some strange reason the changes aren't proving as easy as I expected. I KNOW it's possible to use separate UV coords for different texture stages in shaders because I've done it before. But I seem totally incapable of doing it today. No idea why. Will let you know when I've sorted it out - the answer is probably in my files somewhere ...

Edit: Forgot to refresh before posting - just seen your post. I'll digest that tomorrow.

2nd Edit:

Quote: "Both shaders seem to work with animated meshes."


That is good news for all concerned.

Just had a quick look at your viewer and the differences aren't very obvious. Will see if I can compare them side by side with the light moving - and against one without any bump mapping. We might know what's what then. Won't do it today though.

3rd Edit (yeah, I know, I said it'd have to wait till tomorrow ... but I love this stuff ):

You've used two lights for Matt's shader and one for mine - and the directions are different. Surely that's going to affect the visuals somehow? (Both give an fps of about 30 compared to 60 for simple texturing. ) Anyway, WILL return to this another time when I'm convinced we are comparing like with like.
valleyman86
17
Years of Service
User Offline
Joined: 15th Dec 2006
Location:
Posted: 15th Jan 2007 00:53
Is there an ice shader anywhere. I love the glow shader but is there a way to make it more glowy? It don't really fade off around the object.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 15th Jan 2007 02:07 Edited at: 15th Jan 2007 08:35
@Green Gandalf


As you said the difference is minimal. I don't know if it's the normal map, however I think it is in the required tangent space. The software I use for convertion doesn't let you select between tangent,world and object space anyway.

Yes I played a little around and added another light for Matts example and changed the direction. Anyway it wasn't my goal to pit them up against eachother for a 1:1 comparison. Just wanted to see another result. Anyway it was 4am in the morning when i created it, can be that there are some mix ups or other mistakes in it.

The observation I made concerning the lighting was actually not in the viewer. I loaded the character into your alpha stage code with the moving light.

I will see if I can get hold of a better modell with animation.
Something with a "real" normal map. I had to convert the color map into a normal map for this example. Maybe that's the issue.

Concering the shader, just take all the time you need. I got enough things to play around with at the moment. Thanks for the immense help.

Cheers

[Update]

I tried to optimize the normal map and results do look a bit better now. I think one could achieve pretty good results if the normal maps were created via a high poly mesh. Images converted to normal maps mostly don't result into good normal maps. Tweaking is neccessary to get acceptable results.
I attached the new normal map.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jan 2007 14:47 Edited at: 15th Jan 2007 20:00
@Irradic

I'm still puzzling over the issue of texture stage UV data for your seats example. It seems DBP doesn't work with UV stages in the way I first thought. Could you add a new set of UV coords to your station seat object so I can test the lightmapping issue? I thought I could do it in DBP - but can't it seems (I can only change data which is already there, it seems).

Edit: LIT has answered my query on the following thread:

http://forum.thegamecreators.com/?m=forum_view&t=97827&b=1

I can now test my bump and lightmapping shader with alpha transparency with separate UV coords. I'll post it as soon as I can, but probably not today.

Edit: Actually, here it is. With Lost In Thought's fix to the DBP code the new shader worked first time. It assumes the base texture is stage 0, normal map on stage 1 and lightmap on stage 2, and the look-up texture is on stage 3. The shader allows you to set completely different UV coords for stages 0, 1 and 2. The coords for stage 3 are set in the shader itself.

I still have to think about your issue with the lighting/geometry - but I'll put that as low priority for the moment. Hope that's OK. The main idea seems to be working.

Attachments

Login to view attachments
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 15th Jan 2007 21:55 Edited at: 16th Jan 2007 08:12
@Green Gandalf

great that you were able to figure it out. i just got the seats from my co-artist. i think you no longer need them now
thanks a lot gandalf, I will test the shader tomorrow.

[UPDATE]

I did some testing and your shader is excellent. Thanks a lot Gandalf ! We owe you big time. However can you put me on your Inquiry queue for a new Inquiry ?
Instead the lighting/geometrie inquiry, could you please instead just try to implement an alpha channel on Evolveds NormalMapping 2.0 shader ? Probably just as you did on yours, place an alpha map on the color map.
Our plan is to use your shader on level geometrie, and Evolved's Shader on our animated character objects.

Anyways, thank you for all the time and help !

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jan 2007 13:14
@Irradic

Are you entering the NVIDIA competition?

Quote: "Evolveds NormalMapping 2.0 shader"


Can you clarify precisely which shader you are talking about (in case I get muddled between Ninja Matt's and EVOLVED's shaders again)? [I'm at work at the moment and don't have the code handy.]

Anyway, I'll look at the rest of the queue first.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 16th Jan 2007 14:48 Edited at: 16th Jan 2007 14:49
I attached the shader to my last post. It's the normal map shader 2.0 "normalmappingSM20.fx", part of the 4 lighting shader pack from EVOLVED (in the ultiamte shader pack).
We are still trying to make it till the dead line, but if we will succeed is a different story. We will finish this none the less though.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jan 2007 15:56 Edited at: 16th Jan 2007 16:42
Quote: "I attached the shader to my last post."


So you did. Sorry!

Quote: "Instead the lighting/geometrie inquiry, could you please instead just try to implement an alpha channel on Evolveds NormalMapping 2.0 shader ? Probably just as you did on yours, place an alpha map on the color map."


Had a quick look at the code again. The changes required look simple at first sight - but I'm not sure. The trick is to get the required alphablending right when several passes are used. I would think the shader could be streamlined by using "for" loops rather than multiple passes (a lot of instructions are unnecessarily executed twice per pixel) - but I'll stick to editing it as is (if possible).

Edit: Fairly sure one way it can be done is as follows:

first pass - alpha blend destination with source in usual way using alpha level from base texture (i.e. srcBlend = srcAlpha, destBlend = invSrcAlpha);

second and subsequent passes - alpha blend destination with source using srcBlend = srcAlpha, destBlend = one.

The only other thing to change is the output of the various pixel shaders. These all need the alpha component to be set to the base texture alpha value.

Will try this later when I get home.

The really hard part is to get this done, tested and posted before EVOLVED does.

Edit: First uncompiled and unchecked revised version attached. I'll edit it later if it doesn't work.

I've marked all the lines I had to change.

Attachments

Login to view attachments
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 16th Jan 2007 18:18 Edited at: 16th Jan 2007 18:24
Wow, thanks a lot I didn't expect you'll do it right away.
I tested the shader with techniques Light1-Light6, everything seems to be ok and working. I didn't encounter any problems.
Guess you got it right at the first try. I can't thank you enough.

I was wondering...Depth of Field was 1 of the effects we wanted to have in-game if possible. So I did some research, but a search on the forum resulted in 4-5 posts. The latest was from 2005.
Has anybody accomplished the effect in DBPro ? I attached a nice screenshot of the effect

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jan 2007 22:28
Quote: "Wow, thanks a lot I didn't expect you'll do it right away."


I had a choice between checking that some programs were correctly set up on some machines at work and this. Guess what got priority.

Quote: "I tested the shader with techniques Light1-Light6, everything seems to be ok and working. I didn't encounter any problems.
Guess you got it right at the first try."


I'm even more amazed than you - I usually manage to miss out a bracket or a semi-colon at the first attempt. And since I used copy and paste several times I was fully expecting several copies of the same error!

I'm glad you didn't encounter any problems - but I suspect there might be a problem in some situations. If the lights can all be very bright at the same spot then you could lose the semi-transparent effect and also get a "washed-out" look to the image. Sounds like you were lucky. If it works, use it.

And I don't need to test it now.

Quote: "I was wondering...Depth of Field was 1 of the effects we wanted to have in-game if possible. So I did some research, but a search on the forum resulted in 4-5 posts. The latest was from 2005.
Has anybody accomplished the effect in DBPro ? I attached a nice screenshot of the effect"


I haven't used it myself - but it should be possible with a DOF multipass blur shader. Since EVOLVED's bloom shaders work with DBP a DOF effect should be possible too - some aspects of the code would be similar, I guess you just need to take account of the z coordinate in view space and modify the blur distance (so that it is zero at the "in-focus" distances). No, you won't talk me into this one ... yet. A good reference for anyone who's interested is "Shaders for Game Programmers and Artists" by Sebastien St-Laurent.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jan 2007 23:35
@SirLeon

You said:

Quote: "For anyone interested, I managed to make evolved's parallax mapping shaders to work correctly in lightmapped models. I modified the shader only a little (check the comments in it).

Next step for someone more experienced in shader programming (GG? ) to modify it to work with multiple lights!"


I'm afraid I've only just got around to checking your shader. Nicely done. Worked first time with some media of mine.

The quick and dirty answer to your query is to copy the approach used in EVOLVED's multiple light shader that Irradic posted a few posts back. The main point is that you will have several copies of the vertex and pixel shader code - one for each light - and several techniques, each with several passes. (But light1 will be slightly different possibly.) The code in each vertex and pixel shader will be similar to the ones in the shader you posted.

If you get stuck, post back - but you've obviously found your way around shader code at least once, so you've a good chance of success unaided.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 17th Jan 2007 13:57
Quote: "No, you won't talk me into this one "

Aww too bad ! lol just kidding. I can imagine that it would be quiet difficult. Anyway concerning the alpha map, I haven't encountered any of the situations yet. In case I shoud I hope i could find a work around. Thanks again for your help Gandalf !
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2007 14:00
Quote: "I can imagine that it would be quiet difficult."


I've had a look at this to see if I could do it, but have failed so far. I had one version which blurred things nicely according to distance - but the edges of the objects were still sharp. I then decided to "improve" the shader to give blurred edges as well and everything fell apart. Programming is like that sometimes. I'll keep at it though - if I have anything useful to report I'll post it.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 21st Jan 2007 21:00
Yes programming can be a pain. I don't know if this will be of any use for you, but I have attached a depth of field shader from nvidia. Thanks for trying.
Have a good one

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2007 21:46
Quote: "but I have attached a depth of field shader from nvidia"


Thanks. Just had a quick look - only compiles in my version of FX Composer (FXC 1.8) after a couple of minor changes. Haven't tried DBP yet - it's not at all obvious which technique we need to use - or for what.

Have you managed to get it working?

Mine's coming along (the earlier breakdown was caused by a simple typo that took ages to track down). It still has one problem though. It doesn't seem to correctly blend with the background objects for some reason. Otherwise it's making progress. But it is SLOW - far too much processing in the pixel shaders. Once I've got the basic idea working properly I'll optimise the code (e.g. there are some things that are calculated per pixel which need only be calculated once per sync by DBP!). I had to move a lot of the processing into the pixel shader so that low poly objects like plains looked right.

Login to post a reply

Server time is: 2024-03-19 09:47:02
Your offset time is: 2024-03-19 09:47:02