如何在 Monogame 中更改 MGFX 着色器中的纹理坐标

问题描述 投票:0回答:1

我正在尝试从 Monogame 中的 Effect 类更改纹理坐标,我该怎么做?

这是 C# 中的代码:

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

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

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

这是MGFX代码:

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();
    }
};

我尝试更改纹理坐标,光线将在屏幕上移动

xna monogame hlsl
1个回答
0
投票

如果我正确理解你的问题,我可能会有答案。 我假设您已经注册了纹理并将其传递给采样器,因此您的着色器已经在工作了。 如果您现在想要偏移光纹理,您必须向光罩 uv 坐标(纹理坐标)添加偏移量。

uniform float2 lightOffset;

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

已经可以解决你的问题了。我希望我能帮到你一点。告诉我我是否正确理解了你的问题。如果没有我稍后回复

© www.soinside.com 2019 - 2024. All rights reserved.