Here you go:
Revised dba code:
`-----------------------
` Toon Shading
`-----------------------
` By Evolved
` http://www.vector3r.com/
`-----------------------
`Set Up Screen
set display mode desktop width(),desktop height(),32, 1, 0, 0
hide mouse
hide light 0
set ambient light 15
enableCartoonShader as integer : enableCartoonShader = 1 `comment this line to see non-shader version of the ship
objectno as integer : objectno = 1
stageindex as integer : stageindex = 2 `base tex in stage 0, lightmaps in stage 1, alpha in stage 2 then
limbno as integer : limbno = 2 `hull
alphaimageno as integer : alphaimageno = 4 `2 - player_tex_alph.png above
texcoordmode as integer : texcoordmode = 3 `(3 - Steal UV Data From Stage Zero)
blendmode as integer : blendmode = 7`7 `(7 - D3DTOP_ADD)
`Setup Camera
position camera 0,0,-450
color backdrop rgb(155,96,96)
`Make object
if enableCartoonShader = 1
`load object "Data/shadercruiser/cruiser.dbo",objectno ` *** you need the same object for the shader
load object "Data/cruiser/cruiser.dbo",objectno ` *** i.e. no need for this if block
else
load object "Data/cruiser/cruiser.dbo",objectno
make light 1`create a light for the star
set light range 1, 9500000`12000
SET POINT LIGHT 1, -150, 0, 50
endif
scale object objectno,20,20,20
set object light objectno, 1
`Load images
load image "data/toon.bmp" ,1
load image "data/Shade.bmp" ,2
load image "data/textures/shiptextures/cruiser/cruiser.dds" ,3
load image "data/textures/shiptextures/cruiser/cruiserALPHA.png" ,4
if enableCartoonShader = 1
` texture object objectno,0,3 `1,0,1
` texture object objectno,1,2 `1,1,2
` texture limb objectno, limbno, 2, 3 `NOTE! ob number, limb number, stage index, image number!
`texture limb objectno, limbno, 1, 3
`texture limb objectno, limbno, 1, 3
` texture object objectno,0,3
` texture object objectno,,4
texture object objectno,2,2
texture object objectno,3,4
endif
`SET BLEND MAPPING ON objectno, stageindex, limbno, alphaimageno, texcoordmode, blendmode, -1, -1, -1, -1
a0$ = LIMB TEXTURE NAME(objectno, limbno, 0) `ob, limb, texture stage
a1$ = LIMB TEXTURE NAME(objectno, limbno, 1) `ob, limb, texture stage
a2$ = LIMB TEXTURE NAME(objectno, limbno, 2) `ob, limb, texture stage
a3$ = LIMB TEXTURE NAME(objectno, limbno, 3) `ob, limb, texture stage
`Set effect
load effect "Effect/Toon2.fx",1, 0, 0
if enableCartoonShader = 1
set object effect objectno,1
endif
vec = make vector4(1)
`Make Light Object
make object sphere 2,2
position object 2, -150, 0, 50
`-----------------------
`start loop
do
`Rotate Object
xrotate object objectno,object angle x(1)-mousemovey()*0.2
yrotate object objectno,object angle y(1)-mousemovex()*0.2
`Move Camera
if mouseclick()=1 then move camera 0.5
if mouseclick()=2 then move camera -0.5
if camera position z()>-50 then position camera 0,0,-50
if camera position z()<-500 then position camera 0,0,-500
`Move Light
ang#=wrapvalue(ang#+0.4)
position object 2,sin(ang#)*30,cos(ang#)*30,-80
set vector4 1,object position x(2),object position y(2),object position z(2),0
set effect constant vector 1,"LightPosition",1
text 10, 10, "stage 0: " + a0$
text 10, 30, "stage 1: " + a1$
text 10, 50, "stage 2: " + a2$
text 10, 70, "stage 3: " + a3$
text 10, 90, "fps: " + str$(screen fps())
text 10, 110, "drawprimative calls: " + str$(statistic(5))
`End loop
`sync
loop
revised shader code:
//--------------------------------
// Toon
//--------------------------------
// By Evolved
// http://www.vector3r.com/
//--------------------------------
// Modified by Green Gandalf to use lightmaps and an alpha mask
//--------------------------------
// un-tweaks
//--------------------------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------------------------
// tweaks
//--------------------------------
float EdgeDis = 0.5f;
float4 LightPosition = {0.0f, 0.0f, 0.0f, 1.0f};
float LightRange = 200.0f;
//--------------------------------
// Textures
//--------------------------------
texture Toon
<
string Name="";
>;
sampler2D ToonSample = sampler_state
{
texture = <Toon>;
};
texture LightMap
<
string Name="";
>;
sampler2D LightMapSample = sampler_state
{
texture = <LightMap>;
};
texture Shade
<
string Name="";
>;
sampler2D ShadeSample = sampler_state
{
texture = <Shade>;
};
texture AlphaMap
<
string Name="";
>;
sampler2D AlphaMapSample = sampler_state
{
texture = <AlphaMap>;
};
//--------------------------------
// structs
//--------------------------------
struct input
{
float4 Pos : POSITION ;
float2 UV : TEXCOORD0 ;
float2 LMUV : TEXCOORD1 ;
float3 Normal : NORMAL;
};
struct output
{
float4 OPos : POSITION ;
float2 uv : TEXCOORD0 ;
float2 LMuv : TEXCOORD1 ;
float2 Shade : TEXCOORD2 ;
float2 AMuv : TEXCOORD3 ;
};
struct output_Edge
{
float4 OPos : POSITION ;
float4 Edge : COLOR0 ;
};
//--------------------------------
// vertex shader
//--------------------------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.uv=IN.UV;
OUT.LMuv=IN.LMUV;
OUT.AMuv=IN.UV;
float3 WNor=mul(IN.Normal,World);
WNor=normalize(WNor);
float3 WPos=mul(IN.Pos,World);
float3 LPos=LightPosition-WPos;
float4 Light=max(saturate(0.02f+mul(LPos,WNor)*0.02f),0.2)/2;
float Dis=max(saturate(1-(length(LPos)/LightRange)),0.2);
OUT.Shade.xy=Light*Dis;
return OUT;
}
output_Edge VS_Edge(input IN)
{
output_Edge OUT;
float4 Vpos;
Vpos.xyz=IN.Pos+(IN.Normal*EdgeDis);Vpos.w=IN.Pos.w;
OUT.OPos=mul(Vpos,WorldVP);
OUT.Edge.xyzw=0;
return OUT;
}
//-----------------
// techniques
//-----------------
technique Toon
{
pass p0
{
vertexShader = compile vs_1_1 VS();
Sampler[0] = <ToonSample>;
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
Sampler[1] = <LightMapSample>;
ColorOp[1] = MODULATE;
ColorArg1[1] = TEXTURE;
Sampler[2] = <ShadeSample>;
ColorOp[2] = MODULATE;
ColorArg1[2] = TEXTURE;
Sampler[3] = <AlphaMapSample>;
ColorOp[3] = ADD;
ColorArg1[3] = TEXTURE;
}
pass p1
{
vertexShader = compile vs_1_1 VS_Edge();
CullMode = Cw;
Sampler[0] = null;
Sampler[1] = null;
}
}
Any problems, just ask.