2016-03-14 42 views
-2

我将我的monogame升级到最新版本。首先在流水线工具中构建着色器时,出现错误顶点着色器'SpriteVertexShader'必须是SM 4.0级别9.1或更高!所以我改变ps_2_0到ps_4_0_level_9_1但现在我得到的错误:升级MonoGame,现在我无法让我的着色器编译

错误X3004:未声明的标识符“SecondPassTextureSampler”

任何人有关于如何解决这个问题的想法?

#include "Macros.fxh" 

texture Bitmap; 

sampler2D FirstPassTexture = sampler_state{ 
    Texture = (Bitmap); 
    MagFilter = Linear; 
    MinFilter = Linear; 
    AddressU = Clamp; 
    AddressV = Clamp; 
}; 

sampler2D SecondPassTexture = sampler_state{ 
    Texture = (Bitmap); 
    MagFilter = Linear; 
    MinFilter = Linear; 
    AddressU = Clamp; 
    AddressV = Clamp; 
}; 

#define KERNEL_RADIUS 7 
#define KERNEL_WIDTH (2*KERNEL_RADIUS + 1) 

// Uniforms 
BEGIN_CONSTANTS 
    float kernel[KERNEL_WIDTH]; 
    float2 offsets[KERNEL_WIDTH]; 

MATRIX_CONSTANTS 
    float4x4 MatrixTransform _vs(c0) _cb(c0); 
END_CONSTANTS 

struct VSOutput 
{ 
    float4 position  : SV_Position; 
    float4 color  : COLOR0; 
    float2 texCoord  : TEXCOORD0; 
}; 

VSOutput SpriteVertexShader( float4 position : SV_Position, 
           float4 color : COLOR0, 
           float2 texCoord : TEXCOORD0) 
{ 
    VSOutput output; 
    output.position = mul(position, MatrixTransform); 
    output.color = color; 
    output.texCoord = texCoord; 
    return output; 
} 

float4 gaussH(VSOutput input): SV_Target0 
{ 
    float4 color = float4(0,0,0,0); 
    for(int i = 0; i < KERNEL_WIDTH; ++i) 
     color += SAMPLE_TEXTURE(SecondPassTexture, (input.texCoord + float2(offsets[i].x, 0.0))) * kernel[i]; 
    return color * input.color; 
} 

float4 gaussV(VSOutput input): SV_Target0 
{ 
    float4 color = float4(0.0,0.0,0.0,0); 
    for(int i = 0; i < KERNEL_WIDTH; ++i) 
     color += SAMPLE_TEXTURE(SecondPassTexture, (input.texCoord + float2(0.0, offsets[i].y))) * kernel[i]; 
    return color * input.color; 
} 

float4 gaussVGlow(VSOutput input): SV_Target0 
{ 
    float4 color = float4(1.0,1.0,1.0,0); 
    for(int i = 0; i < KERNEL_WIDTH; ++i) 
    { 
     float alpha = SAMPLE_TEXTURE(SecondPassTexture, (input.texCoord + float2(0.0, offsets[i].y))).a * kernel[i]; 
     color.a += alpha; 
    } 
    // This will make stripes on top of the glow 
    /* 
    float m = smoothstep(0.45, 0.55, 0.5*cos(25.0*atan2(input.texCoord.y-0.5, input.texCoord.x-0.5))+0.5) * 0.5 + 0.5; 
    color.a *= m; 
    */ 
    color.a = pow(color.a, 0.5); 
    color.rgb *= color.a; // Yeah, you have to pre multiply your alpha -- either that or render with premultiply option 
    return color * input.color; 
} 

technique Blur { 
    pass p0 { 
     VertexShader = compile vs_4_0_level_9_1 SpriteVertexShader(); 
     PixelShader = compile ps_4_0_level_9_1 gaussH(); 
    } 
    pass p1 { 
     VertexShader = compile vs_4_0_level_9_1 SpriteVertexShader(); 
     PixelShader = compile ps_4_0_level_9_1 gaussV(); 
    } 
    pass p1Glow { 
     VertexShader = compile vs_4_0_level_9_1 SpriteVertexShader(); 
     PixelShader = compile ps_4_0_level_9_1 gaussVGlow(); 
    } 
} 

Macros.fxh为:http://pastebin.com/y51kFfii

+2

您的着色器看起来不像GLSL;什么是'技术'和'传球'?另外,'SecondPassTextureSampler'不会出现在着色器中;你确定这是你的着色器失败,而不是你的C#代码吗? –

+0

谢谢你的采访。 techinque和pass均来自我链接的XNA宏。 SecondPassTextureSampler get的自动创建我认为。我甚至没有运行C#代码,只是Monogame管道工具。 –

回答

0

从Monogame论坛: 因为你使用的采样宏SAMPLE_TEXTURE你得到一个错误,但不要使用宏DECLARE_TEXTURE宣告质感。 如果要使用Macros.fxh中的宏,则纹理需要命名为SecondPassTexture,而采样器需要命名为SecondPassTextureSampler。 (不要更改其中SAMPLE_TEXTURE被称为行。)

如果你看看在宏观(_Macro.fxh,第31行),代码

SAMPLE_TEXTURE(SecondPassTexture,(input.texCoord + FLOAT2(0.0,偏移[I] .Y))) 扩展到

SecondPassTexture.Sample(SecondPassTextureSampler,(input.texCoord + FLOAT2(0.0,偏移量[I] .Y))) 但是你的情况(原始信息)它应该是

Bitmap.Sample(SecondPassTexture,(input.texCoord + float2(0.0,offsetsets [i] .y))) 这里是一个更简单的解决方案,您可以尝试: 只需将所有SAMPLE_TEXTURE替换为tex2D即可。 (将采样器保留在原始文章中。)

+0

另外需要注意的是,我遇到了额外的问题,并且发现安装MonoGame 3.5时,我的以前安装过程很糟糕,并且卸载并重新安装了一些固定的问题。 –