@Terrorist Zero
OK. Here's my latest attempt. I'm sure it can be improved, but I think we're on the right track now.
Here's the revised DBPro code snippet:
`Set Up Display
set display mode 1024,768,32,1
sync on : sync rate 0
hide mouse
` backdrop off
color backdrop rgb(0,0,0)
`Setup Camera
autocam off
position camera 0,50,-150
set camera fov 70
`Base Map
load object "map001/map.x",1
`Light Map
load image "SpotLight2.dds",1,2
load effect "FX/FlashLightGG.fx",2,0
texture object 1,1,1
set object effect 1,2
set object normals 1
`Brightness
Brightness#=0
Light=0
Ambient# = 0.3 ` GG addition
set effect constant float 2, "Ambient", Ambient# ` GG addition
`Vector / Matrixs
vec = make vector4(1)
mat = make matrix4(2)
mat = make matrix4(3)
mat = make matrix4(4)
mat = make matrix4(5)
`-----------------------
`Start loop
do
`Control Camera
cr#=0:cf#=0
if rightkey()=1 or KEYSTATE(32)=1 then cr#=-20
if leftkey()=1 or KEYSTATE(30)=1 then cr#=20
if upkey()=1 or KEYSTATE(17)=1 then cf#=20
if downkey()=1 or KEYSTATE(31)=1 then cf#=-20
ncr#=curvevalue(cr#,ncr#,5)
ncf#=curvevalue(cf#,ncf#,5)
cx#=cx#+mousemovey()*0.2
cy#=cy#+mousemovex()*0.2
if cx#>80 then cx#=80
if cx#<-80 then cx#=-80
ncx#=curveangle(cx#,ncx#,2)
ncy#=curveangle(cy#,ncy#,2)
move camera ncf#
rotate camera 0,wrapvalue(ncy#-90),0
move camera ncr#
rotate camera 0,wrapvalue(ncy#+90),0
rotate camera ncx#,ncy#,0
`Flash Light On/OFf
if KEYSTATE(33)=1 and NoPress=0 and Light=0 then Light=1:NoPress=1
if KEYSTATE(33)=1 and NoPress=0 and Light=1 then Light=0:NoPress=1
if Light=0 then Brightness#=Brightness#-0.1
if Light=1 then Brightness#=Brightness#+0.1
if Brightness#>1.0 then Brightness#=1.0
if Brightness#<0.0 then Brightness#=0.0
set effect constant float 2,"BrightNess",Brightness#
if KEYSTATE(33)=0 then NoPress=0
`Move Flash Light to camera pos / angle
set vector4 1,camera position x(),camera position y(),camera position z(),0
set effect constant vector 2,"LightPosition",1
angX#=curveangle(camera angle x(),angX#,4)
angY#=curveangle(camera angle Y(),angY#,4)
rotate x matrix4 2,(angX#)/57.3
rotate y matrix4 3,(angY#)/57.3
rotate z matrix4 4,(angZ#)/57.3
multiply matrix4 5,2,3
multiply matrix4 5,5,4
set effect constant matrix 2,"LightAngle",5
`End loop
sync
loop
And here's the revised FX code:
//--------------------------------
// By Evolved with edits for Terrorist Zero by Green Gandalf
// http://www.vector3r.com/
//--------------------------------
//-----------------
// un-tweaks
//-----------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
//-----------------
// tweaks
//-----------------
float4 LightPosition = {150.0f, 150.0f, 0.0f, 1.0f};
float LightRange = 1500.0f;
float BrightNess = 1.0f;
float Ambient = 0.2; // GG addition
float3x3 LightAngle;
//-----------------
// Textures
//-----------------
texture BaseTX
<
string ResourceName="";
>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture CubeLightTX
<
string ResourceName = "";
>;
sampler CubeLight = sampler_state
{
Texture = <CubeLightTX>;
};
//-----------------
// structs
//-----------------
struct input
{
float4 Pos:POSITION;
float2 UV0:TEXCOORD0;
float3 Normal : NORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 UV0:TEXCOORD0;
float3 Attenuation:TEXCOORD1;
float Diffuse:TEXCOORD2;
float3 CubeLight:TEXCOORD3;
};
//-----------------
// vertex shader
//-----------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.UV0=IN.UV0;
float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
float3 WPos=mul(IN.Pos,World);
float3 LightPos=LightPosition-WPos;
OUT.Attenuation=-LightPos/LightRange;
OUT.Diffuse=saturate(0.015f+mul(Wnor,LightPos)*0.015f);
OUT.CubeLight=mul(LightAngle,-LightPos);
return OUT;
}
//-----------------+tex2D(Base2,IN.UV2)+tex2D(Base3,IN.UV3)
// pixel shader
//-----------------
float4 PS(output IN) : COLOR
{
float3 Texture=tex2D(Base,IN.UV0);
float DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
float Light=DiffuseLight*IN.Diffuse;
float3 FlashLight=texCUBE(CubeLight,IN.CubeLight);
return float4(Texture * (Ambient + FlashLight*Light*BrightNess),1);
}
//-----------------
// techniques
//-----------------
technique FlashLight
{
pass p1
{
vertexShader = compile vs_1_1 VS();
pixelShader = compile ps_2_0 PS(); // GG change from PS1.4
}
}
I've made so many changes I've lost sight of the critical ones. The main change, I think, is that the code now deals with just one object (.x file). When you run the code the area is initially very dark - so it's hard to tell when it's actually loaded and ready to go. If that's a problem just increase the ambient value in the DBPro code - that's something I added to the code and the shader.
The downside is that I'm sure something has been lost in the lighting - perhaps that's the lightmapping you were referring to? Anyway, now I've sorted out the main problem, we can move on.
I'm sure we can fix the lightmapping - I'd forgotten it was there.
Let me know what you think and if anything is missing, i.e. textures, lightmaps, etc.
In the meantime I'll see if I can find the lightmap you referred to.
Edit: OK, I've found the lightmaps. I completely missed the point of the second object. Sorry. Is there any reason why you can't apply the lightmap to the original object - i.e. have the textures and lightmaps in one place? I can then adjust the shader to read the appropriate texture stage UV coords. All I need to know is the texture stage for the base texture and the stage for the light map - and if you don't know, I can probably work it out (did something similar for Overdroid the other day).