Found tool for HLSL

Joined
Oct 13, 2010
Messages
108
I found this tool called Tridipy; It allows you to code HLSL shaders and test them out on video footage played back in a internal player. I figured this could help come in handy when working on HLSL for PP.

Link
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
Thanks for the link!

Problem is, from what I can see, it only supports .fx? Which are complete shaders (psh/vsh combined). I guess you could split them, haven't done it successfully yet, I totally lack experience.

Edit: Actually, it might work, gonna check it out.
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
Thanks for the link!

Problem is, from what I can see, it only supports .fx? Which are complete shaders (psh/vsh combined). I guess you could split them, haven't done it successfully yet, I totally lack experience.

Edit: Actually, it might work, gonna check it out.
Have you tried just copy and pasting the contents of the psh/vsh programs into the edit box and modifying as needed?
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
I keep getting a "include interface required to support #include from resource or memory", I linked it right though.

Am I just stupid? Lol
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
I keep getting a "include interface required to support #include from resource or memory", I linked it right though.
Have you tried manually performing the role of a pre-processor? Ie. Copy/pasting the contents of the #include file into the file replacing the #include line?

Tonberry said:
Nice find Mech, hopefully we can make it work.
I keep getting errors about "unexpected point token" when I test out the vertex shaders and includes, and I'm not sure why.
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
I was testing out a .psh file, what you said with copy pasting the includes/functions worked, but now I'm stuck on a "ID3DXEffectCompiler: There were no techniques" error.

Ironically, I can compile the the same code (without copy pasting the includes obviously) in fxc just fine.

Must be the .fx structure that's bugging me or something, I'll play with it more tomorrow.

Did you get any to work at all, or are you still stuck on that token error?
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
I was testing out a .psh file, what you said with copy pasting the includes/functions worked, but now I'm stuck on a "ID3DXEffectCompiler: There were no techniques" error.
Speaking of that, I think I made a discovery:

For the SWG graphics pipeline, the SHT file defines the techniques, and the FORM data in the SHT defines the passes.

So a SHT+VSH/PSH = full graphics program, not just the VSH/PSH themselves; To get it working in Tridipy you have to manually define the techniques since it can't read SHT; Try adding this:

Code:
technique <Technique_Identifier>
	{
	    pass <Pass_Identifier>
	    {
	        <Shadertype>= compile <Shader Model Version> <Function Identifier>();
	    }
	}
Where <Shadertype> equals either PixelShader or VertexShader, and <Shader Model Version> equals vs/ps_1_0, _2_0, etc.
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
Thanks, that did the trick, just had to change a few things (Looked at an existing .fx as reference)

It would end up looking like:

Code:
technique Technique1
    {
        pass Pass1
        {
            PixelShader= compile ps_2_0 main();
        }
    }
Normally main is something like PixelShaderFunction, but since it's a copy paste, main works in this case, but you know that anyway.

Don't you think the EFT is the technique then? EFT handle multipass shading too, all SHT does is direct to EFT, just in some cases it acts as an EFT. Perhaps the EFT is just an extra file split from the SHT, if it acts as technique, if that makes sense.
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
Don't you think the EFT is the technique then? EFT handle multipass shading too, all SHT does is direct to EFT, just in some cases it acts as an EFT. Perhaps the EFT is just an extra file split from the SHT, if it acts as technique, if that makes sense.
Yeah sorry, meant to say EFT when I actually said SHT.

How did you get past error X3202? (location semantics cannot be specified on members)

What shader did you test? Can you post a screenshot of the effect it had on the video?
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
Never got that error, it did end up black out my screen though, but I just wanted to get it to work without crashing. Didn't have the time yesterday to fool around with it more, I'll try some other shaders later.

I used the 2d_distort.psh from the NGE:

Code:
float4    packedRegister0        : register(c0);
float4    packedRegister1        : register(c1);
float4    packedRegister2        : register(c2);
float4    packedRegister3        : register(c3);
float4    packedRegister4        : register(c4);
float4    textureFactor          : register(c5);
float4    textureFactor2         : register(c6);
float4    materialSpecularColor  : register(c7);
float4    userConstants[17]      : register(c8);

static const float bloomSpecularRgbScale = 0.5;
static const float bloomSpecularAlphaScale = 0.65;

#define dot3LightDirection      packedRegister0.xyz
#define materialSpecularPower   packedRegister0.w

#define dot3LightDiffuseColor   packedRegister1.rgb
#define alphaFadeOpacityEnabled packedRegister1.a

#define dot3LightSpecularColor  packedRegister2.rgb
#define alphaFadeOpacity        packedRegister2.a

#define dot3LightTangentMinusDiffuseColor packedRegister3.rgb
#define bloomEnabled            packedRegister3.a

#define dot3LightTangentMinusBackColor    packedRegister4.rgb
#define timeElapsed		packedRegister4.a

// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================

float lengthSquared(float3 v)
{
	return dot(v, v);
}

// ----------------------------------------------------------------------

float3 signAndBias(float3 v)
{
	return (v - 0.5) * 2.0;
}

// ----------------------------------------------------------------------

