One for Yves: Alpha with effect applied to layer
Yves, a moment of your time good sir!
You reported a known bug in one the earlier builds of HWA as follows:-
Effects on layers are incompatible with the alpha channel of objects on this layer and with effects that affect the object transparency. I don't know yet if this issue will be fixed or not.
An example for anyone who's interested!
http://img341.imageshack.us/img341/9...aphicerror.jpg
Alpha channels are extremly useful (as you are probably aware!) Creating glowing particles, soft edged shadows or blending textures or objects together are just a few examples of alpha channels in action! All that would have to be sacrificed the moment you add a layer effect, this seems a steep price to pay.
Say you want your camera to zoom in and out of the battlefield, a night vision camera effect, an undulating water scene perhaps? This is where layer effects come into their own!
It seems a heavy restriction on a build thats created solely for creating great looking graphics, I guess thats what I'm trying to say!
Do you know if this will ever get resolved? My current project relies heavily on layer effect shaders and the lack of alpha channels is a real blow.
Many Thanks
John
Re: One for Yves: Alpha with effect applied to layer
I'm sorry, I don't know if this will be resolved in MMF2, I tried to fix it and didn't find a solution. Maybe if I've an idea later...
Re: One for Yves: Alpha with effect applied to layer
Come on Yves, work that keyboard, make that magic happen! YOU CAN DO IT!!
Re: One for Yves: Alpha with effect applied to layer
I believe it's an issue with how colour/alpha is written to the intermediate render buffer. Unfortunately it's a complete PITA to fix, you basically have to do your own alpha blending in the object's pixel shader, instead of letting direct-x do it.
This is the code:
NewBufferAlpha = Lerp(BufferAlpha, 1, ObjectAlpha)
NewBufferColour = Lerp(BufferColour, ObjectColour, ObjectAlpha)
And you would need to set the D3D blend mode to ONE,ZERO (i.e. overwrite behaviour) instead of SRCALPHA,INVSRCALPHA (alpha blend) when rendering into the layer, and then ONE,INVSRCALPHA when rendering the layer into the main buffer.
EDIT: It's much easier in D3D10, unfortunately. You just set the render state to SRCALPHA,INVSRCALPHA for the colour and ONE,INVSRCALPHA for the alpha when drawing the objects into the layer, and you end up with a premultiplied-alpha texture. You can then blend that onto your output buffer with colour: ONE,INVSRCALPHA and alpha: whatever. If you set the alpha state to ONE,INVSRCALPHA again then you end up with another premultiplied-alpha buffer and can repeat the process :)
Re: One for Yves: Alpha with effect applied to layer
Yes Dynasoft, that's exactly the problem.
Re: One for Yves: Alpha with effect applied to layer
premultiplied-alpha buffer eh? wow.... Im not even going to pretend to know what all that meant!
Re: One for Yves: Alpha with effect applied to layer
Suffice to say I was talking about some very behind-the-scenes stuff that Yves has understood. It's unfortunate that the DX9 version of the fix is so nasty (requiring shader changes), Yves may decide not to implement it.
Re: One for Yves: Alpha with effect applied to layer
Well it would certainly be nice if it ever was :3
I've been experiencing ages of problems with this with my current project, making me have to adjust the alpha values of all objects whenever I want to apply a layer shader, so it gets a lot of graphics artifacts. For example in my time engine thing, most transparent particle effects will be invisible while not overlapping the background while I apply the time-rewinding shader, because of their alpha channels. Its a pain on the eye :p
*edit: and doing workarounds really IS a pita, mind, since I have to lerp the alpha values of overlapping objects to halve the distance between them or some odd thing like that, so some objects that had partial transparent sections will have those sections become fully transparent and the rest become partially transparent. I think I might rewrite the shader I'm using for the layers to accommodate for this if its not going to change, I'll have to remind myself that
Re: One for Yves: Alpha with effect applied to layer
Actually is there any generic way to modify a pixel shader that otherwise doesn't use alpha values to overcome this problem? It would sure be nice
I mean Dyna if you had that as an example in a PS9 shader I'd be very thankful! :D
Re: One for Yves: Alpha with effect applied to layer
No, there's no way to fix it AFAIK without changing the blend formula.