2011-06-20 156 views
2

使用XNA 4可以在另一个着色器中包含着色器吗?我知道你可以在3.1之内做到这一点,但我似乎无法使这个工作?如果可以的话,任何指针都会很棒。包含着色器的着色器?

编辑

//---------------------------------------------------------------------------// 
// Name : Rain.fx 
// Desc : Rain particle effect using cylindrical billboards 
// Author : Justin Stoecker. Copyright (C) 2008-2009. 
//---------------------------------------------------------------------------// 

#include "common.inc" // It's this line that causes me a problem 

float4x4 matWorld; 

float3 vVelocity; 
float3 vOrigin;   // min point of the cube area 
float fWidth;   // width of the weather region (x-axis) 
float fHeight;   // height of the weather region (y-axis) 
float fLength;   // length of the weather region (z-axis) 

... Rest of file ... 

的“common.inc”文件在有变数,但我想知道,如果你可以把方法在那里呢?

+0

你能举一个XNA 3.1的例子吗? –

+0

@Andrew Russell:更新的问题 –

+0

你说这会导致你一个“问题” - 你能更具体吗?错误信息?另外值得指出的是:内容管道已更新为使用XNA 4.0中较新版本的着色器编译器。 –

回答

1

是的,这是可能的,从内存中我认为从MS应用程序中心的基本效果示例着色器示例做它。

无论如何,请看下面的代码!

FractalBase.fxh

float4x4 MatrixTransform : register(vs, c0); 

float2 Pan; 
float Zoom; 
float Aspect; 

float ZPower = 2; 

float3 Colour = 0; 
float3 ColourScale = 0; 

float ComAbs(float2 Arg) 
{ 

} 

float2 ComSquare(float2 Arg) 
{ 

} 

int GreaterThan(float x, float y) 
{ 

} 

float4 GetColour(int DoneIterations, float MaxIterations, float BailoutTest, float OldBailoutTest, float BailoutFigure) 
{ 

} 

void SpriteVertexShader(inout float4 Colour : COLOR0, 
         inout float2 texCoord : TEXCOORD0, 
         inout float4 position : SV_Position) 
{ 
    position = mul(position, MatrixTransform); 

    // Convert the position into from screen space into complex coordinates 
    texCoord = (position) * Zoom * float2(1, Aspect) - float2(Pan.x, -Pan.y); 
} 

FractalMandelbrot.fx

#include "FractalBase.fxh" 

float4 FractalPixelShader(float2 texCoord : TEXCOORD0, uniform float Iterations) : COLOR0 
{ 

} 

technique Technique1 
{ 
    pass 
    { 
     VertexShader = compile vs_3_0 SpriteVertexShader(); 
     PixelShader = compile ps_3_0 FractalPixelShader(128); 
    } 
} 
+0

是一个像'C++'头文件'一样的'fxh'文件吗? –

+0

@Neil,是的,它就像一个C++头文件。 –

1

#include的工作是这样的:

预处理程序加载你的主要的.fx文件,并解析它,寻找任何启动与##include s使预处理器加载引用文件并将其内容插入到源缓冲区中。实际上,您的#include指令被包含文件的全部内容所取代。

所以,是的,您可以在您的#include中定义任何可以在常规.fx文件中定义的内容。我用它来保存几个着色器使用的公用文件中的光照函数,顶点类型声明等。