Jump to content

  • Log In with Google      Sign In   
  • Create Account

HLSL shader refuses to compile


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 30 August 2012 - 07:00 AM

I don't see anything wrong with the syntax of this shader (found in Assimp).
It fails on line 29 with "error X3000: syntax error: unexpected token '{'":

[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;float4x4 World : WORLD;float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;#ifndef AV_DISABLESSSfloat4x3 ViewProj;float4x3 InvViewProj;#endiffloat4 DIFFUSE_COLOR;float4 SPECULAR_COLOR;float4 AMBIENT_COLOR;float4 EMISSIVE_COLOR;#ifdef AV_SPECULAR_COMPONENTfloat SPECULARITY;float SPECULAR_STRENGTH;#endif#ifdef AV_OPACITYfloat TRANSPARENCY;#endiffloat4 afLightColor[5];float4 afLightColorAmbient[5];float3 afLightDir[5];float3 vCameraPos : CAMERAPOSITION;#ifdef AV_SKINNINGfloat4x3 gBoneMatrix[60];#endif // AV_SKINNING#ifdef AV_DIFFUSE_TEXTUREtexture DIFFUSE_TEXTURE;sampler DIFFUSE_SAMPLER{Texture = <DIFFUSE_TEXTURE>;#ifdef AV_WRAPUAddressU = WRAP;#endif#ifdef AV_MIRRORUAddressU = MIRROR;#endif#ifdef AV_CLAMPUAddressU = CLAMP;#endif#ifdef AV_WRAPVAddressV = WRAP;#endif#ifdef AV_MIRRORVAddressV = MIRROR;#endif#ifdef AV_CLAMPVAddressV = CLAMP;#endif};#endif // AV_DIFFUSE_TEXTUR#ifdef AV_DIFFUSE_TEXTURE2texture DIFFUSE_TEXTURE2;sampler DIFFUSE_SAMPLER2{Texture = <DIFFUSE_TEXTURE2>;};#endif // AV_DIFFUSE_TEXTUR2#ifdef AV_SPECULAR_TEXTUREtexture SPECULAR_TEXTURE;sampler SPECULAR_SAMPLER{Texture = <SPECULAR_TEXTURE>;};#endif // AV_SPECULAR_TEXTUR#ifdef AV_AMBIENT_TEXTUREtexture AMBIENT_TEXTURE;sampler AMBIENT_SAMPLER{Texture = <AMBIENT_TEXTURE>;};#endif // AV_AMBIENT_TEXTUR#ifdef AV_LIGHTMAP_TEXTUREtexture LIGHTMAP_TEXTURE;sampler LIGHTMAP_SAMPLER{Texture = <LIGHTMAP_TEXTURE>;};#endif // AV_LIGHTMAP_TEXTURE#ifdef AV_OPACITY_TEXTUREtexture OPACITY_TEXTURE;sampler OPACITY_SAMPLER{Texture = <OPACITY_TEXTURE>;};#endif // AV_OPACITY_TEXTURE#ifdef AV_EMISSIVE_TEXTUREtexture EMISSIVE_TEXTURE;sampler EMISSIVE_SAMPLER{Texture = <EMISSIVE_TEXTURE>;};#endif // AV_EMISSIVE_TEXTUR#ifdef AV_NORMAL_TEXTUREtexture NORMAL_TEXTURE;sampler NORMAL_SAMPLER{Texture = <NORMAL_TEXTURE>;};#endif // AV_NORMAL_TEXTURE#ifdef AV_SKYBOX_LOOKUPtextureCUBE lw_tex_envmap;samplerCUBE EnvironmentMapSampler = sampler_state{Texture = (lw_tex_envmap);AddressU = CLAMP;AddressV = CLAMP;AddressW = CLAMP;MAGFILTER = linear;MINFILTER = linear;};#endif // AV_SKYBOX_LOOKUPstruct VS_INPUT{float3 Position : POSITION;float3 Normal : NORMAL;float4 Color : COLOR0;float3 Tangent : TANGENT;float3 Bitangent : BINORMAL;float2 TexCoord0 : TEXCOORD0;#ifdef AV_TWO_UVfloat2 TexCoord1 : TEXCOORD1;#endif#ifdef AV_SKINNINGfloat4 BlendIndices : BLENDINDICES;float4 BlendWeights : BLENDWEIGHT;#endif // AV_SKINNING};struct VS_OUTPUT{float4 Position : POSITION;float3 ViewDir : TEXCOORD0;float4 Color : COLOR0;#ifndef AV_NORMAL_TEXTUREfloat3 Normal : TEXCOORD1;#endiffloat2 TexCoord0 : TEXCOORD2;#ifdef AV_TWO_UVfloat2 TexCoord1 : TEXCOORD3;#endif#ifdef AV_NORMAL_TEXTUREfloat3 Light0 : TEXCOORD3;float3 Light1 : TEXCOORD4;#endif};struct VS_OUTPUT_FF{float4 Position : POSITION;float4 DiffuseColor : COLOR0;float4 SpecularColor : COLOR1;float2 TexCoord0 : TEXCOORD0;};#define GetSSSCubeMap(_refl) (texCUBElod(EnvironmentMapSampler,float4(_refl,0.0f)).rgb)VS_OUTPUT MaterialVShader_D1(VS_INPUT IN){VS_OUTPUT Out = (VS_OUTPUT)0;#ifdef AV_SKINNINGfloat4 weights = IN.BlendWeights;weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1));float4 localPos = float4( IN.Position, 1.0f);float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w;#elsefloat3 objPos = IN.Position;#endif // AV_SKINNINGOut.Position = mul( float4( objPos, 1.0f), WorldViewProjection);float3 WorldPos = mul( float4( objPos, 1.0f), World);Out.TexCoord0 = IN.TexCoord0;#ifdef AV_TWO_UVOut.TexCoord1 = IN.TexCoord1;#endifOut.Color = IN.Color;#ifndef AV_NORMAL_TEXTUREOut.ViewDir = vCameraPos - WorldPos;Out.Normal = mul(IN.Normal,WorldInverseTranspose);#endif#ifdef AV_NORMAL_TEXTUREfloat3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));#endifreturn Out;}VS_OUTPUT MaterialVShader_D2(VS_INPUT IN){VS_OUTPUT Out = (VS_OUTPUT)0;#ifdef AV_SKINNINGfloat4 weights = IN.BlendWeights;weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1));float4 localPos = float4( IN.Position, 1.0f);float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w;#elsefloat3 objPos = IN.Position;#endif // AV_SKINNINGOut.Position = mul( float4( objPos, 1.0f), WorldViewProjection);float3 WorldPos = mul( float4( objPos, 1.0f), World);Out.TexCoord0 = IN.TexCoord0;#ifdef AV_TWO_UVOut.TexCoord1 = IN.TexCoord1;#endifOut.Color = IN.Color;#ifndef AV_NORMAL_TEXTUREOut.ViewDir = vCameraPos - WorldPos;Out.Normal = mul(IN.Normal,WorldInverseTranspose);#endif#ifdef AV_NORMAL_TEXTUREfloat3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));Out.Light1 = normalize(mul(WTTS, afLightDir[1] ));Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));#endifreturn Out;}VS_OUTPUT_FF MaterialVShader_FF(VS_INPUT IN){VS_OUTPUT_FF Out = (VS_OUTPUT_FF)0;#ifdef AV_SKINNINGfloat4 weights = IN.BlendWeights;weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1));float4 localPos = float4( IN.Position, 1.0f);float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z;objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w;#elsefloat3 objPos = IN.Position;#endif // AV_SKINNINGOut.Position = mul( float4( objPos, 1.0f), WorldViewProjection);float3 worldPos = mul( float4( objPos, 1.0f), World);float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose));Out.TexCoord0 = IN.TexCoord0;float4 diffuseColor = float4( 0.0f, 0.0f, 0.0f, 1.0f);for( int a = 0; a < 2; a++) diffuseColor.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb;Out.DiffuseColor = diffuseColor * DIFFUSE_COLOR + float4( 0.2f, 0.2f, 0.2f, 1.0f) * AMBIENT_COLOR; ;float4 specularColor = float4( 0.0f, 0.0f, 0.0f, 1.0f);#ifdef AV_SPECULAR_COMPONENTfloat3 viewDir = normalize( worldPos - vCameraPos);for( int a = 0; a < 2; a++){ float3 reflDir = reflect( afLightDir[a], worldNormal); float specIntensity = pow( saturate( dot( reflDir, viewDir)), SPECULARITY) * SPECULAR_STRENGTH; specularColor.rgb += afLightColor[a] * specIntensity;}#endif // AV_SPECULAR_COMPONENTOut.SpecularColor = specularColor * SPECULAR_COLOR + EMISSIVE_COLOR;return Out;}float4 MaterialPShaderSpecular_D1(VS_OUTPUT IN) : COLOR{float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);#ifdef AV_NORMAL_TEXTUREfloat3 IN_Light0 = normalize(IN.Light0);float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);#elsefloat3 Normal = normalize(IN.Normal);#endiffloat3 ViewDir = normalize(IN.ViewDir);#ifdef AV_SPECULAR_COMPONENTfloat3 Reflect = normalize(reflect (-ViewDir,Normal));#endif // !AV_SPECULAR_COMPONENT{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;#define AV_LIGHT_0 IN_Light0#elsefloat L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;#define AV_LIGHT_0 afLightDir[0]#endif#ifdef AV_DIFFUSE_TEXTURE2float fHalfLambert = 1.f;#elsefloat fHalfLambert = L1*L1;#endif#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +#elseOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifndef AV_SKYBOX_LOOKUP#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#else#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SKYBOX_LOOKUP#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}#ifdef AV_OPACITYOUT.a = TRANSPARENCY;#endif#ifdef AV_LIGHTMAP_TEXTUREOUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;#endif#ifdef AV_OPACITY_TEXTUREOUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;#endifreturn OUT;#undef AV_LIGHT_0}float4 MaterialPShaderSpecular_D2(VS_OUTPUT IN) : COLOR{float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);#ifdef AV_NORMAL_TEXTUREfloat3 IN_Light0 = normalize(IN.Light0);float3 IN_Light1 = normalize(IN.Light1);float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);#elsefloat3 Normal = normalize(IN.Normal);#endiffloat3 ViewDir = normalize(IN.ViewDir);#ifdef AV_SPECULAR_COMPONENTfloat3 Reflect = -normalize(reflect (ViewDir,Normal));#endif // !AV_SPECULAR_COMPONENT{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;#define AV_LIGHT_0 IN_Light0#elsefloat L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;#define AV_LIGHT_0 afLightDir[0]#endiffloat fHalfLambert = L1*L1;#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +#elseOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifndef AV_SKYBOX_LOOKUP#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#else#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SKYBOX_LOOKUP#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;#define AV_LIGHT_1 IN_Light1#elsefloat L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;#define AV_LIGHT_1 afLightDir[1]#endiffloat fHalfLambert = L1*L1;#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +#elseOUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifndef AV_SKYBOX_LOOKUP#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#else#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SKYBOX_LOOKUP#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}#ifdef AV_OPACITYOUT.a = TRANSPARENCY;#endif#ifdef AV_LIGHTMAP_TEXTUREOUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;#endif#ifdef AV_OPACITY_TEXTUREOUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;#endifreturn OUT;#undef AV_LIGHT_0#undef AV_LIGHT_1}float4 MaterialPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR{float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);#ifdef AV_NORMAL_TEXTUREfloat3 IN_Light0 = normalize(IN.Light0);float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);#elsefloat3 Normal = normalize(IN.Normal);#endiffloat3 ViewDir = normalize(IN.ViewDir);{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,IN_Light0);#elsefloat L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,afLightDir[0]);#endif#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +#elseOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}#ifdef AV_OPACITYOUT.a = TRANSPARENCY;#endif#ifdef AV_OPACITY_TEXTUREOUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;#endifreturn OUT;}float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR{float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);#ifdef AV_NORMAL_TEXTUREfloat3 IN_Light0 = normalize(IN.Light0);float3 IN_Light1 = normalize(IN.Light1);float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);#elsefloat3 Normal = normalize(IN.Normal);#endiffloat3 ViewDir = normalize(IN.ViewDir);{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,IN_Light0);#elsefloat L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,afLightDir[0]);#endif#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +#elseOUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}{#ifdef AV_NORMAL_TEXTUREfloat L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,IN_Light1);#elsefloat L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;float3 Reflect = reflect (Normal,afLightDir[1]);#endif#ifdef AV_DIFFUSE_TEXTUREOUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +#elseOUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +#endif // !AV_DIFFUSE_TEXTURE#ifdef AV_SPECULAR_COMPONENT#ifdef AV_SPECULAR_TEXTURESPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#elseSPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +#endif // !AV_SPECULAR_TEXTURE#endif // !AV_SPECULAR_COMPONENT#ifdef AV_AMBIENT_TEXTUREAMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +#elseAMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb +#endif // !AV_AMBIENT_TEXTURE#ifdef AV_EMISSIVE_TEXTUREEMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;#elseEMISSIVE_COLOR.rgb;#endif // !AV_EMISSIVE_TEXTURE}#ifdef AV_OPACITYOUT.a = TRANSPARENCY;#endif#ifdef AV_OPACITY_TEXTUREOUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;#endifreturn OUT;}technique MaterialFXSpecular_D1{pass p0{#ifdef AV_OPACITY_TEXTUREAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#else#ifdef AV_OPACITYAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#endif#endifPixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();VertexShader = compile vs_3_0 MaterialVShader_D1();}};technique MaterialFXSpecular_D2{pass p0{#ifdef AV_OPACITY_TEXTUREAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#else#ifdef AV_OPACITYAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#endif#endifPixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();VertexShader = compile vs_3_0 MaterialVShader_D2();}};technique MaterialFXSpecular_PS20_D1{pass p0{#ifdef AV_OPACITY_TEXTUREAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#else#ifdef AV_OPACITYAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#endif#endifPixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D1();VertexShader = compile vs_2_0 MaterialVShader_D1();}};technique MaterialFXSpecular_PS20_D2{pass p0{//CullMode=none;#ifdef AV_OPACITY_TEXTUREAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#else#ifdef AV_OPACITYAlphaBlendEnable=TRUE;SrcBlend = srcalpha;DestBlend = invsrcalpha;#endif#endifPixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D2();VertexShader = compile vs_2_0 MaterialVShader_D2();}};technique MaterialFX_FF{pass p0{//CullMode=none;SpecularEnable = true;VertexShader = compile vs_2_0 MaterialVShader_FF();ColorOp[0] = Modulate;ColorArg0[0] = Texture;ColorArg1[0] = Diffuse;AlphaOp[0] = Modulate;AlphaArg0[0] = Texture;AlphaArg1[0] = Diffuse;}};[/source]

It's supposed to handle the material effects from an imported mesh (3ds in my case), and it seems to run just fine from the Assimp Viewer demo. My graphics card supports shaders up to version 3.0, so I know that isn't the issue. Any ideas of what might be wrong?

Edited by Rectangle, 30 August 2012 - 07:41 AM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31810

Like
1Likes
Like

Posted 30 August 2012 - 07:07 AM

Try:
sampler DIFFUSE_SAMPLER = sampler_state

{


#3 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 30 August 2012 - 07:47 AM

Thanks, that seems to have done the trick!
Though I still don't understand how it works in Assimp Viewer without any modification.
Perhaps I'm missing a precompiler flag somewhere.

#4 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 30 August 2012 - 11:17 AM

OK... Just one more. I'm getting the following message:
C:\pathto\defaultShader.fx(148)
ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed

And here's the shader:
[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;float4x4 World : WORLD;float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;float3 afLightColor[5];float3 afLightDir[5];float3 vCameraPos : CAMERAPOSITION;float4x3 gBoneMatrix[60];struct VS_INPUT{ float3 Position : POSITION; float3 Normal : NORMAL; float4 BlendIndices : BLENDINDICES; float4 BlendWeights : BLENDWEIGHT;};struct VS_OUTPUT{ float4 Position : POSITION; float3 ViewDir : TEXCOORD0; float3 Normal : TEXCOORD1;};VS_OUTPUT DefaultVShader(VS_INPUT IN){ VS_OUTPUT Out; float4 weights = IN.BlendWeights; weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); float4 localPos = float4( IN.Position, 1.0f); float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection); float3 WorldPos = mul( float4( objPos, 1.0f), World); Out.ViewDir = vCameraPos - WorldPos; Out.Normal = mul(IN.Normal,WorldInverseTranspose); return Out;}float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f,0.0f,0.0f,1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f; float3 Reflect = reflect (Normal,afLightDir[0]); float fHalfLambert = L1*L1; OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,ViewDir),9)); } return OUT;}float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f,0.0f,0.0f,1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f; float3 Reflect = reflect (ViewDir,Normal); float fHalfLambert = L1*L1; OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[0]),9)); } { float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f; float3 Reflect = reflect (ViewDir,Normal); float fHalfLambert = L1*L1; OUT.rgb += afLightColor[1] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9)); } return OUT;}float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f,0.0f,0.0f,1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot(Normal,afLightDir[0]); float3 Reflect = reflect (Normal,afLightDir[0]); OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9)); } return OUT;}float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f,0.0f,0.0f,1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot(Normal,afLightDir[0]); float3 Reflect = reflect (Normal,afLightDir[0]); OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9)); } { float L1 = dot(Normal,afLightDir[1]); float3 Reflect = reflect (Normal,afLightDir[1]); OUT.rgb += afLightColor[1] * ((L1) + pow(dot(Reflect,ViewDir),9)); } return OUT;}technique DefaultFXSpecular_D1{ pass p0 { CullMode=none; PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1(); VertexShader = compile vs_3_0 DefaultVShader(); }};technique DefaultFXSpecular_D2{ pass p0 { CullMode=none; PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2(); VertexShader = compile vs_3_0 DefaultVShader(); }};technique DefaultFXSpecular_PS20_D1{ pass p0 { CullMode=none; PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1(); VertexShader = compile vs_2_0 DefaultVShader(); }};technique DefaultFXSpecular_PS20_D2{ pass p0 { CullMode=none; PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2(); VertexShader = compile vs_2_0 DefaultVShader(); }};[/source]

