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 / Combining shaders?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Feb 2012 00:32
Hi


So what happens when I want to have a reflective parallax mapped object? To my knowledge I can't apply 2 shaders (parallax and cube mapping) to a single object... How would I combine the two?

What I need is a shader with the following:

Stage 0 - Base texture
Stage 1 - Normal map
Stage 2 - Bump map
Stage 3 - Emissive map
Stage 4 - Specular map
Stage 5 - Alpha map (controls transparency, black = invisible, white = solid)
Stage 6 - optional cube map

This is the shader that needs to be modified (thanks a lot to revenant chaos for adding the emissive map and multiple lights):



Is this doable, or am I asking too much now?

TheComet

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 00:59
I once coded a Detail map and normal map based shader using two of Evolved's shaders. There is a limit on how many variables you can create in one shader; something like 32 (correct me if I am wrong), so I had to remove some features to fit the normal map FX code in.

Perhaps your requirement is just plain difficult to do in HLSL 2. If someone doesn't know how to do what you want, you may need to use two sets of limbs to blend two effects.

I remember seeing somewhere, somebody rendered an object twice using fast sync and sync mask. I think it was the water shader.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 02:17
Quote: "How would I combine the two?"


It's just a matter of understanding the code and making the appropriate changes as in any other programming language. I'll try to find time to look at this tomorrow (unless someone else gets there first).

Quote: "I remember seeing somewhere, somebody rendered an object twice using fast sync and sync mask. I think it was the water shader."


That was probably a completely different problem to do with cameras, clipping planes, etc.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 03:06
Quote: "I'll try to find time to look at this tomorrow (unless someone else gets there first)."


Looking forward to seeing this.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 13:33
Here's the first draft.

I've changed only the pixel shader for one light as the others can be changed in exactly the same way. You'll need to adjust your "tweaks" to get sensible results of course.

That shader is rather cumbersome and could be streamlined enormously by using for loops in higher shader versions such as PS2a or PS3.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 13:37 Edited at: 1st Feb 2012 13:37
Screenshot from Dark Shader using images from one of EVOLVED's demos.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 14:24 Edited at: 1st Feb 2012 14:27
Top notch!

I wonder why DarkShader displayed variable count errors the last time I tried this? I will need to learn from this example.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 15:52
Thanks.

Quote: "I wonder why DarkShader displayed variable count errors the last time I tried this?"


Did you try to cram too many lights into one pass?
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 16:57 Edited at: 1st Feb 2012 17:11
It was light heavy I guess since it contained a normal mapping script. I was just playing around at the time, but will need to do what TheComet is trying; use fewer shaders with more options.

I tend to try to 'detailmap' my objects to make the visuals less repetitive, so I was trying to add a detail texture to all of the other shaders, starting with the normal map shader, which checks for 8 lights if I remember correctly. (If I had it on me I would have attached it; it was a long while ago since I did any FX work).

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 18:48
I'd need to see the shader code before I can be more specific.

Pixel shader instruction count limits are quite tight on PS2 and below which is probably why Evolved coded the present shader that way. One of the shaders that comes with Dark Shader shows a better way if you are able to use a higher shader version such as PS2.x or higher.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 19:55 Edited at: 1st Feb 2012 19:56
Ok I found it. It does not include comments and is unfinished as I was only playing around at the time; but it works. It was derived from the two Dark Shader samples; it has sliders for adjusting the blending of two textures and the contrast of the normal filter.





Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 20:21 Edited at: 1st Feb 2012 20:21
If it works I guess there's nothing to fix.

Anyway, just had a peek at your shader. I see you're using the method used by the Dark Shader version which uses a single pass. That could be your problem. Here's what the DX9 SDK docs say about instruction counts for PS2:



It seems you are lucky it works at all. I suspect the actual limit for PS2a depends on your GFX card since your instruction count is far in excess of the guaranteed limit of 96. You might find your problems go away if you can use PS3 instead which has a guaranteed limit of 512 instructions.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 20:36 Edited at: 1st Feb 2012 20:37
Quote: "If it works I guess there's nothing to fix."


I was intending to add reflection or cube mapping (like TheComet) which is my problem. I settled with normal mapping, due to trying to add reflectivity but being limited by what you say.

Based on your advice I should be able to get it working. Would be nice to see some reflections of shiney surfaces...

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2012 21:01
Good luck. Just post if you have problems but I think you should be almost there now.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 21:27
Thanks for the help. I will post up my progress when I attempt the task.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Feb 2012 17:18
That's amazing GG! Would it be possible to add an emissive, specular, and alpha map as well?

I've been testing the limitations of DBP and I found that DBP will crash if you try to apply the parallax shader to an object with more than 22k polygons. Why could that be?

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Feb 2012 18:51
Thanks. It already has an emissive map facility.

You can add two more textures (the limit is 8) so yes, you can add specular and alpha maps as well.

However, you might not need to. If some of your maps only need one colour channel and use the same UV coords then you could combine them into a single image. For example, the heightmap could be stored in the red channel, specular in the green channel and so on. You would then just need one texture read instead of three in the shader and you can pick out the channels you need in the shader code.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Feb 2012 03:23
Im keeping track of this...

I had this question in my head for some time now...

So a silly question... what reasons other than hardware would you not use PS3.0 over PS2.0?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Feb 2012 12:37
None really - although I do remember reading somewhere (on the nVidia site?) that if you can use a lower shader model then it can run slightly faster. However I don't have any specific evidence of my own to support this and I guess the differences are hard to predict unless you know a lot about the actual machine code produced by the different compilers. I'd be surprised if the differences were more than marginal though. I use PS2 out of habit more than anything else and only resort to PS3 when I need to. PS3 does have a few additional features which can be useful.

I guess shaders are just as subject to code bloat as everything else.

Login to post a reply

Server time is: 2026-07-10 04:20:01
Your offset time is: 2026-07-10 04:20:01