How to change Texture coordinates in MGFX Shaders in Monogame

49 Views Asked by At

I'm trying to change texture coordinates from Effect class in Monogame, how can I do that?

this is code in C#:

lighting.CurrentTechnique = lighting.Techniques["LightDrawing"]   

lighting.Parameters["RenderTargetTexture"].SetValue(_melttown[0].Texture);

lighting.Parameters["MaskTexture"].SetValue(_lightMask[0].Texture);

this is MGFX code:

float4 MainPS(float2 textureCoords : TEXCOORD0) : COLOR
{
    float4 pixelColor = tex2D(RenderTargetSampler, textureCoords);

    float4 lightColor = tex2D(MaskSampler, textureCoords);

    return pixelColor * lightColor;
}

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

I tried to change Texture Coordinates and Light will be moving on the screen

1

There are 1 best solutions below

0
LeDreamer On

If I understood your problem correctly I might have an answer to this. I assume that you registered the textures and passed it to a sampler already so your shader is working already. If you now want to offset the the light texture you have to add an offset to the lightmasks uv coordinates (texture coordiantes).

uniform float2 lightOffset;

and

float4 lightColor = tex2D(MaskSampler, textureCoords + lightOffset);

could already solve your problem. I hope I could help you a bit with this. Tell me whether I understood your problem correctly. If not I will reply later