Sign in to follow this  
skydave

glsl: how to not write all gl_FragColor components

Recommended Posts

skydave    128
Hi, I have a question regarding the behaviour of writing to a subset of all gl_FragColor components. When I run my glsl code doing something like gl_FragColor.xy = ... it will overwrite the z and w values with 0. But in some resources I sometimes read that the input texture is also used as the target texture into which is rendered because the inputchannels are different than the output channels. With the behaviour I get its not possible to resuse the texture in that way (without sampling the value of zw and writing it again). Now my question: is it supposed to work like this (meaning: it is not possible to write certain channels only and leave all others as they are) or am I just missing something? From what I gather I think it is not possible because thats what the discard; command is for (otherwise we could just not write to gl_FragColor). Whats the oppinion of the glsl pros here? Thanks alot, David

Share this post


Link to post
Share on other sites
karwosts    840

Maybe glColorMask can work for you?

I'm not sure if according to the spec it is legal to read/write to the same buffer, even if you use different channels, so this might be undefined behaviour. Worth a try though.

Share this post


Link to post
Share on other sites
skydave    128
Hey Thanks alot for your replies.

@Prune: whats the proper way to do it? gl_FragData[]?

@karwosts: glColorMask is a good hint ! Thanks! I think I might use it.

The source I was refering to is the dof implementation of starcraft2. In their siggraph paper they say that they compute CoC in the alpha channel of a map and use the same map to store the blured rgb values of the source image. Either they somehow manage to prevent overwriting the alpha value or maybe they blur and compute in one shader together (which I dont like).


However, I think I've enough to go on.

Thanks and happy coding,
David

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this