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 / does anyone know how to initialise the stencil buffer cleanly?

Author
Message
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 19:38 Edited at: 8th Sep 2011 19:40
In an attempt to understand how shadow volume shaders work I thought it was time I understood the stencil buffer. Here's a simple demo of the stencil buffer at work. In the demo the central part of the screen contains an invisible object which allows you to see through walls (see image below). The stencil buffer is accessed in the shader.

The demo requires the stencil buffer to be cleared each sync before any other rendering takes place. I couldn't find a simple way of doing this - I had to add an extra object (a plain in front of the camera) which was rendered first and cleared the buffer using this and a shader.

Is there a simpler way?



I'm no nearer getting a shadow volume shader though.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 19:40
Screenshot for previous post.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th Sep 2011 19:46
Wow! I know nothing about shaders as of yet but that gives me an idea for xray vision with your code...

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Sep 2011 21:57 Edited at: 8th Sep 2011 21:59
The stencil buffer is only cleared when needed - if you don't do anything in DBPro that requires the use of the stencil buffer then it will leave it uncleared.

[EDIT]Addition to make it clearer - remember that DBPro can't see inside your shader so doesn't know you use the stencil buffer. DBPro needs a command that accesses the non-shader pipeline for it to determine that the stencil buffer is being used.[/EDIT]

The code in the rendering pipeline seems to require shadow shading to be active on at least one object, and that global shadows are also enabled.

That's basically:


The object you enable shadow shading on does not actually have to be rendered if it interferes with your scene - you can exclude it if you wish.

Give it a go and let me know how it turns out.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 22:00 Edited at: 8th Sep 2011 22:15
Thanks. I'll try that.

While we're on the subject, any idea why the set shadow shading on command seems to be completely broken as of U77RC7 when you try to use the shader option?

Edit Thanks for the edit - you've answered a question I decided against asking.

Edit2 It sort of works but it seems some other things need to be changed. For example, it destroys the default DBPro lighting on object 1 in my demo. I'll check out Spooky's old demo and see what else needs to be fixed.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 22:42 Edited at: 8th Sep 2011 22:42
No. I can't seem to get the "shadow shading" method to work correctly. Everything works except for the lighting. The "invisible" sphere in the middle of the screen remains visible whatever I've tried (the stencil part works fine - it's the lighting I can't seem to fix):

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2011 15:22
Hmm? Strange. This revised and simpler version of the demo seems to work perfectly without explicitly clearing the stencil buffer.

One of my fixes must have cured the original problem I was having.
david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 11th Sep 2011 05:00
Why clear the stencil buffer? Why not just set it to all one value?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Sep 2011 15:33
Quote: "Why not just set it to all one value?"


That's what I mean - and how would you do that cleanly?

Anyway, the original question seems redundant now since it seems that DBPro clears it by default anyway. I must have done something wrong in one of my earlier demos and then fixed it without realising. The latest demo works cleanly without explicitly clearing the stencil buffer to a value. Haven't checked but I guess it gets cleared to zero.
Morcilla
23
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Sep 2011 19:28
Hey hi GG,
So is this exercise just for learning purposes or could it have any practical use or advantage that we can take?
Just wondering

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Sep 2011 19:44
I have had an idea that I want to try out. Click the link. You see how shapes are masked out to create a GUI? I would just like a program to cut out the mask shapes very quickly. I think you could end up with more complex GUI interfaces like that. Then just save the stencils, and load them into Photoshop for editing. So is that possible using this method?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Sep 2011 23:57
Quote: "So is this exercise just for learning purposes"


Mainly.



Quote: "or could it have any practical use or advantage that we can take?"


The X-ray idea mentioned by WLGfx perhaps?

Login to post a reply

Server time is: 2026-07-11 04:44:07
Your offset time is: 2026-07-11 04:44:07