I've been working my way through a coding book, and I've been taking their shaders and messing with them to create different ones. At this point however I'm wholly stuck on a pair of errors. Further, I can't find any documentation on the errors to help me out!
At any rate, the code below has been simplified to only output one color because even that's failing. While it gets past the Vertex Shader, it pretty much has to be a VS to PS issue. As you can see, I've commented out everything in the pixel shader at this point aside from the one 1,1,1,1 color that it outputs. This should work under the original, but in this one it's upset. Is this being caused by a hangover of some piece of data from outVS?
Code:
//=============================================================================
// ProcTexSheer.fx by Erich Ulmer, based on Frank Luna's Terrain.fx
//
// Blends three textures together using a blending function to imitate
// procedural texturing
//=============================================================================
uniform extern float4x4 gWorldInverseTranspose;
uniform extern float4x4 gViewProj;
uniform extern float3 gDirToSunW;
uniform extern texture gTex0;
uniform extern texture gTex1;
uniform extern texture gTex2;
uniform extern texture gBlendMap;
static float gTexScale = 16.0f;
sampler Tex0S = sampler_state
{
Texture = <gTex0>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
sampler Tex1S = sampler_state
{
Texture = <gTex1>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
sampler Tex2S = sampler_state
{
Texture = <gTex2>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
sampler BlendMapS = sampler_state
{
Texture = <gBlendMap>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
struct OutputVS
{
float4 posH : POSITION0;
float2 tiledTexC : TEXCOORD0;
float shade : TEXCOORD1;
float3 B : COLOR0;
};
OutputVS TerrainVS(float3 posW : POSITION0, // We assume terrain geometry is
specified
float3 normalW : NORMAL0, // directly in world space.
float2 tex0: TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform normal to world space.
float3 normalS = mul(float4(normalW, 0.0f), gWorldInverseTranspose).xyz;
normalS = normalize(normalS);
// Compute the texture (based on angle from XZ plane)
float theta = abs(atan(normalW.y / sqrt(normalW.x * normalW.x +
normalW.z * normalW.z))); //compute the angle
// Just compute a grayscale diffuse and ambient lighting
// term--terrain has no specular reflectance.
outVS.shade = saturate(max(0.0f, dot(normalW, gDirToSunW)) + 0.3f);
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posW, 1.0f), gViewProj);
// Pass on texture coordinates to be interpolated in rasterization.
outVS.tiledTexC = tex0 * gTexScale; // Scale tex-coord to tile.
//Compute a blend pattern based on the normal
theta = 2*theta/3.142;
outVS.B.r = 1.0f;
outVS.B.g = 1.0f;
outVS.B.b = 1.0f;
// Done--return the output.
return outVS;
}
float4 TerrainPS(float2 tiledTexC : TEXCOORD0,
float shade : TEXCOORD1,
float3 B : COLOR0) : COLOR1
{
/*
// Layer maps are tiled
float3 c0 = tex2D(Tex0S, tiledTexC).rgb;
float3 c1 = tex2D(Tex1S, tiledTexC).rgb;
float3 c2 = tex2D(Tex2S, tiledTexC).rgb;
// Find the inverse of all the blend weights so that we can
// scale the total color to the range [0, 1].
float totalInverse = 1.0f / (B.r + B.g + B.b);
// Scale the colors by each layer by its corresponding weight
// stored in the blendmap.
c0 *= B.r * totalInverse;
c1 *= B.g * totalInverse;
c2 *= B.b * totalInverse;
// Sum the colors and modulate with the shade to brighten/darken.
float3 final = (c0 + c1 + c2) * shade;
*/
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}
technique TerrainTech
{
pass P0
{
vertexShader = compile vs_2_0 TerrainVS();
pixelShader = compile ps_2_0 TerrainPS(); //error occurs after equal sign. I.E. The output is bad
}
}
Again, notice that I've attempted to fix everything by setting everything to 1, just to make a usable color, and it's still not allowing it.
The error box I'm getting is:
error x4530: pixel shader must minimally write all four components of COLOR0
error x4538: COLOR outputs must be contiguous from COLOR0 to COLORn
ProcTexSheer.fx (132,24): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation Failed
I've tried making B a float4, normalizing all of B to '1.0f's and giving it "real" information. I'm at the end of my rope as to why it won't even do the most simple of requests at this point (setting all colors to 1,1,1,1)