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 / How would I modify this shader?

Author
Message
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 31st Jul 2015 23:39
I'm trying to modify this cubic shadow mapping shader to blend a lightmap from dark lights as well. I tried but couldn't get it to work, so I've instead been rendering two copies of the same level with different shaders on them, which is just silly.

I know I need to add some new code under textures but from then on I'm lost.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2015 00:02
I assume the lightmap is to be applied to one or more fixed objects such as the ground and buildings. If that is the case then the lightmap would normally be applied using a specially prepared set of UV data for the objects - usually stage 1. Is that the case? If not how is the lightmap being applied to the object or objects?

Once we know that then we can move forward. The necessary changes to the shader should be straightforward.



Powered by Free Banners
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 1st Aug 2015 00:05
Quote: "I assume the lightmap is to be applied to one or more fixed objects such as the ground and buildings."

Correct! I can post some media for testing if helpful.

Quote: "The necessary changes to the shader should be straightforward."

I was really hoping so!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2015 00:47
Quote: "Correct! I can post some media for testing if helpful."


Good.

Yes, some simple media would be helpful.



Powered by Free Banners
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 1st Aug 2015 01:06
Here you go.

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: 2nd Aug 2015 13:47
Thanks. I'll have a look today. Was busy with other stuff yesterday.



Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Aug 2015 14:41 Edited at: 2nd Aug 2015 15:14
Had a quick test of your media before checking the cube bit. The lightmap seems to apply OK, but I can't seem to get the base texture to look right. Here's what I see when I apply the base texture to stage 0 and the lightmap to stage 1:



Edit Never mind - your shader seems to apply the base texture sensibly. I should be able to figure it out from that. What method were you using for applying the cubic shadow map?

Edit2 Forget this - the object had clamp set as its texturing mode. Shaders override that setting and use wrap by default. Should be able to fix your shader easily now.



Powered by Free Banners

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: 2nd Aug 2015 17:41 Edited at: 2nd Aug 2015 17:41
OK. Here's the first draft:

DBPro code:



Shader code:



There's still a problem. If you change the light position by holding the left or right keys, you'll see the shadows for your object are wrong. The pillars don't seem to be casting shadows for some reason. No time to investigate right now - but at least you've got the light map. I've probably overlooked something simple.





Powered by Free Banners

Attachments

Login to view attachments
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 2nd Aug 2015 17:44 Edited at: 2nd Aug 2015 19:33
Very cool!
I was going to say you could probably get rid of the problem in the previous post with set object texture but it looks like you've already dealt with it directly.

Edit
I wonder if this is the same issue you we're describing in the demo; it seems the lighter the lightmap is, the more invisible the real time shadows are.

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: 2nd Aug 2015 19:36
Quote: "I was going to say you could probably get rid of the problem in the previous post with set object texture but it looks like you've already dealt with it directly."


Yes, that's needed if you're using standard DBPro rendering but not if you're using a shader. In fact that's one reason I usually make the texture filtering and addressing modes explicit in the samplers - I haven't bothered to alter those in the shader.

Have you spotted the error or the cause of it yet? I haven't had time to investigate it yet.



Powered by Free Banners
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 2nd Aug 2015 20:35 Edited at: 2nd Aug 2015 20:39
Quote: "Have you spotted the error or the cause of it yet?"

I think I ninja edited my last post while you were typing. I'm not actually sure what's going on with that testing model, it seems bugged somehow and it isn't happening in the level I'm working on.
(This image is overly dark, but you can see the shadows from the columns)


Edit
Actually it may have something to do with the lightmap alpha, perhaps in a lit area the shadows are being rendered but are invisible. (see previous image above)

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: 2nd Aug 2015 21:20 Edited at: 2nd Aug 2015 21:23
Quote: "but you can see the shadows from the columns"


Are those shadows from the lightmap or from the realtime shadow map?

I'm assuming you are using the shadow map for dynamic objects and light, i.e. movable, whereas the lightmap is for all the fixed lights and objects.

Quote: "I think I ninja edited my last post while you were typing."




I think I posted my reply to your edit too soon.

Do you mean the missing shadows from your character's legs and feet? If so, then yes it is the same issue. There seems to be some strange clipping going on that I can't explain yet. Here's another screenshot illustrating the same problem. The yellow lines mark two edges of the shadow frustum cast by the light. As you can see, one line matches correctly with the shadow on the floor, the other doesn't - see the shadow edge marked "?". I've done some experimenting and still can't see what's causing that obvious error.