float3 reverseSignAndBias(float3 v)
{
	return (v * 0.5) + 0.5;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal(sampler map, float2 tcs)
{
	float4 pixel = tex2D(map, tcs);
	float3 normal = { pixel.a, pixel.y, 1 };
	normal = signAndBias(normal);
	normal.z = sqrt(1 - (normal.x * normal.x + normal.y * normal.y));
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	normal.z = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// no sqrt( ) available, so we must approximate it
	if (normal.z >= 0.24)
	{
		normal.z = (normal.z * 0.6667) + 0.375;
	}
	else
	{
		normal.z = (normal.z * 1.6667) + 0.15;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14_min_constants( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	float zSquared = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// slightly creative rework of above method to reduce instructions and constants
	// no sqrt( ) available, so we must approximate it
	normal.z = (zSquared * 0.6667) + 0.375;
	zSquared -= 0.225; // subtracting the 0.375 that was added to normal.z above and adding 0.15 before the comparison
	if (zSquared < 0)
	{
		normal.z += zSquared;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float intensity(float3 rgb)
{
	return dot(rgb, float3(0.3f, 0.59f, 0.11f));
}

// ======================================================================



// ======================================================================
// functions.inc
// HLSL pixel shader functions
// ======================================================================


// ======================================================================

float calculateFakeAnisotropicSpecularLighting(float dot3SpecularNoPower)
{
	float tighten = 1.25f;
	float powerScale = 0.15f;
	return max(0, pow(1 - abs(1 - (dot3SpecularNoPower * tighten)), materialSpecularPower * powerScale) - powerScale);
}

// ======================================================================

float3 calculateHemisphericLighting(float3 direction, float3 normal, float3 vertexDiffuse)
{
	float  dotProduct = dot(direction, normal);
	
	float3 light = vertexDiffuse + dot3LightTangentMinusDiffuseColor + dot3LightDiffuseColor + (-max(0.0, dotProduct) * (dot3LightTangentMinusDiffuseColor));
	
	light += (min(0.0, dotProduct) * (dot3LightTangentMinusBackColor));

	return saturate(light);
}

float3 calculateHemisphericLightingVertexColor(float3 direction, float3 normal, float3 vertexDiffuse, float3 vertexColor)
{
	float  dotProduct = dot(direction, normal);
	
	float3 light = 
		  dot3LightTangentMinusDiffuseColor 
		+ dot3LightDiffuseColor 
		+ -max(0.0, dotProduct) * (dot3LightTangentMinusDiffuseColor)
		+  min(0.0, dotProduct) * (dot3LightTangentMinusBackColor)
		;
	
	light = light*vertexColor + vertexDiffuse;

	return saturate(light);
}

float3 calculateHemisphericLightingAlpha(float3 direction, float3 normal, float3 vertexDiffuse, float alpha)
{
	float  dotProduct = dot(direction, normal);
	float3 allMainLight = saturate(lerp(dotProduct, direction.z, alpha));
	
	float3 light = vertexDiffuse + dot3LightTangentMinusDiffuseColor + dot3LightDiffuseColor + (-max(0.0, allMainLight) * (dot3LightTangentMinusDiffuseColor));
	
	light += (min(0.0, dotProduct) * (dot3LightTangentMinusBackColor));

	return saturate(light);
}




sampler diffuseMap : register(s0);
sampler noiseMap : register(s1);

static const float zeroOffset = 0.5f/255.0f;

float4 main(
        in float3  diffuse   : COLOR0,
	in float2  noiseTc   : TEXCOORD0
) : COLOR 
{
    // Copy the original UVs
    float2 alterCoords = noiseTc;
    
    // Alter the UVs by Sin/Cos
    alterCoords.x = noiseTc.y + sin(timeElapsed * 0.05f);
    alterCoords.y = noiseTc.x + cos(timeElapsed * 0.05f);

    // Sample the original texture
    float4 final = tex2D(diffuseMap, noiseTc);

    //Apply lighting
    final.rgb = final.rgb * diffuse;
    
    // Get our displacement values
    float2 displace = tex2D(noiseMap, alterCoords).rg;
    
    // Sample the texture by the displaced values.
    displace -= 0.5f + zeroOffset;
    final *= tex2D(diffuseMap, ( noiseTc.xy + (displace * 0.05f) ) );

    return final;
}

technique Technique1
    {
        pass Pass1
        {
            PixelShader= compile ps_2_0 main();
        }
    }
One thing I forgot to mention earlier, 'const' gave me error, I had to change it to 'static const' in this line:

Code:
static const float zeroOffset = 0.5f/255.0f;
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
I used the 2d_distort.psh from the NGE
Interesting, maybe the NGE shaders were built more up to spec, because I keep trying the Pre-CU shaders and I'm having no luck.
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
I just tried it with 2d_blur.psh, but had to use ps_3_0 because it gave me this error when I tried compiling it with ps_2_0:

Code:
Error X5608: Compiled shader code uses too many artithmetic instruction slots (67). Max. allowed by the target (ps_2_0) is 64.
Black screen again in the video player, but it 'runs' fine, I can hear the audio and everything.

I just copy shared_program in there first, then the include from pixel_program, remove any #include's, then add the technique.

Code:
// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================

float lengthSquared(float3 v)
{
	return dot(v, v);
}

// ----------------------------------------------------------------------

float3 signAndBias(float3 v)
{
	return (v - 0.5) * 2.0;
}

// ----------------------------------------------------------------------

float3 reverseSignAndBias(float3 v)
{
	return (v * 0.5) + 0.5;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal(sampler map, float2 tcs)
{
	float4 pixel = tex2D(map, tcs);
	float3 normal = { pixel.a, pixel.y, 1 };
	normal = signAndBias(normal);
	normal.z = sqrt(1 - (normal.x * normal.x + normal.y * normal.y));
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	normal.z = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// no sqrt( ) available, so we must approximate it
	if (normal.z >= 0.24)
	{
		normal.z = (normal.z * 0.6667) + 0.375;
	}
	else
	{
		normal.z = (normal.z * 1.6667) + 0.15;
	}
	
	return normal;
}

// ----------------------------------------------------------------------


float3 tex2DDxt5CompressedNormal_ps_14_min_constants( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	float zSquared = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// slightly creative rework of above method to reduce instructions and constants
	// no sqrt( ) available, so we must approximate it
	normal.z = (zSquared * 0.6667) + 0.375;
	zSquared -= 0.225; // subtracting the 0.375 that was added to normal.z above and adding 0.15 before the comparison
	if (zSquared < 0)
	{
		normal.z += zSquared;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float intensity(float3 rgb)
{
	return dot(rgb, float3(0.3f, 0.59f, 0.11f));
}

// ======================================================================

float3    dot3LightDirection     : register(c0);
float4    dot3LightDiffuseColor  : register(c1);
float4    dot3LightSpecularColor : register(c2);
float4    textureFactor          : register(c3);
float4    textureFactor2         : register(c4);
float4    materialSpecularColor  : register(c5);
float     materialSpecularPower  : register(c6);
float4    alphaFadeOpacityHolder : register(c7);
float4    userConstants[17]      : register(c8);

static const float bloomSpecularRgbScale = 0.5;
static const float bloomSpecularAlphaScale = 0.65;

#define alphaFadeOpacityEnabled alphaFadeOpacityHolder.r
#define bloomEnabled            alphaFadeOpacityHolder.g
#define alphaFadeOpacity        alphaFadeOpacityHolder.a
#define bloomEnabled        	alphaFadeOpacityHolder.g

// ======================================================================

// ======================================================================
// functions.inc
// HLSL pixel shader functions
// ======================================================================



// ======================================================================

float calculateFakeAnisotropicSpecularLighting(float dot3SpecularNoPower)
{
	float tighten = 1.25f;
	float powerScale = 0.15f;
	return max(0, pow(1 - abs(1 - (dot3SpecularNoPower * tighten)), materialSpecularPower * powerScale) - powerScale);
}


sampler s0 : register(s0);

float4 main
(
	in float2 textureCoordinates  : TEXCOORD0
)
: COLOR
{
	float4 result = 0.0f;
	float2 textureCoordinateOffsets = 0.0f;
	for (int i = 0; i < 16; ++i, textureCoordinateOffsets += userConstants[16].xy)
		result += tex2D(s0, textureCoordinates + textureCoordinateOffsets) * userConstants[i];

	return result;
}

technique Technique1
    {
        pass Pass1
        {
            PixelShader= compile ps_3_0 main();
        }
    }
Are you trying out shaders written in ASM or HLSL? .VSH seems to be a bit more complex, since it has more code, I'll play around with it later.



EDIT:



Here is my .VSH code, copied the bad_vertex_shader.vsh from preCU, I get the same error:

Code:
// ======================================================================
//
// inputs:
//
//   none
//
// outputs:
//
//   r7       = cell/ambient lighting
//
// ======================================================================

// ----------------------------------------------------------------------
//  calculate ambient light


#define vPosition                                     v0
#define vNormal                                       v3
#define vPointSize                                    v4
#define vColor0                                       v5
#define vColor1                                       v6
#define vTextureCoordinateSet0                        v7
#define vTextureCoordinateSet1                        v8
#define vTextureCoordinateSet2                        v9
#define vTextureCoordinateSet3                        v10
#define vTextureCoordinateSet4                        v11
#define vTextureCoordinateSet5                        v12
#define vTextureCoordinateSet6                        v13
#define vTextureCoordinateSet7                        v14

#define cObjectWorldCameraProjectionMatrix            c0
#define cObjectWorldMatrix                            c4
#define cCameraPosition                               c8
#define cViewportData                                 c9
#define cFog                                          c10
#define cMaterial_diffuseColor                        c11
#define cMaterial_ambientColor                        c12
#define cMaterial_specularColor                       c13
#define cMaterial_emissiveColor                       c14
#define cMaterial_specularPower                       c15.x
#define cLightData_ambient_ambientColor               c16
#define cLightData_parallelSpecular_0_direction       c17
#define cLightData_parallelSpecular_0_diffuseColor    c18
#define cLightData_parallelSpecular_0_specularColor   c19
#define cLightData_parallel_0_direction               c20
#define cLightData_parallel_0_diffuseColor            c21
#define cLightData_parallel_1_direction               c22
#define cLightData_parallel_1_diffuseColor            c23
#define cLightData_pointSpecular_0_position           c24
#define cLightData_pointSpecular_0_diffuseColor       c25
#define cLightData_pointSpecular_0_attenuation        c26
#define cLightData_pointSpecular_0_specularColor      c27
#define cLightData_point_0_position                   c28
#define cLightData_point_0_diffuseColor               c29
#define cLightData_point_0_attenuation                c30
#define cLightData_point_1_position                   c31
#define cLightData_point_1_diffuseColor               c32
#define cLightData_point_1_attenuation                c33
#define cLightData_point_2_position                   c34
#define cLightData_point_2_diffuseColor               c35
#define cLightData_point_2_attenuation                c36
#define cLightData_point_3_position                   c37
#define cLightData_point_3_diffuseColor               c38
#define cLightData_point_3_attenuation                c39
#define cLightData_dot3_0_cameraPosition              c40
#define cLightData_dot3_0_direction                   c41
#define cLightData_dot3_0_diffuseColor                c42
#define cLightData_dot3_0_specularColor               c43
#define cTextureFactor                                c44
#define cTextureFactor2                               c45
#define cTextureScroll                                c47
#define cCurrentTime                                  c48
#define cUnitX                                        c49
#define cUnitY                                        c50
#define cUnitZ                                        c51
#define cUserConstant0                                c52
#define cUserConstant1                                c53
#define cUserConstant2                                c54
#define cUserConstant3                                c55
#define cUserConstant4                                c56
#define cUserConstant5                                c57
#define cUserConstant6                                c58
#define cUserConstant7                                c59
#define c0_0                                          c95.x
#define c0_5                                          c95.y
#define c1_0                                          c95.z
#define cLog2e                                        c95.w

struct Input
{
	float4  position : POSITION0  : register(v0) ;
};


struct Output
{
	float4  position  : POSITION0;
	float4  diffuse   : COLOR0;
	float   fog       : FOG;
};


Output main(Input vertex)
{
	Output output;

	// transform vertex
	output.position = mul(vertex.position, objectWorldCameraProjectionMatrix);

	// calculate fog
	output.fog = calculateFog(vertex.position);

	// calculate lighting
	output.diffuse = lightData.ambient.ambientColor + calculateDiffuseLighting(false, vertex.position, normalize(vertex.position));

	return output;
}




technique Technique1
    {
        pass Pass1
        {
            VertexShader= compile vs_3_0 main();
        }
    }
From what I could see,
Code:
register(v0)
Is what causes the issue in line 91.

If you remove it (which obviously needs to be fixed, but just for the sake of it), it passes it and then gives me the error:

Code:
Line (108.41): error X3004: undeclared identifier 'objectWorldCameraProjectionMatrix'
Line (108.20): error X3013: 'mul': intrinsic function does not take 2 parameters
Line (108.20): error X3013: Possible Functions are:
Line (108.20): error X3013: mul(float, float)
Line (108.20): error X3013: mul(float, floatK)
Line (108.20): error X3013: mul(float, floatLxK)
Line (108.20): error X3013: mul(floatM, float)
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
I just tried it with 2d_blur.psh, but had to use ps_3_0 because it gave me this error when I tried compiling it with ps_2_0:

Code:
Error X5608: Compiled shader code uses too many artithmetic instruction slots (67). Max. allowed by the target (ps_2_0) is 64.
Black screen again in the video player, but it 'runs' fine, I can hear the audio and everything.

I just copy shared_program in there first, then the include from pixel_program, remove any #include's, then add the technique.

Code:
// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================

float lengthSquared(float3 v)
{
	return dot(v, v);
}

// ----------------------------------------------------------------------

float3 signAndBias(float3 v)
{
	return (v - 0.5) * 2.0;
}

// ----------------------------------------------------------------------

float3 reverseSignAndBias(float3 v)
{
	return (v * 0.5) + 0.5;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal(sampler map, float2 tcs)
{
	float4 pixel = tex2D(map, tcs);
	float3 normal = { pixel.a, pixel.y, 1 };
	normal = signAndBias(normal);
	normal.z = sqrt(1 - (normal.x * normal.x + normal.y * normal.y));
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	normal.z = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// no sqrt( ) available, so we must approximate it
	if (normal.z >= 0.24)
	{
		normal.z = (normal.z * 0.6667) + 0.375;
	}
	else
	{
		normal.z = (normal.z * 1.6667) + 0.15;
	}
	
	return normal;
}

// ----------------------------------------------------------------------


float3 tex2DDxt5CompressedNormal_ps_14_min_constants( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	float zSquared = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// slightly creative rework of above method to reduce instructions and constants
	// no sqrt( ) available, so we must approximate it
	normal.z = (zSquared * 0.6667) + 0.375;
	zSquared -= 0.225; // subtracting the 0.375 that was added to normal.z above and adding 0.15 before the comparison
	if (zSquared < 0)
	{
		normal.z += zSquared;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float intensity(float3 rgb)
{
	return dot(rgb, float3(0.3f, 0.59f, 0.11f));
}

// ======================================================================

float3    dot3LightDirection     : register(c0);
float4    dot3LightDiffuseColor  : register(c1);
float4    dot3LightSpecularColor : register(c2);
float4    textureFactor          : register(c3);
float4    textureFactor2         : register(c4);
float4    materialSpecularColor  : register(c5);
float     materialSpecularPower  : register(c6);
float4    alphaFadeOpacityHolder : register(c7);
float4    userConstants[17]      : register(c8);

static const float bloomSpecularRgbScale = 0.5;
static const float bloomSpecularAlphaScale = 0.65;

#define alphaFadeOpacityEnabled alphaFadeOpacityHolder.r
#define bloomEnabled            alphaFadeOpacityHolder.g
#define alphaFadeOpacity        alphaFadeOpacityHolder.a
#define bloomEnabled        	alphaFadeOpacityHolder.g

// ======================================================================

// ======================================================================
// functions.inc
// HLSL pixel shader functions
// ======================================================================



// ======================================================================

float calculateFakeAnisotropicSpecularLighting(float dot3SpecularNoPower)
{
	float tighten = 1.25f;
	float powerScale = 0.15f;
	return max(0, pow(1 - abs(1 - (dot3SpecularNoPower * tighten)), materialSpecularPower * powerScale) - powerScale);
}


sampler s0 : register(s0);

float4 main
(
	in float2 textureCoordinates  : TEXCOORD0
)
: COLOR
{
	float4 result = 0.0f;
	float2 textureCoordinateOffsets = 0.0f;
	for (int i = 0; i < 16; ++i, textureCoordinateOffsets += userConstants[16].xy)
		result += tex2D(s0, textureCoordinates + textureCoordinateOffsets) * userConstants[i];

	return result;
}

technique Technique1
    {
        pass Pass1
        {
            PixelShader= compile ps_3_0 main();
        }
    }
Are you trying out shaders written in ASM or HLSL? .VSH seems to be a bit more complex, since it has more code, I'll play around with it later.



EDIT:



Here is my .VSH code, copied the bad_vertex_shader.vsh from preCU, I get the same error:

Code:
// ======================================================================
//
// inputs:
//
//   none
//
// outputs:
//
//   r7       = cell/ambient lighting
//
// ======================================================================

// ----------------------------------------------------------------------
//  calculate ambient light


#define vPosition                                     v0
#define vNormal                                       v3
#define vPointSize                                    v4
#define vColor0                                       v5
#define vColor1                                       v6
#define vTextureCoordinateSet0                        v7
#define vTextureCoordinateSet1                        v8
#define vTextureCoordinateSet2                        v9
#define vTextureCoordinateSet3                        v10
#define vTextureCoordinateSet4                        v11
#define vTextureCoordinateSet5                        v12
#define vTextureCoordinateSet6                        v13
#define vTextureCoordinateSet7                        v14

#define cObjectWorldCameraProjectionMatrix            c0
#define cObjectWorldMatrix                            c4
#define cCameraPosition                               c8
#define cViewportData                                 c9
#define cFog                                          c10
#define cMaterial_diffuseColor                        c11
#define cMaterial_ambientColor                        c12
#define cMaterial_specularColor                       c13
#define cMaterial_emissiveColor                       c14
#define cMaterial_specularPower                       c15.x
#define cLightData_ambient_ambientColor               c16
#define cLightData_parallelSpecular_0_direction       c17
#define cLightData_parallelSpecular_0_diffuseColor    c18
#define cLightData_parallelSpecular_0_specularColor   c19
#define cLightData_parallel_0_direction               c20
#define cLightData_parallel_0_diffuseColor            c21
#define cLightData_parallel_1_direction               c22
#define cLightData_parallel_1_diffuseColor            c23
#define cLightData_pointSpecular_0_position           c24
#define cLightData_pointSpecular_0_diffuseColor       c25
#define cLightData_pointSpecular_0_attenuation        c26
#define cLightData_pointSpecular_0_specularColor      c27
#define cLightData_point_0_position                   c28
#define cLightData_point_0_diffuseColor               c29
#define cLightData_point_0_attenuation                c30
#define cLightData_point_1_position                   c31
#define cLightData_point_1_diffuseColor               c32
#define cLightData_point_1_attenuation                c33
#define cLightData_point_2_position                   c34
#define cLightData_point_2_diffuseColor               c35
#define cLightData_point_2_attenuation                c36
#define cLightData_point_3_position                   c37
#define cLightData_point_3_diffuseColor               c38
#define cLightData_point_3_attenuation                c39
#define cLightData_dot3_0_cameraPosition              c40
#define cLightData_dot3_0_direction                   c41
#define cLightData_dot3_0_diffuseColor                c42
#define cLightData_dot3_0_specularColor               c43
#define cTextureFactor                                c44
#define cTextureFactor2                               c45
#define cTextureScroll                                c47
#define cCurrentTime                                  c48
#define cUnitX                                        c49
#define cUnitY                                        c50
#define cUnitZ                                        c51
#define cUserConstant0                                c52
#define cUserConstant1                                c53
#define cUserConstant2                                c54
#define cUserConstant3                                c55
#define cUserConstant4                                c56
#define cUserConstant5                                c57
#define cUserConstant6                                c58
#define cUserConstant7                                c59
#define c0_0                                          c95.x
#define c0_5                                          c95.y
#define c1_0                                          c95.z
#define cLog2e                                        c95.w

struct Input
{
	float4  position : POSITION0  : register(v0) ;
};


struct Output
{
	float4  position  : POSITION0;
	float4  diffuse   : COLOR0;
	float   fog       : FOG;
};


Output main(Input vertex)
{
	Output output;

	// transform vertex
	output.position = mul(vertex.position, objectWorldCameraProjectionMatrix);

	// calculate fog
	output.fog = calculateFog(vertex.position);

	// calculate lighting
	output.diffuse = lightData.ambient.ambientColor + calculateDiffuseLighting(false, vertex.position, normalize(vertex.position));

	return output;
}




technique Technique1
    {
        pass Pass1
        {
            VertexShader= compile vs_3_0 main();
        }
    }
From what I could see,
Code:
register(v0)
Is what causes the issue in line 91.

If you remove it (which obviously needs to be fixed, but just for the sake of it), it passes it and then gives me the error:

Code:
Line (108.41): error X3004: undeclared identifier 'objectWorldCameraProjectionMatrix'
Line (108.20): error X3013: 'mul': intrinsic function does not take 2 parameters
Line (108.20): error X3013: Possible Functions are:
Line (108.20): error X3013: mul(float, float)
Line (108.20): error X3013: mul(float, floatK)
Line (108.20): error X3013: mul(float, floatLxK)
Line (108.20): error X3013: mul(floatM, float)
You forgot to copy over the definition for objectWorldCameraProjectionMatrix from the vertex constants file.
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
Oh yea, looking at what I copy pasted, tons of stuff was missing, no idea how that happened.

Anyway, same error even with the full functions and constants file. This time it appeared in line 100, from the shader functions. .

Code:
// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================

float lengthSquared(float3 v)
{
	return dot(v, v);
}

// ----------------------------------------------------------------------

float3 signAndBias(float3 v)
{
	return (v - 0.5) * 2.0;
}

// ----------------------------------------------------------------------

float3 reverseSignAndBias(float3 v)
{
	return (v * 0.5) + 0.5;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal(sampler map, float2 tcs)
{
	float4 pixel = tex2D(map, tcs);
	float3 normal = { pixel.a, pixel.y, 1 };
	normal = signAndBias(normal);
	normal.z = sqrt(1 - (normal.x * normal.x + normal.y * normal.y));
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	normal.z = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// no sqrt( ) available, so we must approximate it
	if (normal.z >= 0.24)
	{
		normal.z = (normal.z * 0.6667) + 0.375;
	}
	else
	{
		normal.z = (normal.z * 1.6667) + 0.15;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14_min_constants( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	float zSquared = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// slightly creative rework of above method to reduce instructions and constants
	// no sqrt( ) available, so we must approximate it
	normal.z = (zSquared * 0.6667) + 0.375;
	zSquared -= 0.225; // subtracting the 0.375 that was added to normal.z above and adding 0.15 before the comparison
	if (zSquared < 0)
	{
		normal.z += zSquared;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float intensity(float3 rgb)
{
	return dot(rgb, float3(0.3f, 0.59f, 0.11f));
}

// ======================================================================


// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================



// ======================================================================

float4 transform3d(float4 vertexPosition_o)
{
	return mul(vertexPosition_o, objectWorldCameraProjectionMatrix);
}

// ----------------------------------------------------------------------

float4 transform2d(float2 vertexPosition_s)
{
	float4 result;
	result.x = (vertexPosition_s.x * viewportData.x) + viewportData.z;
	result.y = (vertexPosition_s.y * viewportData.y) + viewportData.w;
	result.z = 0.5;
	result.w = 1.0;
	return result;
}

// ----------------------------------------------------------------------

float3 rotate_o2w(float3 vector_o)
{
	return mul(vector_o, (float3x3)objectWorldMatrix);
}

// ----------------------------------------------------------------------

float3 rotateNormalize_o2w(float3 vector_o)
{
	return normalize(rotate_o2w(vector_o));
}

// ----------------------------------------------------------------------

float3 rotateTranslate_o2w(float3 vector_o)
{
	return mul(vector_o, objectWorldMatrix);
}

// ----------------------------------------------------------------------

float3 calculateHalfAngle_o(float3 position_o)
{
	return normalize(lightData.dot3[0].direction_o + normalize(lightData.dot3[0].cameraPosition_o - position_o));
}

// ----------------------------------------------------------------------

//float3 calculateReflectionVector_w(float3 position_o, float3 normal_o)
//{
//	float3 fromViewer_w = normalize(rotateTranslate_o2w(position_o) - cameraPosition);
//	float3 normal_w = rotateTranslateNormalize_o2w(normal_o);
//	return reflect(fromViewer_w, normal_w);
//}

// ----------------------------------------------------------------------

float calculateFog(float4 vertexPosition_o)
{
	float4 position_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 viewer_w = cameraPosition_w - position_w;
	float  viewerDistanceSquared = lengthSquared(viewer_w);
	return 1.0 / exp(viewerDistanceSquared * fog.w);
}

// ----------------------------------------------------------------------

float3x3 calculateTextureToWorldTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	// build the transformation matrix
	float3x3 m;
	m[0] = rotate_o2w((float3)tcsDOT3);
	m[2] = normalize(rotate_o2w(vertexNormal_o));
	m[1] = cross(m[2], m[0]) * tcsDOT3.w;
	return m;
}

// ----------------------------------------------------------------------

float3x3 calculateTextureToObjectTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	// build the transformation matrix
	float3x3 m;
	m[0] = (float3)tcsDOT3;
	m[2] = vertexNormal_o;
	m[1] = cross(m[2], m[0]) * tcsDOT3.w;
	return m;
}

// ----------------------------------------------------------------------

float3x3 calculateObjectToTextureTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	return transpose(calculateTextureToObjectTransform(vertexNormal_o,tcsDOT3));
}

// ----------------------------------------------------------------------

float3 calculateDot3LightDirection_t(float3 vertexNormal_o, float4 tcsDOT3)
{
	// transform the light direction into texture space
	return mul(lightData.dot3[0].direction_o, calculateObjectToTextureTransform(vertexNormal_o, tcsDOT3));
}

// ----------------------------------------------------------------------
// deprecated 

float3 transformDot3LightDirection(float3 vertexNormal_o, float4 tcsDOT3)
{
	return calculateDot3LightDirection_t(vertexNormal_o, tcsDOT3);
}

// ----------------------------------------------------------------------

float3 computeHalfAngle(float3 vertexPosition_o)
{
	// (H = L + V / |L + V|)
	return normalize(normalize(lightData.dot3[0].cameraPosition_o - vertexPosition_o) + lightData.dot3[0].direction_o);
}

// ----------------------------------------------------------------------

float3 calculateHalfAngle_t(float3 vertexPosition_o, float3 vertexNormal_o, float4 tcsDOT3)
{
	return mul(computeHalfAngle(vertexPosition_o), calculateObjectToTextureTransform(vertexNormal_o, tcsDOT3));
}

// ----------------------------------------------------------------------
// deprecated 

float3 transformHalfAngle(float3 vertexPosition_o, float3 vertexNormal_o, float4 tcsDOT3)
{
	return calculateHalfAngle_t(vertexPosition_o, vertexNormal_o, tcsDOT3);
}

// ----------------------------------------------------------------------

float3 transformTerrainDot3LightDirection(float3 vertexNormal_o)
{
	float3 j = cross(vertexNormal_o, float3(1.0f, 0.0f, 0.0f));
	float3 i = cross(j, vertexNormal_o);

	float3 result;
	result.x = dot(i, lightData.dot3[0].direction_o);
	result.y = dot(j, lightData.dot3[0].direction_o);
	result.z = dot(vertexNormal_o, lightData.dot3[0].direction_o);

	return reverseSignAndBias(result);
}

// ----------------------------------------------------------------------

float3 calculateViewerDirection_o(float3 vertexPosition_o)
{
	return normalize(lightData.dot3[0].cameraPosition_o - vertexPosition_o);
}

// ----------------------------------------------------------------------

float3 calculateViewerDirection_w(float3 vertexPosition_o)
{
	return normalize(cameraPosition_w - rotateTranslate_o2w(vertexPosition_o));
}

// ----------------------------------------------------------------------

float4 calculateDiffuseParallelLight(ParallelLight light, float3 vertexNormal_o)
{
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));
	return max(dot(normal_w, light.direction_w), 0.0) * light.diffuseColor;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularParallelLight(ParallelSpecularLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 viewer_w = normalize(cameraPosition_w - mul(vertexPosition_o, objectWorldMatrix));
	float3 vertexNormal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));

	float3 halfAngle = normalize(light.direction_w + viewer_w);
	float  nDotL = dot(vertexNormal_w, light.direction_w);
	float  nDotH = dot(vertexNormal_w, halfAngle);
	
	float4 lighting = lit(nDotL, nDotH, material.specularPower.x);

	DiffuseSpecular diffuseSpecular;
	diffuseSpecular.diffuse  = lighting.y * light.diffuseColor;
	diffuseSpecular.specular = lighting.z * light.specularColor;

	return diffuseSpecular;
}

// ----------------------------------------------------------------------

float4 calculateDiffusePointLight(PointLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 vertexPosition_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));

	// Get light direction
	float3 lightDirection = light.position_w - vertexPosition_w;

	// Get light distance squared.
	float lightDistanceSquared = lengthSquared(lightDirection);

	// Get 1/lightDistance
	float oneOverLightDistance = rsqrt(lightDistanceSquared);

	// Normalize light direction
	lightDirection *= oneOverLightDistance;

	// compute distance attenuation
	float4 attenuationFactors;
	attenuationFactors.x = 1.0;
	attenuationFactors.y = lightDistanceSquared * oneOverLightDistance;
	attenuationFactors.z = lightDistanceSquared;
	attenuationFactors.w = oneOverLightDistance;
	float distanceAttenuation = 1.0 / dot(light.attenuation, attenuationFactors);

	return max(dot(normal_w, lightDirection), 0.0) * distanceAttenuation * light.diffuseColor;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularPointLight(PointSpecularLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 vertexPosition_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));
	float3 viewer_w = normalize(cameraPosition_w - vertexPosition_w);

	// Get light direction
	float3 lightDirection = light.position_w - vertexPosition_w;

	// Get light distance squared.
	float lightDistanceSquared = lengthSquared(lightDirection);

	// Get 1/lightDistance
	float oneOverLightDistance = rsqrt(lightDistanceSquared);

	// Normalize light direction
	lightDirection *= oneOverLightDistance;

	// compute distance attenuation
	float4 attenuationFactors;
	attenuationFactors.x = 1.0;
	attenuationFactors.y = lightDistanceSquared * oneOverLightDistance;
	attenuationFactors.z = lightDistanceSquared;
	attenuationFactors.w = 1.0; // oneOverLightDistance;
	float distanceAttenuation = 1.0 / dot(light.attenuation, attenuationFactors);

	float3 halfAngle = normalize(lightDirection + viewer_w);
	float  nDotL = dot(normal_w, lightDirection);
	float  nDotH = dot(normal_w, halfAngle);
	
	float4 lighting = lit(nDotL, nDotH, material.specularPower.x) * distanceAttenuation;

	DiffuseSpecular diffuseSpecular;
	diffuseSpecular.diffuse  = lighting.y * light.diffuseColor;
	diffuseSpecular.specular = lighting.z * light.specularColor;
	return diffuseSpecular;
}

// ----------------------------------------------------------------------

float4 calculateDiffuseLighting(bool dot3, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float4 result = material.emissiveColor;

	if (!dot3)
		result += calculateDiffuseParallelLight((ParallelLight)lightData.parallelSpecular[0], vertexNormal_o);

	result += calculateDiffuseParallelLight(lightData.parallel[0], vertexNormal_o);
	result += calculateDiffuseParallelLight(lightData.parallel[1], vertexNormal_o);

	result += calculateDiffusePointLight((PointLight)lightData.pointSpecular[0], vertexPosition_o, vertexNormal_o);

	result += calculateDiffusePointLight(lightData.point[0], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[1], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[2], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[3], vertexPosition_o, vertexNormal_o);

	return result;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularLighting(bool dot3, float4 vertexPosition_o, float3 vertexNormal_o)
{
	DiffuseSpecular output;
	output.diffuse = material.emissiveColor;
	output.specular = float4(0.0, 0.0, 0.0, 0.0);
	
	if (!dot3)
	{
		DiffuseSpecular temporary = calculateDiffuseSpecularParallelLight(lightData.parallelSpecular[0], vertexPosition_o, vertexNormal_o);
		output.diffuse += temporary.diffuse;
		output.specular += temporary.specular;
	}
	
	output.diffuse += calculateDiffuseParallelLight(lightData.parallel[0], vertexNormal_o);
	output.diffuse += calculateDiffuseParallelLight(lightData.parallel[1], vertexNormal_o);

	DiffuseSpecular temporary = calculateDiffuseSpecularPointLight(lightData.pointSpecular[0], vertexPosition_o, vertexNormal_o);
	output.diffuse += temporary.diffuse;
	output.specular += temporary.specular;

	output.diffuse += calculateDiffusePointLight(lightData.point[0], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[1], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[2], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[3], vertexPosition_o, vertexNormal_o);

	return output;
}

// ----------------------------------------------------------------------

float2 calculateDiffuseSpecularLightingLookupTextureCoordinates(float4 vertexPosition_o, float vertexNormal_o)
{
	float2 result;
	
	// Calculate L.N for light texture lookup
	result.x = max(0.0f, dot(lightData.dot3[0].direction_o, vertexNormal_o));

	//Calculate H.N for light texture lookup
	float3 halfAngle_o = calculateHalfAngle_o(vertexPosition_o);
	result.y = max(0.0f, dot(halfAngle_o, vertexNormal_o));

	return result;
}


// ======================================================================

// ======================================================================
// types
// ======================================================================

struct Material
{
	float4   diffuseColor;
	float4   ambientColor;
	float4   specularColor;
	float4   emissiveColor;
	float    specularPower;
};

struct AmbientLight
{
	float4   ambientColor;
};

struct ParallelSpecularLight
{
	float3   direction_w;
	float4   diffuseColor;
	float4   specularColor;
};

struct ParallelLight
{
	float3   direction_w;
	float4   diffuseColor;
};

struct PointSpecularLight
{
	float3   position_w;
	float4   diffuseColor;
	float4   attenuation;
	float4   specularColor;
};

struct PointLight
{
	float3   position_w;
	float4   diffuseColor;
	float4   attenuation;
};

struct Dot3Light
{
	float3   cameraPosition_o;
	float3   direction_o;
	float4   diffuseColor;
	float4   specularColor;
};

struct DiffuseSpecular
{
	float4	diffuse;
	float4	specular;
};

static const int NumberOfParallelSpecularLights = 1;
static const int NumberOfParallelLights         = 2;
static const int NumberOfPointSpecularLights    = 1;
static const int NumberOfPointLights            = 4;
static const int NumberOfDot3Lights             = 1;

struct LightData
{
	AmbientLight           ambient;
	ParallelSpecularLight  parallelSpecular[NumberOfParallelSpecularLights];
	ParallelLight          parallel[NumberOfParallelLights];
	PointSpecularLight     pointSpecular[NumberOfPointSpecularLights];
	PointLight             point[NumberOfPointLights];
	Dot3Light              dot3[NumberOfDot3Lights];
};

// ======================================================================
// constants
// ======================================================================

float4x4  objectWorldCameraProjectionMatrix : register(c0);
float4x4  objectWorldMatrix : register(c4);
float3    cameraPosition_w : register(c8);

float4    viewportData : register(c9);

float4    fog : register(c10);

Material  material : register(c11);
LightData lightData : register(c16);

float4    textureFactor : register(c44);
float4    textureFactor2 : register(c45);
float4    textureScroll : register(c47);

float     currentTime : register(c48);

float3    unitX : register(c49);
float3    unitY : register(c50);
float3    unitZ : register(c51);

float4    userConstant0 : register(c52);
float4    userConstant1 : register(c53);
float4    userConstant2 : register(c54);
float4    userConstant3 : register(c55);
float4    userConstant4 : register(c56);
float4    userConstant5 : register(c57);
float4    userConstant6 : register(c58);
float4    userConstant7 : register(c59);

#if VERTEX_SHADER_VERSION >= 20
const bool light_parallelSpecular_0_enabled    : register(b0);
const bool light_parallel_0_enabled            : register(b1);
const bool light_parallel_1_enabled            : register(b2);
const bool light_pointSpecular_0_enabled       : register(b3);
const bool light_point_0_enabled               : register(b4);
const bool light_point_1_enabled               : register(b5);
const bool light_point_2_enabled               : register(b6);
const bool light_point_3_enabled               : register(b7);
#endif

#pragma def(vs, c95, 0.0, 0.5f, 1.0f, 1.4426950408889634f)

struct Input
{
    float4  position : POSITION0  : register(v0) ;
};


struct Output
{
    float4  position  : POSITION0;
    float4  diffuse   : COLOR0;
    float   fog       : FOG;
};


Output main(Input vertex)
{
    Output output;

    // transform vertex
    output.position = mul(vertex.position, objectWorldCameraProjectionMatrix);

    // calculate fog
    output.fog = calculateFog(vertex.position);

    // calculate lighting
    output.diffuse = lightData.ambient.ambientColor + calculateDiffuseLighting(false, vertex.position, normalize(vertex.position));

    return output;
}




technique Technique1
    {
        pass Pass1
        {
            VertexShader= compile vs_3_0 main();
        }
    }
This time I didn't get a X3202, did you fix yours yet?
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
Oh yea, looking at what I copy pasted, tons of stuff was missing, no idea how that happened.

Anyway, same error even with the full functions and constants file. This time it appeared in line 100, from the shader functions. .

Code:
// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================

float lengthSquared(float3 v)
{
	return dot(v, v);
}

// ----------------------------------------------------------------------

float3 signAndBias(float3 v)
{
	return (v - 0.5) * 2.0;
}

// ----------------------------------------------------------------------

float3 reverseSignAndBias(float3 v)
{
	return (v * 0.5) + 0.5;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal(sampler map, float2 tcs)
{
	float4 pixel = tex2D(map, tcs);
	float3 normal = { pixel.a, pixel.y, 1 };
	normal = signAndBias(normal);
	normal.z = sqrt(1 - (normal.x * normal.x + normal.y * normal.y));
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	normal.z = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// no sqrt( ) available, so we must approximate it
	if (normal.z >= 0.24)
	{
		normal.z = (normal.z * 0.6667) + 0.375;
	}
	else
	{
		normal.z = (normal.z * 1.6667) + 0.15;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float3 tex2DDxt5CompressedNormal_ps_14_min_constants( sampler map, float2 tcs )
{
	float4 pixel = tex2D( map, tcs );
	float3 normal = { pixel.a, pixel.y, pixel.z };
	normal = signAndBias( normal );
	float zSquared = 1.0f - (normal.x * normal.x + normal.y * normal.y);
	
	// slightly creative rework of above method to reduce instructions and constants
	// no sqrt( ) available, so we must approximate it
	normal.z = (zSquared * 0.6667) + 0.375;
	zSquared -= 0.225; // subtracting the 0.375 that was added to normal.z above and adding 0.15 before the comparison
	if (zSquared < 0)
	{
		normal.z += zSquared;
	}
	
	return normal;
}

// ----------------------------------------------------------------------

float intensity(float3 rgb)
{
	return dot(rgb, float3(0.3f, 0.59f, 0.11f));
}

// ======================================================================


// ======================================================================
// functions.inc
// HLSL vertex shader functions
// ======================================================================



// ======================================================================

float4 transform3d(float4 vertexPosition_o)
{
	return mul(vertexPosition_o, objectWorldCameraProjectionMatrix);
}

// ----------------------------------------------------------------------

float4 transform2d(float2 vertexPosition_s)
{
	float4 result;
	result.x = (vertexPosition_s.x * viewportData.x) + viewportData.z;
	result.y = (vertexPosition_s.y * viewportData.y) + viewportData.w;
	result.z = 0.5;
	result.w = 1.0;
	return result;
}

// ----------------------------------------------------------------------

float3 rotate_o2w(float3 vector_o)
{
	return mul(vector_o, (float3x3)objectWorldMatrix);
}

// ----------------------------------------------------------------------

float3 rotateNormalize_o2w(float3 vector_o)
{
	return normalize(rotate_o2w(vector_o));
}

// ----------------------------------------------------------------------

float3 rotateTranslate_o2w(float3 vector_o)
{
	return mul(vector_o, objectWorldMatrix);
}

// ----------------------------------------------------------------------

float3 calculateHalfAngle_o(float3 position_o)
{
	return normalize(lightData.dot3[0].direction_o + normalize(lightData.dot3[0].cameraPosition_o - position_o));
}

// ----------------------------------------------------------------------

//float3 calculateReflectionVector_w(float3 position_o, float3 normal_o)
//{
//	float3 fromViewer_w = normalize(rotateTranslate_o2w(position_o) - cameraPosition);
//	float3 normal_w = rotateTranslateNormalize_o2w(normal_o);
//	return reflect(fromViewer_w, normal_w);
//}

// ----------------------------------------------------------------------

float calculateFog(float4 vertexPosition_o)
{
	float4 position_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 viewer_w = cameraPosition_w - position_w;
	float  viewerDistanceSquared = lengthSquared(viewer_w);
	return 1.0 / exp(viewerDistanceSquared * fog.w);
}

// ----------------------------------------------------------------------

float3x3 calculateTextureToWorldTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	// build the transformation matrix
	float3x3 m;
	m[0] = rotate_o2w((float3)tcsDOT3);
	m[2] = normalize(rotate_o2w(vertexNormal_o));
	m[1] = cross(m[2], m[0]) * tcsDOT3.w;
	return m;
}

// ----------------------------------------------------------------------

float3x3 calculateTextureToObjectTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	// build the transformation matrix
	float3x3 m;
	m[0] = (float3)tcsDOT3;
	m[2] = vertexNormal_o;
	m[1] = cross(m[2], m[0]) * tcsDOT3.w;
	return m;
}

// ----------------------------------------------------------------------

float3x3 calculateObjectToTextureTransform(float3 vertexNormal_o, float4 tcsDOT3)
{
	return transpose(calculateTextureToObjectTransform(vertexNormal_o,tcsDOT3));
}

// ----------------------------------------------------------------------

float3 calculateDot3LightDirection_t(float3 vertexNormal_o, float4 tcsDOT3)
{
	// transform the light direction into texture space
	return mul(lightData.dot3[0].direction_o, calculateObjectToTextureTransform(vertexNormal_o, tcsDOT3));
}

// ----------------------------------------------------------------------
// deprecated 

float3 transformDot3LightDirection(float3 vertexNormal_o, float4 tcsDOT3)
{
	return calculateDot3LightDirection_t(vertexNormal_o, tcsDOT3);
}

// ----------------------------------------------------------------------

float3 computeHalfAngle(float3 vertexPosition_o)
{
	// (H = L + V / |L + V|)
	return normalize(normalize(lightData.dot3[0].cameraPosition_o - vertexPosition_o) + lightData.dot3[0].direction_o);
}

// ----------------------------------------------------------------------

float3 calculateHalfAngle_t(float3 vertexPosition_o, float3 vertexNormal_o, float4 tcsDOT3)
{
	return mul(computeHalfAngle(vertexPosition_o), calculateObjectToTextureTransform(vertexNormal_o, tcsDOT3));
}

// ----------------------------------------------------------------------
// deprecated 

float3 transformHalfAngle(float3 vertexPosition_o, float3 vertexNormal_o, float4 tcsDOT3)
{
	return calculateHalfAngle_t(vertexPosition_o, vertexNormal_o, tcsDOT3);
}

// ----------------------------------------------------------------------

float3 transformTerrainDot3LightDirection(float3 vertexNormal_o)
{
	float3 j = cross(vertexNormal_o, float3(1.0f, 0.0f, 0.0f));
	float3 i = cross(j, vertexNormal_o);

	float3 result;
	result.x = dot(i, lightData.dot3[0].direction_o);
	result.y = dot(j, lightData.dot3[0].direction_o);
	result.z = dot(vertexNormal_o, lightData.dot3[0].direction_o);

	return reverseSignAndBias(result);
}

// ----------------------------------------------------------------------

float3 calculateViewerDirection_o(float3 vertexPosition_o)
{
	return normalize(lightData.dot3[0].cameraPosition_o - vertexPosition_o);
}

// ----------------------------------------------------------------------

float3 calculateViewerDirection_w(float3 vertexPosition_o)
{
	return normalize(cameraPosition_w - rotateTranslate_o2w(vertexPosition_o));
}

// ----------------------------------------------------------------------

float4 calculateDiffuseParallelLight(ParallelLight light, float3 vertexNormal_o)
{
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));
	return max(dot(normal_w, light.direction_w), 0.0) * light.diffuseColor;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularParallelLight(ParallelSpecularLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 viewer_w = normalize(cameraPosition_w - mul(vertexPosition_o, objectWorldMatrix));
	float3 vertexNormal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));

	float3 halfAngle = normalize(light.direction_w + viewer_w);
	float  nDotL = dot(vertexNormal_w, light.direction_w);
	float  nDotH = dot(vertexNormal_w, halfAngle);
	
	float4 lighting = lit(nDotL, nDotH, material.specularPower.x);

	DiffuseSpecular diffuseSpecular;
	diffuseSpecular.diffuse  = lighting.y * light.diffuseColor;
	diffuseSpecular.specular = lighting.z * light.specularColor;

	return diffuseSpecular;
}

// ----------------------------------------------------------------------

float4 calculateDiffusePointLight(PointLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 vertexPosition_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));

	// Get light direction
	float3 lightDirection = light.position_w - vertexPosition_w;

	// Get light distance squared.
	float lightDistanceSquared = lengthSquared(lightDirection);

	// Get 1/lightDistance
	float oneOverLightDistance = rsqrt(lightDistanceSquared);

	// Normalize light direction
	lightDirection *= oneOverLightDistance;

	// compute distance attenuation
	float4 attenuationFactors;
	attenuationFactors.x = 1.0;
	attenuationFactors.y = lightDistanceSquared * oneOverLightDistance;
	attenuationFactors.z = lightDistanceSquared;
	attenuationFactors.w = oneOverLightDistance;
	float distanceAttenuation = 1.0 / dot(light.attenuation, attenuationFactors);

	return max(dot(normal_w, lightDirection), 0.0) * distanceAttenuation * light.diffuseColor;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularPointLight(PointSpecularLight light, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float3 vertexPosition_w = mul(vertexPosition_o, objectWorldMatrix);
	float3 normal_w = normalize(mul(vertexNormal_o, (float3x3)objectWorldMatrix));
	float3 viewer_w = normalize(cameraPosition_w - vertexPosition_w);

	// Get light direction
	float3 lightDirection = light.position_w - vertexPosition_w;

	// Get light distance squared.
	float lightDistanceSquared = lengthSquared(lightDirection);

	// Get 1/lightDistance
	float oneOverLightDistance = rsqrt(lightDistanceSquared);

	// Normalize light direction
	lightDirection *= oneOverLightDistance;

	// compute distance attenuation
	float4 attenuationFactors;
	attenuationFactors.x = 1.0;
	attenuationFactors.y = lightDistanceSquared * oneOverLightDistance;
	attenuationFactors.z = lightDistanceSquared;
	attenuationFactors.w = 1.0; // oneOverLightDistance;
	float distanceAttenuation = 1.0 / dot(light.attenuation, attenuationFactors);

	float3 halfAngle = normalize(lightDirection + viewer_w);
	float  nDotL = dot(normal_w, lightDirection);
	float  nDotH = dot(normal_w, halfAngle);
	
	float4 lighting = lit(nDotL, nDotH, material.specularPower.x) * distanceAttenuation;

	DiffuseSpecular diffuseSpecular;
	diffuseSpecular.diffuse  = lighting.y * light.diffuseColor;
	diffuseSpecular.specular = lighting.z * light.specularColor;
	return diffuseSpecular;
}

// ----------------------------------------------------------------------

float4 calculateDiffuseLighting(bool dot3, float4 vertexPosition_o, float3 vertexNormal_o)
{
	float4 result = material.emissiveColor;

	if (!dot3)
		result += calculateDiffuseParallelLight((ParallelLight)lightData.parallelSpecular[0], vertexNormal_o);

	result += calculateDiffuseParallelLight(lightData.parallel[0], vertexNormal_o);
	result += calculateDiffuseParallelLight(lightData.parallel[1], vertexNormal_o);

	result += calculateDiffusePointLight((PointLight)lightData.pointSpecular[0], vertexPosition_o, vertexNormal_o);

	result += calculateDiffusePointLight(lightData.point[0], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[1], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[2], vertexPosition_o, vertexNormal_o);
	result += calculateDiffusePointLight(lightData.point[3], vertexPosition_o, vertexNormal_o);

	return result;
}

// ----------------------------------------------------------------------

DiffuseSpecular calculateDiffuseSpecularLighting(bool dot3, float4 vertexPosition_o, float3 vertexNormal_o)
{
	DiffuseSpecular output;
	output.diffuse = material.emissiveColor;
	output.specular = float4(0.0, 0.0, 0.0, 0.0);
	
	if (!dot3)
	{
		DiffuseSpecular temporary = calculateDiffuseSpecularParallelLight(lightData.parallelSpecular[0], vertexPosition_o, vertexNormal_o);
		output.diffuse += temporary.diffuse;
		output.specular += temporary.specular;
	}
	
	output.diffuse += calculateDiffuseParallelLight(lightData.parallel[0], vertexNormal_o);
	output.diffuse += calculateDiffuseParallelLight(lightData.parallel[1], vertexNormal_o);

	DiffuseSpecular temporary = calculateDiffuseSpecularPointLight(lightData.pointSpecular[0], vertexPosition_o, vertexNormal_o);
	output.diffuse += temporary.diffuse;
	output.specular += temporary.specular;

	output.diffuse += calculateDiffusePointLight(lightData.point[0], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[1], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[2], vertexPosition_o, vertexNormal_o);
	output.diffuse += calculateDiffusePointLight(lightData.point[3], vertexPosition_o, vertexNormal_o);

	return output;
}

// ----------------------------------------------------------------------

float2 calculateDiffuseSpecularLightingLookupTextureCoordinates(float4 vertexPosition_o, float vertexNormal_o)
{
	float2 result;
	
	// Calculate L.N for light texture lookup
	result.x = max(0.0f, dot(lightData.dot3[0].direction_o, vertexNormal_o));

	//Calculate H.N for light texture lookup
	float3 halfAngle_o = calculateHalfAngle_o(vertexPosition_o);
	result.y = max(0.0f, dot(halfAngle_o, vertexNormal_o));

	return result;
}


// ======================================================================

// ======================================================================
// types
// ======================================================================

struct Material
{
	float4   diffuseColor;
	float4   ambientColor;
	float4   specularColor;
	float4   emissiveColor;
	float    specularPower;
};

struct AmbientLight
{
	float4   ambientColor;
};

struct ParallelSpecularLight
{
	float3   direction_w;
	float4   diffuseColor;
	float4   specularColor;
};

struct ParallelLight
{
	float3   direction_w;
	float4   diffuseColor;
};

struct PointSpecularLight
{
	float3   position_w;
	float4   diffuseColor;
	float4   attenuation;
	float4   specularColor;
};

struct PointLight
{
	float3   position_w;
	float4   diffuseColor;
	float4   attenuation;
};

struct Dot3Light
{
	float3   cameraPosition_o;
	float3   direction_o;
	float4   diffuseColor;
	float4   specularColor;
};

struct DiffuseSpecular
{
	float4	diffuse;
	float4	specular;
};

static const int NumberOfParallelSpecularLights = 1;
static const int NumberOfParallelLights         = 2;
static const int NumberOfPointSpecularLights    = 1;
static const int NumberOfPointLights            = 4;
static const int NumberOfDot3Lights             = 1;

struct LightData
{
	AmbientLight           ambient;
	ParallelSpecularLight  parallelSpecular[NumberOfParallelSpecularLights];
	ParallelLight          parallel[NumberOfParallelLights];
	PointSpecularLight     pointSpecular[NumberOfPointSpecularLights];
	PointLight             point[NumberOfPointLights];
	Dot3Light              dot3[NumberOfDot3Lights];
};

// ======================================================================
// constants
// ======================================================================

float4x4  objectWorldCameraProjectionMatrix : register(c0);
float4x4  objectWorldMatrix : register(c4);
float3    cameraPosition_w : register(c8);

float4    viewportData : register(c9);

float4    fog : register(c10);

Material  material : register(c11);
LightData lightData : register(c16);

float4    textureFactor : register(c44);
float4    textureFactor2 : register(c45);
float4    textureScroll : register(c47);

float     currentTime : register(c48);

float3    unitX : register(c49);
float3    unitY : register(c50);
float3    unitZ : register(c51);

float4    userConstant0 : register(c52);
float4    userConstant1 : register(c53);
float4    userConstant2 : register(c54);
float4    userConstant3 : register(c55);
float4    userConstant4 : register(c56);
float4    userConstant5 : register(c57);
float4    userConstant6 : register(c58);
float4    userConstant7 : register(c59);

#if VERTEX_SHADER_VERSION >= 20
const bool light_parallelSpecular_0_enabled    : register(b0);
const bool light_parallel_0_enabled            : register(b1);
const bool light_parallel_1_enabled            : register(b2);
const bool light_pointSpecular_0_enabled       : register(b3);
const bool light_point_0_enabled               : register(b4);
const bool light_point_1_enabled               : register(b5);
const bool light_point_2_enabled               : register(b6);
const bool light_point_3_enabled               : register(b7);
#endif

#pragma def(vs, c95, 0.0, 0.5f, 1.0f, 1.4426950408889634f)

struct Input
{
    float4  position : POSITION0  : register(v0) ;
};


struct Output
{
    float4  position  : POSITION0;
    float4  diffuse   : COLOR0;
    float   fog       : FOG;
};


Output main(Input vertex)
{
    Output output;

    // transform vertex
    output.position = mul(vertex.position, objectWorldCameraProjectionMatrix);

    // calculate fog
    output.fog = calculateFog(vertex.position);

    // calculate lighting
    output.diffuse = lightData.ambient.ambientColor + calculateDiffuseLighting(false, vertex.position, normalize(vertex.position));

    return output;
}




technique Technique1
    {
        pass Pass1
        {
            VertexShader= compile vs_3_0 main();
        }
    }
This time I didn't get a X3202, did you fix yours yet?
I found your problem: You pasted in the constants after code that was trying to use objectWorldCameraProjectionMatrix; Make sure you paste the contents of all include files at the top before you paste in anything else. I recommend pasting in vertex_shader_constants.inc before functions.inc.
 
Top Bottom