• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Rectangle

HLSL shader refuses to compile

6 posts in this topic

I don't see anything wrong with the syntax of this shader (found in [url="http://assimp.sourceforge.net/"]Assimp[/url]).
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_DISABLESSS
float4x3 ViewProj;
float4x3 InvViewProj;
#endif
float4 DIFFUSE_COLOR;
float4 SPECULAR_COLOR;
float4 AMBIENT_COLOR;
float4 EMISSIVE_COLOR;
#ifdef AV_SPECULAR_COMPONENT
float SPECULARITY;
float SPECULAR_STRENGTH;
#endif
#ifdef AV_OPACITY
float TRANSPARENCY;
#endif
float4 afLightColor[5];
float4 afLightColorAmbient[5];
float3 afLightDir[5];
float3 vCameraPos : CAMERAPOSITION;
#ifdef AV_SKINNING
float4x3 gBoneMatrix[60];
#endif // AV_SKINNING
#ifdef AV_DIFFUSE_TEXTURE
texture DIFFUSE_TEXTURE;
sampler DIFFUSE_SAMPLER
{
Texture = <DIFFUSE_TEXTURE>;
#ifdef AV_WRAPU
AddressU = WRAP;
#endif
#ifdef AV_MIRRORU
AddressU = MIRROR;
#endif
#ifdef AV_CLAMPU
AddressU = CLAMP;
#endif
#ifdef AV_WRAPV
AddressV = WRAP;
#endif
#ifdef AV_MIRRORV
AddressV = MIRROR;
#endif
#ifdef AV_CLAMPV
AddressV = CLAMP;
#endif
};
#endif // AV_DIFFUSE_TEXTUR
#ifdef AV_DIFFUSE_TEXTURE2
texture DIFFUSE_TEXTURE2;
sampler DIFFUSE_SAMPLER2
{
Texture = <DIFFUSE_TEXTURE2>;
};
#endif // AV_DIFFUSE_TEXTUR2
#ifdef AV_SPECULAR_TEXTURE
texture SPECULAR_TEXTURE;
sampler SPECULAR_SAMPLER
{
Texture = <SPECULAR_TEXTURE>;
};
#endif // AV_SPECULAR_TEXTUR
#ifdef AV_AMBIENT_TEXTURE
texture AMBIENT_TEXTURE;
sampler AMBIENT_SAMPLER
{
Texture = <AMBIENT_TEXTURE>;
};
#endif // AV_AMBIENT_TEXTUR
#ifdef AV_LIGHTMAP_TEXTURE
texture LIGHTMAP_TEXTURE;
sampler LIGHTMAP_SAMPLER
{
Texture = <LIGHTMAP_TEXTURE>;
};
#endif // AV_LIGHTMAP_TEXTURE
#ifdef AV_OPACITY_TEXTURE
texture OPACITY_TEXTURE;
sampler OPACITY_SAMPLER
{
Texture = <OPACITY_TEXTURE>;
};
#endif // AV_OPACITY_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
texture EMISSIVE_TEXTURE;
sampler EMISSIVE_SAMPLER
{
Texture = <EMISSIVE_TEXTURE>;
};
#endif // AV_EMISSIVE_TEXTUR
#ifdef AV_NORMAL_TEXTURE
texture NORMAL_TEXTURE;
sampler NORMAL_SAMPLER
{
Texture = <NORMAL_TEXTURE>;
};
#endif // AV_NORMAL_TEXTURE
#ifdef AV_SKYBOX_LOOKUP
textureCUBE lw_tex_envmap;
samplerCUBE EnvironmentMapSampler = sampler_state
{
Texture = (lw_tex_envmap);
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
MAGFILTER = linear;
MINFILTER = linear;
};
#endif // AV_SKYBOX_LOOKUP
struct VS_INPUT
{
float3 Position : POSITION;
float3 Normal : NORMAL;
float4 Color : COLOR0;
float3 Tangent : TANGENT;
float3 Bitangent : BINORMAL;
float2 TexCoord0 : TEXCOORD0;
#ifdef AV_TWO_UV
float2 TexCoord1 : TEXCOORD1;
#endif
#ifdef AV_SKINNING
float4 BlendIndices : BLENDINDICES;
float4 BlendWeights : BLENDWEIGHT;
#endif // AV_SKINNING
};
struct VS_OUTPUT
{
float4 Position : POSITION;
float3 ViewDir : TEXCOORD0;
float4 Color : COLOR0;
#ifndef AV_NORMAL_TEXTURE
float3 Normal : TEXCOORD1;
#endif
float2 TexCoord0 : TEXCOORD2;
#ifdef AV_TWO_UV
float2 TexCoord1 : TEXCOORD3;
#endif
#ifdef AV_NORMAL_TEXTURE
float3 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_SKINNING
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;
#else
float3 objPos = IN.Position;
#endif // AV_SKINNING
Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);
float3 WorldPos = mul( float4( objPos, 1.0f), World);
Out.TexCoord0 = IN.TexCoord0;
#ifdef AV_TWO_UV
Out.TexCoord1 = IN.TexCoord1;
#endif
Out.Color = IN.Color;
#ifndef AV_NORMAL_TEXTURE
Out.ViewDir = vCameraPos - WorldPos;
Out.Normal = mul(IN.Normal,WorldInverseTranspose);
#endif
#ifdef AV_NORMAL_TEXTURE
float3x3 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)));
#endif
return Out;
}
VS_OUTPUT MaterialVShader_D2(VS_INPUT IN)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
#ifdef AV_SKINNING
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;
#else
float3 objPos = IN.Position;
#endif // AV_SKINNING
Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);
float3 WorldPos = mul( float4( objPos, 1.0f), World);
Out.TexCoord0 = IN.TexCoord0;
#ifdef AV_TWO_UV
Out.TexCoord1 = IN.TexCoord1;
#endif
Out.Color = IN.Color;
#ifndef AV_NORMAL_TEXTURE
Out.ViewDir = vCameraPos - WorldPos;
Out.Normal = mul(IN.Normal,WorldInverseTranspose);
#endif
#ifdef AV_NORMAL_TEXTURE
float3x3 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)));
#endif
return Out;
}
VS_OUTPUT_FF MaterialVShader_FF(VS_INPUT IN)
{
VS_OUTPUT_FF Out = (VS_OUTPUT_FF)0;
#ifdef AV_SKINNING
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;
#else
float3 objPos = IN.Position;
#endif // AV_SKINNING
Out.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_COMPONENT
float3 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_COMPONENT
Out.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_TEXTURE
float3 IN_Light0 = normalize(IN.Light0);
float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);
#else
float3 Normal = normalize(IN.Normal);
#endif
float3 ViewDir = normalize(IN.ViewDir);
#ifdef AV_SPECULAR_COMPONENT
float3 Reflect = normalize(reflect (-ViewDir,Normal));
#endif // !AV_SPECULAR_COMPONENT
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;
#define AV_LIGHT_0 IN_Light0
#else
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
#define AV_LIGHT_0 afLightDir[0]
#endif
#ifdef AV_DIFFUSE_TEXTURE2
float fHalfLambert = 1.f;
#else
float fHalfLambert = L1*L1;
#endif
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +
#else
OUT.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_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
SPECULAR_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)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
#ifdef AV_OPACITY
OUT.a = TRANSPARENCY;
#endif
#ifdef AV_LIGHTMAP_TEXTURE
OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;
#endif
#ifdef AV_OPACITY_TEXTURE
OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;
#endif
return 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_TEXTURE
float3 IN_Light0 = normalize(IN.Light0);
float3 IN_Light1 = normalize(IN.Light1);
float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);
#else
float3 Normal = normalize(IN.Normal);
#endif
float3 ViewDir = normalize(IN.ViewDir);
#ifdef AV_SPECULAR_COMPONENT
float3 Reflect = -normalize(reflect (ViewDir,Normal));
#endif // !AV_SPECULAR_COMPONENT
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;
#define AV_LIGHT_0 IN_Light0
#else
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
#define AV_LIGHT_0 afLightDir[0]
#endif
float fHalfLambert = L1*L1;
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +
#else
OUT.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_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
SPECULAR_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)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;
#define AV_LIGHT_1 IN_Light1
#else
float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;
#define AV_LIGHT_1 afLightDir[1]
#endif
float fHalfLambert = L1*L1;
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +
#else
OUT.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_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
SPECULAR_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)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
#ifdef AV_OPACITY
OUT.a = TRANSPARENCY;
#endif
#ifdef AV_LIGHTMAP_TEXTURE
OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;
#endif
#ifdef AV_OPACITY_TEXTURE
OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;
#endif
return 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_TEXTURE
float3 IN_Light0 = normalize(IN.Light0);
float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);
#else
float3 Normal = normalize(IN.Normal);
#endif
float3 ViewDir = normalize(IN.ViewDir);
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,IN_Light0);
#else
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,afLightDir[0]);
#endif
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +
#else
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +
#endif // !AV_DIFFUSE_TEXTURE
#ifdef AV_SPECULAR_COMPONENT
#ifdef AV_SPECULAR_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
#ifdef AV_OPACITY
OUT.a = TRANSPARENCY;
#endif
#ifdef AV_OPACITY_TEXTURE
OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;
#endif
return OUT;
}
float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR
{
float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);
#ifdef AV_NORMAL_TEXTURE
float3 IN_Light0 = normalize(IN.Light0);
float3 IN_Light1 = normalize(IN.Light1);
float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);
#else
float3 Normal = normalize(IN.Normal);
#endif
float3 ViewDir = normalize(IN.ViewDir);
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,IN_Light0);
#else
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,afLightDir[0]);
#endif
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +
#else
OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +
#endif // !AV_DIFFUSE_TEXTURE
#ifdef AV_SPECULAR_COMPONENT
#ifdef AV_SPECULAR_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
{
#ifdef AV_NORMAL_TEXTURE
float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,IN_Light1);
#else
float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal,afLightDir[1]);
#endif
#ifdef AV_DIFFUSE_TEXTURE
OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +
#else
OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +
#endif // !AV_DIFFUSE_TEXTURE
#ifdef AV_SPECULAR_COMPONENT
#ifdef AV_SPECULAR_TEXTURE
SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) +
#else
SPECULAR_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_TEXTURE
AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +
#else
AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb +
#endif // !AV_AMBIENT_TEXTURE
#ifdef AV_EMISSIVE_TEXTURE
EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;
#else
EMISSIVE_COLOR.rgb;
#endif // !AV_EMISSIVE_TEXTURE
}
#ifdef AV_OPACITY
OUT.a = TRANSPARENCY;
#endif
#ifdef AV_OPACITY_TEXTURE
OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;
#endif
return OUT;
}
technique MaterialFXSpecular_D1
{
pass p0
{
#ifdef AV_OPACITY_TEXTURE
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#else
#ifdef AV_OPACITY
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#endif
#endif
PixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();
VertexShader = compile vs_3_0 MaterialVShader_D1();
}
};
technique MaterialFXSpecular_D2
{
pass p0
{
#ifdef AV_OPACITY_TEXTURE
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#else
#ifdef AV_OPACITY
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#endif
#endif
PixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();
VertexShader = compile vs_3_0 MaterialVShader_D2();
}
};
technique MaterialFXSpecular_PS20_D1
{
pass p0
{
#ifdef AV_OPACITY_TEXTURE
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#else
#ifdef AV_OPACITY
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#endif
#endif
PixelShader = 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_TEXTURE
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#else
#ifdef AV_OPACITY
AlphaBlendEnable=TRUE;SrcBlend = srcalpha;
DestBlend = invsrcalpha;
#endif
#endif
PixelShader = 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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
OK... Just one more. I'm getting the following message:
[code]C:\pathto\defaultShader.fx(148)
ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed[/code]

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 [i]DefaultFXSpecular_PS20_D2[/i] technique, it then complains about line #138 in [i]DefaultFXSpecular_PS20_D1[/i]).
Am I using the wrong syntax here? Edited by Rectangle
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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 '[i]VertexShader = compile vs_x_x DefaultShader()[/i]' 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?

[b]#EDIT[/b]: 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
0

Share this post


Link to post
Share on other sites
Well I figured out why it wouldn't compile. Or rather, I got it to compile. I replaced the shader flag [i]D3DXSHADER_USE_LEGACY_D3DX9_31_DLL[/i] with [i]D3DXSHADER_DEBUG[/i] 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...
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0