So i also need to invert the colours on the shadowMask (From white to black and black to White, there is only 2 colours on the shadowmask). So far ive got this. The colours are getting inverted, but no matter what i put the alpha value at i’m not getting alpha through.
Also, RGB values, are they simply between 0 and 1?
how did you configure the blendstate? The BlendState is responsible of applying the alpha to the target - and of course the rendertarget should have an alpha channel as well (SurfaceFormat)
yes, you handle color values in 0-1 range in the shader (but in reality it’s byte components in vertexdeclaration)
Okay so i got it to work. I had to make the RGB values for black have a value of 0.5. Giving them straight 0 would not allow any alpha to come through and would be dead black.
I’m a little confused thoguh. I’m not using “pos” or “color1” from the PixelShaderFunction, however as soon as i take the parameters out of the method constructor it does not work.
My other question is, at the moment i need to draw this from one render target to another render target to apply this effect. Is there a way that i can apply this effect to the current render target. Using shadowEffect.CurrentTechnique.Passes[0].Apply(); still requires me to a draw call to another rendertarget.
BlendState.AlphaBlend assumes premultiplied alpha. That means, that every color is expected to be premultiplied by the alpha value. That’s why I sugessted to use BlendState.Nonpremultiplied. Which ises Source.Alpha instead of Source.One etc
If you want to copy a rendertarget to another (or process the contents inbetween) you have to set the source rendertarget as texture, and the target rendertarget as target - you then draw a fullscreen quad (or a fullscreen sprite in SpriteBatch) - this is regularily done for postprocessing effects like blurring the whole screen or fading out etc
no because the output is not deterministic on the GPU (sampling) - you would get weird results, that’s why it’s a limitiation that you cannot set a current rendertarget as texture