Fur Shader Old
From GameStudio Wiki
[edit]
fur shader
the alpha channel of bmp_fur should look like this:
the color channels don't get used.
the entity should just use an ordinary color map.
play around with the skills!
- skill41 is the distance of the shells.
- the innermost shell has the brightness skill1 and with each shell the brightness increases with the value of skill2.
- skill43 and skill44 define how fine the fur will be.
the shader is quite slow especially if the camera is very near because there is a lot of overdraw. you could add or remove additional shells / passes...
bmap bmp_fur=<fur.tga>;
function mtl_fur_init
{
mtl.skill1=float(0.2); // first_shell_brightness
mtl.skill2=float(0.04); // brightness_increment
bmap_to_mipmap(mtl.skin1);
}
material mtl_fur
{
event=mtl_fur_init;
skin1=bmp_fur;
effect
"
texture entSkin1;
texture mtlSkin1;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSkill1;
vector vecSkill41;
vector vecFog;
vector vecSunDir;
technique fur
{
pass p0
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=false;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>; // shell_distance, 0, fur_u_scale, fur_v_scale
vertexShaderConstant[17]=(0.0,0.0,0.0,0.0); // shell_number
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>; // first_shell_brightness, brightness_increment, 0, 0
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3]; // position
float v3[3]; // normal
float v7[3]; // uv
}
asm
{
vs.1.1
m3x3 r0,v3,c4 // transform normal to world space
dp3 r0,r0,-c19 // normal.light
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x // shell distance * shell number
mul r1,r1,v3 // scale normal
add r0.xyz,r0.xyz,r1.xyz // shell offset (vertex position + scaled normal)
m4x4 oPos,r0,c0 // transform position to clip space
mov oT0,v7 // output uvs
mul oT1.xy,v7.xy,c16.zw // output scaled uvs
mov r1.w,c20.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c20.x // distance-fog_start
mad r0.x,-r0.x,c20.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog.x,r0.x,c95.w // clamp with custom max value
};
pixelShader=
asm
{
ps.1.1
tex t0 // sample colormap
tex t1 // sample noise
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};
}
//-----------------------------------------------------------------------------
pass p1
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(1.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p2
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(2.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p3
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(3.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p4
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(4.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p5
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(5.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p6
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(6.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p7
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(7.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p8
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(8.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p9
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(9.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p10
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(10.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
pass p11
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;
zWriteEnable=true;
alphaBlendEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSkill41>;
vertexShaderConstant[17]=(11.0,0.0,0.0,0.0);
vertexShaderConstant[19]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[94]=<vecSkill1>;
vertexShaderConstant[95]=(0.5,1.0,2.0,0.0);
vertexShader =
decl
{
stream 0;
float v0[3];
float v3[3];
float v7[3];
}
asm
{
vs.1.1
m3x3 r0,v3,c4
dp3 r0,r0,-c19
mul r0,r0,c94.x
mov r1,c94.y
mul r1,r1,c17.x
add oD0,r0,r1
mov r0,v0
mov r1,c16
mul r1,r1.x,c17.x
mul r1,r1,v3
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
mov oT0,v7
mul oT1.xy,v7.xy,c16.zw
mov r1.w,c20.w
dp4 r0,v0,c10
add r0,r0,-c20.x
mad r0.x,-r0.x,c20.z,r1.w
max oFog.x,r0.x,c95.w
};
pixelShader=
asm
{
ps.1.1
tex t0
tex t1
mov r0.rgb,t0
+mov r0.a,t1.a
mul_x2 r0.rgb,r0,v0
};
}
}
technique fallback { pass p0 { } }
";
}
action fur
{
my.skill41=float(0.16); // shell_distance
my.skill43=float(12); // fur_u_scale
my.skill44=float(12); // fur_v_scale
my.material=mtl_fur;
}

