hey Chalkey... i can't seem to get the default bumpmapping working either... it doesn't crash or anything, just doesn't show the object...
i suggest you use a different bumpmapping shader...
here's the code for Green Gandalf's bumpmapping shader...
//
// Green Gandalf's Bumpmapper v1.0e
//
// Created 2 September 2006, modified 7 September 2006.
//
// Bumpmapping using a texture and normal map with a single directional light source,
// plus ambient and specular lighting.
// Uses half vector approximation for specular reflection plus VS normalisation.
// Uses 2D texture lookup for specular light calculation.
matrix wvp : WorldViewProjection;
matrix mworld : World;
matrix winv: WorldInverse;
float3 eyePos : CameraPosition;
texture colorTexture < string ResourceName = "lead.jpg"; >;
texture bumpTexture < string ResourceName = "spherical bumps.png"; >;
texture lightLookup < string ResourceName = "light lookup table2.bmp"; >;
sampler2D sampler0 = sampler_state
{ texture = <colorTexture>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D sampler1 = sampler_state
{ texture = <bumpTexture>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D sampler2 = sampler_state
{ texture = <lightLookup>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
AddressW = Clamp;
};
float4 lightDir = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor = {1.0f, 1.0f, 1.0f, 1.0f};
float specPower = 0.31;
float specLevel = 0.5;
struct VS_INPUT
{ float4 Pos : POSITION;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
};
struct VS_OUTPUT
{ float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 Half : TEXCOORD2;
};
VS_OUTPUT GGBumpVShader(VS_INPUT In, VS_OUTPUT Out)
{ Out.Pos = mul(In.Pos, wvp);
Out.Tex = In.Tex;
float3x3 TSM = {In.Tangent, -In.Binormal, In.Normal};
TSM = transpose(TSM); // tangent space matrix
float3 temp = -mul(lightDir.xyz,winv);
temp = normalize(mul(temp,TSM));
Out.Light = temp;
float3 temp2 = mul(eyePos.xyz,winv) - In.Pos;
temp2 = normalize(mul(temp2,TSM));
Out.Half = normalize(temp + temp2);
return Out;
}
struct PS_INPUT
{ float2 Tex : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 Half : TEXCOORD2;
};
struct PS_OUTPUT
{ float4 col : COLOR;
};
PS_OUTPUT GGBumpPShader(PS_INPUT In, PS_OUTPUT Out)
{ float4 baseColour = tex2D(sampler0, In.Tex);
float3 normal = 2 * tex2D(sampler1, In.Tex) - 1.0;
float3 tempLightDir = In.Light;
float3 tempHalf = In.Half;
float diffuse = saturate(dot(normal, tempLightDir));
float2 coord2d = float2 (saturate(dot(normal, tempHalf)), specPower);
float light = specLevel * tex2D(sampler2,coord2d);
Out.col = baseColour * ambiColor + (baseColour + light) * diffuse * lightColor;
return Out;
}
technique t0
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader();
PixelShader = compile ps_2_0 GGBumpPShader();
}
}
just copy and paste it to a file called GGbump01e.fx, and place it in your projects
fx folder, so the next bit of code can find it...
then compile and run this code...
#include "stdafx.h"
#include "DarkGDK.h"
float yRot;
void DarkGDK ( void ){
dbSetDisplayMode(800,600,32);
dbAutoCamOff();
dbControlCameraUsingArrowKeys( 0,1,1);
dbBackdropOn();
dbBackdropColor(dbRGB(22,22,222));
dbSyncOn();
dbSyncRate (60);
dbSetTextFont( "Verdana");
dbSetTextSize (12);
dbSetTextToBold();
dbInk(dbRGB(200,200,200),0);
dbMakeObjectCube(1,88);
//dbScaleObject(1,700,700,700);
dbPositionObject(1,0,0,166);
dbPositionCamera(0,0,0,0);
dbLoadImage("..medialift.bmp",1);
dbLoadImage("..medialiftnormalmap.bmp",2);
dbLoadEffect("..fxGGbump01e.fx",1,0);
dbTextureObject(1,0,1);
dbTextureObject(1,1,2);
//dbSetBumpMappingOn(1,2);
dbSetObjectEffect(1,1);
while (dbKeyState(1)==0){
dbRotateObject(1,0,yRot,0);
dbSync();
yRot=yRot+0.26;
}
}
it's a simple program which will just give you a bumpmapped cube rotating in the middle of the view...
note 1
you will need to supply your own image and normal map, and put it in the projects
media folder so the code can find it... don't forget to replace the names in the code...
note 2
GG uses a light direction instead of light position, so you'll have to come up with an algorithm for changing the lighting direction and passing it as a variable to the shader...
note 3
look through the shader code to see what other variables can be passed to the shader to get different effects...
i hope this helps... good luck
--Mike