Powered by Free Banners

Attachments

Login to view attachments
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 2nd Aug 2015 22:03
Quote: "Are those shadows from the lightmap or from the realtime shadow map?"

Those are from the real time shadow map.

Quote: "using the shadow map for dynamic objects and light, i.e. movable, whereas the lightmap is for all the fixed lights and objects."

Quote: "Do you mean the missing shadows from your character's legs and feet?"

Yes and yes, respectively.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Aug 2015 00:45
Hmm? That's reassuring anyway.

I thought of something while I was cooking supper - but it's gone now. This needs a fresh look when I'm wide awake.



Powered by Free Banners
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 3rd Aug 2015 01:02
Quote: "I thought of something while I was cooking supper - but it's gone now."

I can most definitely relate to that.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Aug 2015 13:18 Edited at: 3rd Aug 2015 13:18
Weird. I've just created a simple test scene and I don't get the problem. The shadows are created using the shadow map, the light map is just plain dark blue (because I'm lazy ).



So it seems there's something odd about your test object as you suggested. However, I've saved it as a mesh .X file and cannot see anything obviously wrong with it. Also, if I load the X file instead of your dbo file the problem is still there.

Perhaps there's something weird hidden in the FVFdata structure of the file? There's one way to find out I guess.



Powered by Free Banners

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: 3rd Aug 2015 19:26 Edited at: 3rd Aug 2015 19:43
Well, that was a bit of a marathon! After a fair bit of fiddling about I managed to get the shadow mapping shader and a light map to display correctly on a version of your object:



I'm not sure what the crucial step was but what I did was roughly as follows:

1. save your object as a mesh X file;
2. load it into MilkShape;
3. export it as a new X file using the JT DirectX exporter;
4. create a new lightmap and lightmap object using DarkLights (so the light map will differ somewhat from yours).

At that point everything was fine till I tried to use the shader and demo code as before - I had a new set of glitches. However, I tried saving the new lightmapped object as a mesh X file again and used that in DBPro instead of the source DBO file. This time everything worked as it should.

I'll zip up the new test project and media in the next post. I've no idea which specific step is causing the problem - but I'm fairly sure it's something to do with the dbo files produced by Dark Lights.

[I know you don't really need this but I couldn't resist the challenge of getting this to work somehow. ]



Powered by Free Banners

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: 3rd Aug 2015 19:46
Here's the zip file of the whole project. Change the following line to see problems with the new source DBO object:





Powered by Free Banners

Attachments

Login to view attachments
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 3rd Aug 2015 21:03
That's really weird. I couldn't try it myself, as I don't own milkshape and the demo version doesn't seem to have DirectX export - but as my level doesn't seem to have that problem (I have no idea what I did differently for the demo media!) everything is looking pretty nice.
The newer version of the shader seems to produce much crisper shadows.

Thanks for your help GG! If you ever need some music, models or textures let me know.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Aug 2015 01:49 Edited at: 4th Aug 2015 01:52
Quote: "The newer version of the shader seems to produce much crisper shadows."


That was a mistake on my part. I forgot to clean up the shader code after I had established that the shader was not at fault. While I was experimenting I'd commented out the filtering of the shadow edges and used simple shadowing instead. Here's the relevant bit of code:



Similarly, there are several lines which could be deleted. I'll post a cleaner version tomorrow - it's far too close to midnight here for me to risk anything technical tonight. [Edit: Let me know whether you prefer the crisper shadows or whether you want the filtering reinstated.]

Quote: "Thanks for your help GG! If you ever need some music, models or textures let me know."


You're welcome - and thanks for the offer.



Powered by Free Banners
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 4th Aug 2015 02:41
Quote: "Let me know whether you prefer the crisper shadows or whether you want the filtering reinstated."

To be honest, I think I like the crisp shadows better.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Aug 2015 15:25
Fine. Here's the tidied up shader. I've added a few comments in case you need to change back to filtering.



Powered by Free Banners

Attachments

Login to view attachments
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 16th Aug 2015 20:32 Edited at: 16th Aug 2015 20:32
Potentially stupid question; If I was to add depth of field along with this shader and bloom, should the bloom camera be rendered before or after the dof, or doesn't it matter?

Login to post a reply

Server time is: 2024-04-20 09:53:41
Your offset time is: 2024-04-20 09:53:41