如何在MonoGame中使用着色器? [英] How to use shaders in MonoGame?

查看:149
本文介绍了如何在MonoGame中使用着色器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我,如何在单人游戏中使用着色器吗?

Can someone tell me, how to use shaders in monogame?

我有此错误: https://gamedev.stackexchange.com/questions/46994/有任何人都能在Windows 8的Monogame中获得-照明引擎的工作原理

我尝试使用2MGFX,但该工具报告:效果必须至少包含一种技术并通过.从myshader.fx文件中可以看到它.

I tried to use 2MGFX, but the tool reports: The effect must contain at least one technique and pass. From what I can see from myshader.fx the file, it does.

这是我的着色器代码:

sampler TextureSampler : register(s0);
float _valueAlpha = 1;
float _valueRGB = 1;

float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
    // Look up the texture color.
    float4 tex = tex2D(TextureSampler, texCoord);

    // Convert it to greyscale. The constants 0.3, 0.59, and 0.11 are because
    // the human eye is more sensitive to green light, and less to blue.
    float greyscale = dot(tex.rgb, float3(0.3, 0.59, 0.11));

    // The input color alpha controls saturation level.
    tex.rgb = lerp(greyscale, tex.rgb *_valueRGB, color.a *_valueAlpha);

    return tex;
}
technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_3_0 main();
    }
}

我尝试将技术更改为Technique,并将通行证更改为Pass,但仍然抛出"效果必须包含至少一种技术并通过"

I tried changing the technique to Technique, and the pass to Pass, but it still throws "The effect must contain at least one technique and pass"

推荐答案

我成功了! :)

首先,我使用了2MGFX工具.然后我加载了这样的效果:

First of all I used 2MGFX tool. Then I loaded the effect like this:

BinaryReader Reader = new BinaryReader(File.Open(@"Content\\myShader.mgfxo", FileMode.Open)); 
myShader = new Effect(GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length)); 

希望它也会对其他人有帮助! :)

Hope it will help someone else too! :)

谢谢!

这篇关于如何在MonoGame中使用着色器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