Xna 着色器是否包含另一个着色器?
是否可以使用XNA 4在另一个着色器中包含着色器?我知道你可以在3.1之内完成,但我似乎很难让它正常工作?如果可以,任何指针都会很好 编辑Xna 着色器是否包含另一个着色器?,xna,shader,Xna,Shader,是否可以使用XNA 4在另一个着色器中包含着色器?我知道你可以在3.1之内完成,但我似乎很难让它正常工作?如果可以,任何指针都会很好 编辑 //---------------------------------------------------------------------------// // Name : Rain.fx // Desc : Rain particle effect using cylindrical billboards // Author : Justin S
//---------------------------------------------------------------------------//
// 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”文件中有变量,但我想知道您是否可以将方法也放在其中?是的,这是可能的,从内存中我认为MS App Hub的基本效果示例着色器示例可以做到这一点 在任何情况下,请参见下面的代码 在
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);
}
}
#包括
s这样的工作:
预处理器加载主.fx文件,并对其进行解析,查找任何以#
开头的文件#include
s使预处理器加载引用的文件并将其内容插入源缓冲区。实际上,您的#include
指令将被包含文件的全部内容替换
因此,是的,您可以在#include
中定义任何可以在常规.fx文件中定义的内容。我用它来保存几个着色器使用的公共文件中的照明功能、顶点类型声明等。你能给出一个XNA 3.1的例子吗?@Andrew Russell:更新的问题你说这会给你带来一个“问题”-你能更具体一点吗?错误消息?另外,值得指出的是:内容管道已更新为使用XNA 4.0中较新版本的着色器编译器。我现在不在计算机旁,但会收到错误消息。同时,是否可以在着色中使用包含方法的代码?是<代码> fxh < /Case>文件,像C++ >代码>页眉< /Cord>文件?@尼尔,是的,它就像一个C++头文件。