1 registered members (Akow),
1,361
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: dot3 bumpmapping example
[Re: Drew]
#16973
10/26/03 14:57
10/26/03 14:57
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
Expert
|
Expert
Joined: Oct 2003
Posts: 4,131
|
ok here is my shader code so far: Code:
material mat_diffuseperpixel { skin2 = zombiebump; flags = tangent; effect = " texture texSkin1; texture texSkin2; matrix matWorldViewProj; matrix matWorld; matrix matWorldView; vector vecSkill41; vector vecFog; technique diffuseperpixel { pass p0 { Texture[0]=<texSkin1>; Texture[1]=<texSkin2>;
VertexShaderConstant[0]=<matWorldViewProj>; VertexShaderConstant[4]=<matWorld>; VertexShaderConstant[8]=<matWorldView>; VertexShaderConstant[16]=<vecSkill41>; VertexShaderConstant[17]=<vecFog>; VertexShaderConstant[95]=(0.5f,0.0f,0.0f,0.0f);
VertexShader= decl { stream 0; float v0[3]; //position float v3[3]; //normal float v7[3]; //uv float v8[3]; //tangent } asm { vs.1.1 m4x4 oPos,v0,c0 mov oT0,v7 mov oT1,v7
m3x3 r5,v8,c4 // transform tangent to world space m3x3 r7,v3,c4 // transform normal to world space
mul r0,r5.zxyw,-r7.yzxw // tangent x normal -> binormal mad r6,r5.yzxw,-r7.zxyw,-r0 // dp3 r8.x,r5,-c16 // transform light vector to texture space // dp3 r8.y,r6,-c16 // dp3 r8.z,r7,-c16 // mad oD0.xyz,r8.xyz,c95.x,c95.x //new code for point lights m4x4 r10,v0,c4 // transform position to world space sub r10,v0,c16 // lightdir=vertexpos-lightpos dp3 r10.w,r10,r10 // renormalize it rsq r10.w,r10.w mul r10,r10,r10.w
dp3 r8.x,r5,r10 // transform light vector to texture space dp3 r8.y,r6,r10 dp3 r8.z,r7,r10 mad oD0.xyz,r8.xyz,c95.x,c95.x
mov r1.w,c17.w // r1.w=1 dp4 r0,v0,c10 // distance to camera position add r0,r0,-c17.x // distance-fog_start mad r0.x,-r0.x,c17.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.3 tex t0 // sample colormap tex t1 // sample normalmap dp3_sat r1,t1_bx2,v0_bx2 // normal . light mul r0,t0,r1 // modulate against base color }; } } "; } here is the function i use to get the ight positions: Code:
function find_nearest_light()
{ temp.pan =360; temp.tilt=360; temp.z=3000; you=scan_entity(my.x,temp); if your.light==ON { temp.x = your.x; temp.y = your.y; temp.z = your.z; my.skill41=float(temp.x); my.skill42=float(temp.y); my.skill43=float(temp.z); my.skill44=float(1); return ; } } its does appear to work.. buts it difficult to tell exactly.. i cant tell if its getting the light positions always.. or if it just samples it once.. or if my nearest light code just alwasy returns 0 for everything.. which of course would make the light source always 0,0,0 ..sigh im not a programmer.. just artist.. im trying to muddle through tho
|
|
|
Re: dot3 bumpmapping example
[Re: Matt_Aufderheide]
#16974
10/26/03 15:56
10/26/03 15:56
|
Joined: Jan 2002
Posts: 1,276 trapped in a paper bag
Drew
Serious User
|
Serious User
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
|
seems to be working...maybe you can help me with a problem... my texture is like this:
here is the code i'm using...just this applied as an action.
EDIT!: I replaced this code with the fixed version.
Code:
//Matt_Aufderheide's modified ventilator shader
//Important! generate a normal map from your greyscale hightmap. You can do this via ATI's "TGAtoDOT3" tool
// it uses the models regular map as a clor map and the normal map as a bump
//here is the function i use to get the ight positions:
bmap zombiebump=<bumpmapDOT3.tga>;//normal map
function find_nearest_light()
{
temp.pan =360;
temp.tilt=360;
temp.z=3000;
you=scan_entity(my.x,temp);
if your.light==ON
{
temp.x = your.x;
temp.y = your.y;
temp.z = your.z;
my.skill41=float(temp.x);
my.skill42=float(temp.y);
my.skill43=float(temp.z);
my.skill44=float(1);
return ;
}
}
material mat_bumpmapping
{
skin2 = zombiebump;
flags = tangent;
effect =
"
texture texSkin1;
texture texSkin2;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSkill41;
vector vecFog;
technique bumpmapping
{
pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<texSkin2>;
VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
VertexShaderConstant[8]=<matWorldView>;
VertexShaderConstant[16]=<vecSkill41>;
VertexShaderConstant[17]=<vecFog>;
VertexShaderConstant[95]=(0.5f,0.0f,0.0f,0.0f);
VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
float v8[3]; //tangent
}
asm
{
vs.1.1
m4x4 oPos,v0,c0
mov oT0,v7
mov oT1,v7
m3x3 r5,v8,c4 // transform tangent to world space
m3x3 r7,v3,c4 // transform normal to world space
mul r0,r5.zxyw,-r7.yzxw // tangent x normal -> binormal
mad r6,r5.yzxw,-r7.zxyw,-r0
// dp3 r8.x,r5,-c16 // transform light vector to texture space
// dp3 r8.y,r6,-c16
// dp3 r8.z,r7,-c16
// mad oD0.xyz,r8.xyz,c95.x,c95.x
//new code for point lights
m4x4 r10,v0,c4 // transform position to world space
sub r10,v0,c16 // lightdir=vertexpos-lightpos
dp3 r10.w,r10,r10 // renormalize it
rsq r10.w,r10.w
mul r10,r10,r10.w
dp3 r8.x,r5,r10 // transform light vector to texture space
dp3 r8.y,r6,r10
dp3 r8.z,r7,r10
mad oD0.xyz,r8.xyz,c95.x,c95.x
mov r1.w,c17.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c17.x // distance-fog_start
mad r0.x,-r0.x,c17.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.3
tex t0 // sample colormap
tex t1 // sample normalmap
dp3_sat r1,t1_bx2,v0_bx2 // normal . light
mul r0,t0,r1 // modulate against base color
};
}
}
";
}
action Shaders_Bump
{
//bmap_to_normals(bmap_for_entity(my,10),16); //1,16 convert the bumpmap to a normal map with scale factor 16
my.material=mat_bumpmapping;
//... // causes error but leave it here
my.pan=random(360); //rotate for testing
my.tilt=random(360); //rotate for testing
my.roll=random(360); //rotate for testing
while(1) { //rotate for testing
my.pan+=sin(my.tilt)/2*time; //rotate for testing
my.tilt+=cos(my.roll)/2*time; //rotate for testing
my.roll+=sin(my.pan)/2*time; //rotate for testing
wait(1); //rotate for testing
}
}
Last edited by Dr. Jelly; 10/26/03 16:32.
|
|
|
Re: dot3 bumpmapping example
[Re: Matt_Aufderheide]
#16976
10/26/03 16:09
10/26/03 16:09
|
Joined: Jan 2002
Posts: 1,276 trapped in a paper bag
Drew
Serious User
|
Serious User
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
|
EXCELLENT!!! thanks... I use ATI's "TGAtoDOT3",
commented out the bmap_to_normals line,and replace the name of the targa being called... I edited the above code in case anyone wanted to copy&paste it without the need to edit..
works great!! seems to be a real bump map!
A good way to test is to use the object as a player, switch to orbit mode (F7), and rotate around the player. You really get to see the Skin change as the light rolls across the surface.
whats the best way to control the amount? tweaking the contrast of the texture or in code?
Last edited by Dr. Jelly; 10/26/03 17:06.
|
|
|
Re: dot3 bumpmapping example
[Re: Matt_Aufderheide]
#16978
10/26/03 17:06
10/26/03 17:06
|
Joined: Jan 2002
Posts: 1,276 trapped in a paper bag
Drew
Serious User
|
Serious User
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
|
thanks...one last question (hopefully
Is there a way to have it also react to realtime light code attached to entites? light code like this:
my.lightrange = 100; // RANGE
my.lightred = 100;// 85
my.lightgreen = 100;//22
my.lightblue = 100;//22
|
|
|
Re: dot3 bumpmapping example
[Re: Matt_Aufderheide]
#16980
10/26/03 22:49
10/26/03 22:49
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
all i want is to use different normal maps for different entities.. not differnt ones per the same models...see. maybe your script already can do that..but i dont see how. I dont want to define differetn materials for each model.. just use the same mat_diffuse. How does it know which model/skin gets which normal map?
instead of defining skin2=<wahtever.tga> as the normal map.. how do you make the shader know to use differnt normal maps .. maybe im being dense.. thank you for your patience.
my first example does exactly that. it uses the second texture (which you assigned in med) of the current model as normalmap. don't assign skin2 in the material.
Code:
action ball // the action of your entity
{
//bmap_to_normals(bmap_for_entity(my,1),16); // you don't need this line if you already generated the normalmap with an external tool
my.material=mat_diffuseperpixel;
...
}
material mat_diffuseperpixel
{
flags=tangent;
effect=
"
texture texSkin1;
texture texSkin2;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSkill41;
vector vecFog;
technique diffuseperpixel
{
pass p0
{
Texture[0]=<texSkin1>; // colormap (texture 1 of 2 in med's skin editor)
Texture[1]=<texSkin2>; // normalmap (texture 2 of 2 in med's skin editor) make sure you use a 24bit tga bitmap
.........
sub r10,v0,c16 // lightdir=vertexpos-lightpos
this line should be:
sub r10,r10,c16 // lightdir=vertexpos-lightpos
i corrected this 5 minutes after i posted the code but you were faster!
if the model space vertex position gets used, the light direction won't be correct. but in the current beta this doesn't matter much. the light direction will behave strange anyway because of the wrong normals...
the amount of the hightmapping?.. yeah eitehr contrast on the hightmap/normal map or i think there is a way to bias the dotproduct.. but i dont know the assembly
i don't think you should manipulate the normalmap in any way (for example giving it more contrast). the normalmap's normalvectors won't be well behaved (normalized) anymore. the photoshop and gimp plugins provide amplification parameters which get used when the bumpmap gets converted to a normalmap. you should do it this way. if you convert the bumpmap to normalmap with bmap_to_normals you can scale the bumps with the second parameter.
im not a programmer.. just artist..
i am more artist than programmer too!
|
|
|
Re: dot3 bumpmapping example
[Re: ventilator]
#16981
10/26/03 22:55
10/26/03 22:55
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
here is the complete shader again:
Code:
action ball // your entity's action
{
//bmap_to_normals(bmap_for_entity(my,1),16); // don't use this if you already have a normalmap
my.material=mat_diffuseperpixel;
while(1)
{
my.skill41=float(sun_pos.x); // use your own lightpos here
my.skill42=float(sun_pos.y);
my.skill43=float(sun_pos.z);
my.skill44=float(1);
wait(1);
}
...
material mat_diffuseperpixel
{
flags=tangent;
effect=
"
texture texSkin1;
texture texSkin2;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSkill41;
vector vecFog;
technique diffuseperpixel
{
pass p0
{
Texture[0]=<texSkin1>; // colormap (texture 1 of 2 in med's skin editor)
Texture[1]=<texSkin2>; // normalmap (texture 2 of 2 in med's skin editor) make sure you use a 24bit tga bitmap
VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
VertexShaderConstant[8]=<matWorldView>;
VertexShaderConstant[16]=<vecSkill41>;
VertexShaderConstant[17]=<vecFog>;
VertexShaderConstant[95]=(0.5f,0.0f,0.0f,0.0f);
VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
float v8[3]; //tangent
}
asm
{
vs.1.1
m4x4 oPos,v0,c0 // transform vertexpos to clip space
mov oT0,v7 // output uvs
mov oT1,v7 // output uvs
m3x3 r5,v8,c4 // transform tangent to world space
m3x3 r7,v3,c4 // transform normal to world space
mul r0,r5.zxyw,-r7.yzxw // tangent x normal -> binormal
mad r6,r5.yzxw,-r7.zxyw,-r0
m4x4 r10,v0,c4 // transform vertexpos to world space
sub r10,r10,c16 // lightdir=vertexpos-lightpos
dp3 r10.w,r10,r10 // renormalize it
rsq r10.w,r10.w
mul r10,r10,r10.w
dp3 r8.x,r5,r10 // transform lightdir to texture space
dp3 r8.y,r6,r10
dp3 r8.z,r7,r10
mad oD0.xyz,r8.xyz,c95.x,c95.x
mov r1.w,c17.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c17.x // distance-fog_start
mad r0.x,-r0.x,c17.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.3
tex t0 // sample colormap
tex t1 // sample normalmap
dp3 r1,t1_bx2,v0_bx2 // normal . light
mul r0,t0,r1 // modulate against color
};
}
}
";
}
|
|
|
|