Here's the source where I attempt to compile it:
[source lang="cpp"]//...if(FAILED( D3DXCreateEffectFromFileA(m_d3dDev, m_szDefaultShaderFile, NULL, NULL, D3DXSHADER_USE_LEGACY_D3DX9_31_DLL, NULL, &m_piDefaultEffect, &piBuffer) ))//...[/source]

It appears to complain for each technique (i.e., If I comment out the DefaultFXSpecular_PS20_D2 technique, it then complains about line #138 in DefaultFXSpecular_PS20_D1).
Am I using the wrong syntax here?

Edited by Rectangle, 31 August 2012 - 01:30 AM.


#5 phil_t   Crossbones+   -  Reputation: 4094

Like
0Likes
Like

Posted 31 August 2012 - 12:15 AM

Looks like shader model 2.0 only supports 32 constant registers. You've got way more than that (202 by my count). Can you switch to 3.0 shaders?

Edited by phil_t, 31 August 2012 - 12:16 AM.


#6 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 31 August 2012 - 01:50 AM

Well the idea here is to allow specular shading for both 2.0 and 3.0 enabled cards.
And even with the following modifications, it still fails to compile (showing the same error on the bottom-most 'VertexShader = compile vs_x_x DefaultShader()' line, just like before):
[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;float4x4 World : WORLD;float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;float3 afLightColor[5];float3 afLightDir[5];float3 vCameraPos : CAMERAPOSITION;float4x3 gBoneMatrix[60];struct VS_INPUT{ float3 Position : POSITION; float3 Normal : NORMAL; float4 BlendIndices : BLENDINDICES; float4 BlendWeights : BLENDWEIGHT;};struct VS_OUTPUT{ float4 Position : POSITION; float3 ViewDir : TEXCOORD0; float3 Normal : TEXCOORD1;};VS_OUTPUT DefaultVShader(VS_INPUT IN){ VS_OUTPUT Out; float4 weights = IN.BlendWeights; weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1) ); float4 localPos = float4( IN.Position, 1.0f ); float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x] ) * weights.x; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y] ) * weights.y; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z] ) * weights.z; objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w] ) * weights.w; Out.Position = mul( float4(objPos, 1.0f), WorldViewProjection ); float3 WorldPos = mul( float4(objPos, 1.0f), World ); Out.ViewDir = vCameraPos - WorldPos; Out.Normal = mul( IN.Normal,WorldInverseTranspose ); return Out;}float4 DefaultPShaderSpecular(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot( Normal,afLightDir[0] ) * 0.5f + 0.5f; float3 Reflect = reflect( Normal,afLightDir[0] ); float fHalfLambert = L1 * L1; OUT.rgb += afLightColor[0] * ( fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, ViewDir), 9) ); } return OUT;}technique DefaultFXSpecular{ pass p0 { CullMode=none; PixelShader = compile ps_3_0 DefaultPShaderSpecular(); VertexShader = compile vs_3_0 DefaultVShader(); }};[/source]

