Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  EXT_packed_depth_stencil and fragment shaders  (Read 2132 times)
0 Members and 1 Guest are viewing this topic.
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Posted 2007-01-21 14:24:10 »

Hi all,
I honestly dont know where else to post this, since it probably is a n00b question, it has its home here. In any case...

I am using EXT_packed_depth_stencil to render to DEPTH24_STENCIL8 texture target and I wish to access the stencil value from fragment shaders in order to do some funky shadow volume/map mixing of their ambient factor.

Anyway, how can I access the stencil? The specs for EXT_packed_depth_stencil say that a sampler2D has an undefined operation on a DEPTH24_STENCIL8 format, only sampler2DShadow has defined operations. How does the sampler2DShadow deal with stencil values?

Any help on this matter is appreciated.

DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Spasi
« Reply #1 - Posted 2007-01-21 15:38:45 »

Stencil values are not accessible from fragment shaders (not sure if they've changed this in DX10). You can try using the alpha channel to accomplish stencil like functionality.
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #2 - Posted 2007-01-21 16:30:09 »

The idea was to access the stencil buffer to unify shadow maps/shadow volumes in their ambient factor so that I can mix and match them. As you probably know, the ambient factor of shadows in maps is just a constant you add at the end of the lighting equation, whereas in shadow volumes, the alpha of the full screen quad changes the ambient factor of the shadows.

I was hoping to be able to access both the shadow map and the stencil buffer from fragment shader so that I can treat both colour values the same...

Any ideas for this?

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2007-01-21 16:46:59 »

Render a big-white quad using the stencil to a texture, then sample the texture?

It's slower, but... it's obvious you can't access sstencil-values from the fragment-shader, as the fragment-shaders are not run if the stencil-test fails. Besides... stencil-buffers are plain bits, and i don't think there is a sample-function for bits out there Smiley (at least not in DX9 cards)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #4 - Posted 2007-01-21 17:08:56 »

Umm, your misunderstanding the point there riven...

I am using EXT_packed_depth_stencil as a texture format for the stencil buffer to be rendered to as a target. The texture should hold the bits of the stencil. When passing this texture to a fragment shader as a sampler2D, you cannot access the stencil information through any current means. Your slightly right in the sense that there isn't a sample function out there, but the fragment shaders that I need will run as they are not stencil tested.

I was hoping to pack the shadow map inside the 24bits of the texture and the stencil shadows in the other 8 bits and use 1 texture for both shadow maps and shadow volumes. But It seems like im going to have to forget about EXT_packed_depth_stencil for the time being as it doesn't give me enough functionality to work with.

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Spasi
« Reply #5 - Posted 2007-01-22 13:40:02 »

I was hoping to be able to access both the shadow map and the stencil buffer from fragment shader so that I can treat both colour values the same...

What you're trying to do sounds wrong. Shadow maps contain depth values, stencil buffers contain integers in the range 0-255. There's no color value.

Quote from: darkprophet
As you probably know, the ambient factor of shadows in maps is just a constant you add at the end of the lighting equation

Not exactly. The lighting equation looks like this in Marathon:

1  
half3 color = (normalMapZ * AMBIENT_PRODUCT + diffuse * shadowTerm * DIFFUSE_PRODUCT) * decal.rgb;


Then you have specular, fog, etc.

Quote from: darkprophet
whereas in shadow volumes, the alpha of the full screen quad changes the ambient factor of the shadows.

There's no full screen quad in any shadow volume algorithm I've seen.

Quote from: darkprophet
The idea was to access the stencil buffer to unify shadow maps/shadow volumes in their ambient factor so that I can mix and match them.

That's easy. Render an ambient only pass first (that also inits your depth buffer, nicely and fast), then render each light using either shadow maps or stencil volumes or both, without worrying about ambient (the shader should only add more light to the scene). Smiley
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #6 - Posted 2007-01-22 15:13:03 »

Quote
What you're trying to do sounds wrong. Shadow maps contain depth values, stencil buffers contain integers in the range 0-255. There's no color value.

Yup, i know Smiley. I would render into the depth attachment from the light's perspective. Then from the camera's perspective render the to the stencil attachment and send to the fp shader. The sampler2DShadow would then figure out which pixel is in shadow regarding the SM. With the stencil, any stencil bit/pixel thats not 0 is in shadow. You then combine the values of the stencil (clamp to between 0 and 1) and add to the SM value. You then obtain a final value to say whether this pixel is in shadow or not.

Quote
There's no full screen quad in any shadow volume algorithm I've seen.
Umm, there is. After you have the stencil buffer ready and before you render all all shadow volumes, you render a fullscreen quad so that you store it to give some ambient after wards.

Quote
The final section of this function draws one blended rectangle over the whole screen, to cast a shadow. The darker you make this rectangle, the darker the shadows will be. So to change the properties of the shadow, change the glColor4f statement. Higher alpha will make it more black. Or you can make it red, green, purple, ...!

Edit: Completed one of the quote thingies to make it look nice

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Spasi
« Reply #7 - Posted 2007-01-22 16:22:11 »

I know that some people do it this way, but it's wrong and really not needed.

It's wrong, because it doesn't work correctly on surfaces with specular highlights. You can't take a surface with specular and just darken it. The specular shouldn't have been there at all.

It's not needed, because an ambient-only pass is easier, faster and more flexible (different surfaces may have different ambient colors).
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #8 - Posted 2007-01-22 19:19:45 »

I will be very surprised if rendering the entire scene with colours and depth as an ambient pass is faster than rendering a fullscreen quad with alpha. But I guess your right about the specular highlights...

I still think that my way is faster and better than both, but its a shame that I need to render the stencil texture to another texture to get values...


Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Spasi
« Reply #9 - Posted 2007-01-22 19:30:42 »

Rendering an ambient pass first is considered good practice and may actually make subsequent passes faster (because the depth buffer values are already there).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (55 views)
2014-12-09 22:41:13

BurntPizza (88 views)
2014-12-08 04:46:31

JscottyBieshaar (50 views)
2014-12-05 12:39:02

SHC (65 views)
2014-12-03 16:27:13

CopyableCougar4 (68 views)
2014-11-29 21:32:03

toopeicgaming1999 (128 views)
2014-11-26 15:22:04

toopeicgaming1999 (119 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!