0
\$\begingroup\$

I've been working on a mod for "Duck Game" that adds dark levels like in Spelunky.

I read this guide on how to make shaders, but in my case I don't have access to the draw method and since the game isnt drawn in a rendertarget first I can't do the same blending as he did.

I wrote my own shader that sets the alpha based on the average color value, looks like this:

float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
    // TODO: add your pixel shader code here.
    float4 color = tex2D(s0,coords);
    color.a = 1-((color.r + color.b + color.g)/3);
    return color;
}

And it looks like this in game:

enter image description here

I personally isn't satisfied with how this looks but to make it like in the tutorial (which is way better) I would need to get the sampler of the main draw (with current rendercontext set to null).

Is there a way to get the pixels on screen so that I can use it like in the tutorial?
I'll also accept answers with better ways of doing it.

\$\endgroup\$
  • \$\begingroup\$ Could you explain exactly what is wrong with the picture please, not knowing what your game is meant to look like makes it hard for me to see the problem. \$\endgroup\$ – Thomas Mathieson Oct 13 '17 at 18:58
  • \$\begingroup\$ what im trying to achieve: youtu.be/J1xr9kbQXKI I dont even think its possible tho \$\endgroup\$ – eim64 Oct 14 '17 at 8:53
-1
\$\begingroup\$

Ok, so I'm not an expert in XNA, but provided it uses standard GLSL then you might be able to do:

if (color.a < cutoff)
{
    discard;
}

This would mean that you don't alpha blending but you can still do alpha clipping where you discard the pixel if it's not opaque enough (based on the cutoff variable). If it uses HLSL then the equivalent would be:

clip(color.a-cutoff);

I hope this helps,
-Thomas

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.