After reading other similar posts across the internet, I'm almost certain it has something to do with my vertex struct. But what?

#EDIT: The following won't compile either. So now I'm at a total loss as to why this error is occuring.
[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;float4x4 World : WORLD;float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;float3 vCameraPos : CAMERAPOSITION;float3 afLightColor[5];float3 afLightDir[5];struct VS_INPUT{ float3 Position : POSITION; float3 Normal : NORMAL;};struct VS_OUTPUT{ float4 Position : POSITION; float3 ViewDir : TEXCOORD0; float3 Normal : TEXCOORD1;};VS_OUTPUT DefaultVShader(VS_INPUT IN){ VS_OUTPUT OUT; OUT.Position = mul( IN.Position, WorldViewProjection ); float3 WorldPos = mul( IN.Position, World ); OUT.ViewDir = vCameraPos - WorldPos; OUT.Normal = mul(IN.Normal, WorldInverseTranspose); return OUT;};float4 DefaultPShaderSpecular(VS_OUTPUT IN) : COLOR{ float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f); float3 Normal = normalize(IN.Normal); float3 ViewDir = normalize(IN.ViewDir); { float L1 = dot(Normal, afLightDir[0]) * 0.5f + 0.5f; float3 Reflect = reflect (Normal, afLightDir[0]); float fHalfLambert = L1*L1; OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, ViewDir), 9)); } return OUT;};technique DefaultFXSpecular{ pass p0 { CullMode = none; PixelShader = compile ps_3_0 DefaultPShaderSpecular(); VertexShader = compile vs_3_0 DefaultVShader(); }};[/source]

Edited by Rectangle, 31 August 2012 - 02:07 AM.


#7 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 31 August 2012 - 06:41 AM

Well I figured out why it wouldn't compile. Or rather, I got it to compile. I replaced the shader flag D3DXSHADER_USE_LEGACY_D3DX9_31_DLL with D3DXSHADER_DEBUG and it finally stopped crying. Of course, this means that I can't implement legacy shader support, which kind of sucks. But high functionality is better than none at all...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS