Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

2D Light Shader

$
0
0

@Finnhax wrote:

Hi,

I'm starting to learn shaders and wanted to make a 2D-Light shader.
This is what I have right now:

#if OPENGL
    #define SV_POSITION POSITION
    #define VS_SHADERMODEL vs_3_0
    #define PS_SHADERMODEL ps_3_0
#else
    #define VS_SHADERMODEL vs_4_0_level_9_1
    #define PS_SHADERMODEL ps_4_0_level_9_1
#endif

sampler s0;
float4 LightColor;
float2 LightPosition;
float LightRadius;

struct PixelInput
{
    float2 pos : SV_POSITION0;
    float2 uv : TEXCOORD0;
};

float4 MainPS(PixelInput input) : COLOR0
{
    float dist = pow(input.pos.x - LightPosition.x, 2) + pow(input.pos.y - LightPosition.y, 2);
    if (dist < pow(LightRadius,2))
        return tex2D(s0, input.uv) * LightColor;
    else
        return float4(0, 0, 0, 1);
}

technique DrawLight
{
    pass P0
    {
        PixelShader = compile PS_SHADERMODEL MainPS();
    }
};

I set LightPosition to MousePosition.

This is working pretty well, except that input.pos.Y seems to be flipped (0 being bottom). Why is that and how do I fix it?

And also all tutorials I've seen always use "SV_POSITION" or "POSITION". That will throw an error for me and is only fixed by using "SV_POSITION0". What's the difference?

Greets

Posts: 6

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles