dot3 bumpmapping example - please help

Posted By: ello

dot3 bumpmapping example - please help - 09/17/03 03:40

i added the example script of the readbeta.txt to an entity, but the only thing i recognize is that the surface gets somehow shiny.
is this because of my geforce2 and still with my new radeon9600?

here is the code:
Code:

bmap reptile = <noise64.tga>;

material mat_bump
{
skin2 = reptile; // set a reptile skin
scale1 = 0.2; // factor for the skin scale at stage 0

// define a material effect
effect = "

// declare the used textures and variables
texture texSkin1; // the entity skin
texture mtlSkin2; // the bump map
dword mtlSkill1; // the light vector

// default technique
technique bump_dot3
{
pass P0
{
// set texture stage states
Texture[0] = <mtlSkin2>;
Texture[1] = <texSkin1>;
TextureFactor = <mtlSkill1>;

ColorArg1[0] = Texture; // stage 0 = bumpmap
ColorOp[0] = DotProduct3;
ColorArg2[0] = TFactor;

ColorArg1[1] = Texture; // stage 1 - skin texture
ColorOp[1] = AddSigned;
ColorArg2[1] = Current;

ColorArg1[2] = Diffuse; // stage 2 - lighting
ColorOp[2] = Modulate2x;
ColorArg2[2] = Current;
}
}

// fallback technique for devices that do not support bumpmapping
technique fallback
{
pass P0
{
// set texture stage states
Texture[0] = <texSkin1>;

ColorArg1[0] = Texture; // stage 0 = skin texture
ColorOp[0] = Modulate2x;
ColorArg2[0] = Diffuse; // modulate by lighting
}
}


"; //end of the effect string
}

starter mat_bump_init {
// initialize the material properties
vec_set(mat_bump.ambient_blue,mat_model.ambient_blue);
vec_set(mat_bump.diffuse_blue,mat_model.diffuse_blue);
vec_set(mat_bump.specular_blue,mat_model.specular_blue);
mat_bump.power = mat_model.power;
// create the normals map for DOT3 bumpmapping
bmap_to_normals(mat_bump.skin2,2);
// set a lighting vector for DOT3 bumpmapping
mat_bump.skill1 = pixel_for_vec(vector(200,200,200),100,8888);
}

entity* test;
action test_it {
test=me;
my.material=mat_bump;
my.skill1=sign(random(2)-1);
my.skill2=sign(random(2)-1);
my.skill3=sign(random(2)-1);
while(1) {
my.pan+=my.skill1;
my.tilt+=my.skill2;
my.roll+=my.skill3;
wait(1);
}
}
entity* kamera;
action player_light {
kamera=me;
my.invisible=on;
my.passable=on;
my.lightrange=230;

while(1) {
vec_set(my.x,camera.x);
vec_set(my.pan,camera.pan);
wait(1);
}
}


Posted By: napo

Re: dot3 bumpmapping example - 09/17/03 03:49

I dont think the GeForce 2 supports 3 Textures, so I think the fallback technique will be used.

If it's too shiny, maybe it's because of the power of the material is too small (the less power, the more specular reflection ).

BTW: For 2 pass Dot3 Bumpmapping you should render the bumpmap and the diffuse color in one pass, and then the skin with alpha blending for simulating the "addsigned" Colorarg. You can also render bumpmap and skin in the first pass and then in a second pass diffuse color, but I think it's worst.
Posted By: ello

Re: dot3 bumpmapping example - 09/17/03 04:18

thanx for the explanation.
i think the days of my geforce2 will be over very soon..
Posted By: jcl

Re: dot3 bumpmapping example - 09/17/03 06:20

I believe Geforce2 supports 3 stages and 2 textures. You can check this with the Caps Viewer. But I suppose that it does not support Dot3 bumpmapping. It probably supports only normal bumpmapping, with texture coordinate displacement.
Posted By: ello

Re: dot3 bumpmapping example - 09/21/03 02:41

today i got my radeon9600pro and the firt thing was to try the script above. but i still don't see any bumpmapping. there is only small difference with the lighting. am i doing something wrong or did i missed something. i have directx9.0 installed which came with the drivercd for the radeon.


Posted By: ventilator

Re: dot3 bumpmapping example - 09/21/03 03:57

maybe your bumpmap isn't intense enough? you could try to experiment with the scale1 and the bmap_to_normals amplification value... the standard bumpmap effect isn't that spectacular though!
Posted By: ello

Re: dot3 bumpmapping example - 09/21/03 22:09

i tried many different images now for the bumpmap, only black and whites , blurred boise and i tried them as 8 bit bmp or 24bit tga, i tried different scales (0.1 .. 100) and the same on bmap_to_normals. i tried map-entities and mdl-entities. i am getting no error and no bumpmapping.
there was no noticable difference at all.

i tried 3dmark 2003 and it worked fine, though i think my new graphicscard should support the bumpmapping.

is there something wrong with my update, or do i have to toggle any specific mode of a6?
how did you guys get it to work. as i saw on some screenshots it does work.

please help me on this one.
Posted By: jcl

Re: dot3 bumpmapping example - 09/23/03 09:24

I don't have a Radeon8600 right here, but this is the beta bumpmapping example on the Radeon8500:



with the emboss1.tga from the DirectX SDK as bumpmap.

Radeon8600 supports bumpmapping, so it must work on your system also. Check whether you're running in A6 mode - effect scripts are not supported in A5 mode.
Posted By: ello

Re: dot3 bumpmapping example - 09/23/03 15:31

it shows a6 in the upper right corner. so i think its the right mode. i have tried everything now and i dont get bumpmapping. i dont know what to do, i am absolutely frustrated about this. thought i could have some fun with shader programming and now this.
Posted By: ello

Re: dot3 bumpmapping example - 09/24/03 15:19

does anybody have a clue what is going on here?
I tried different textures, different standardmodels.
does it work fine for the rest of you all?
Posted By: ventilator

Re: dot3 bumpmapping example - 09/24/03 18:16

have you tried any other effect like environment mapping?

try this:
Code:
bmap cubemap=<skycube2.tga>;

material mat_cubemap
{
skin1=cubemap;
effect=
"
texture mtlSkin1;
texture texSkin1;
technique cubic_environment
{
pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<mtlSkin1>;

ColorArg1[0]=Texture;
ColorOp[0]=Modulate2x;
ColorArg2[0]=Diffuse;

ColorArg1[1]=Texture;
ColorOp[1]=AddSigned;
ColorArg2[1]=Current;

AddressU[1]=Clamp;
AddressV[1]=Clamp;
AddressW[1]=Clamp;
TexCoordIndex[1]=CameraSpaceReflectionVector;
TextureTransformFlags[1]=Count3;
}
}
";
}


...there is no function to convert a bitmap to a cubemap yet. your model will reflect skycube2.tga but the reflection won't look correct...
Posted By: ello

Re: dot3 bumpmapping example - 09/24/03 18:24

thx, i'll give it a try when i'm back home and then i'll tell you what happens.
Posted By: ello

Re: dot3 bumpmapping example - 09/25/03 02:44

yes, now it works(strange look, as you mentioned, but it works). i dont know why, but after i tried your code the bumpmapping works,too. only thing i changed was that i now use .bmp files. could it be that my radeon card does not like tga-files?



Posted By: ventilator

Re: dot3 bumpmapping example - 09/25/03 02:46

it should also work with tgas! maybe it's a bug?
Posted By: jcl

Re: dot3 bumpmapping example - 09/25/03 03:59

24 bit TGAs are ok for bumpmapping. The image file format does not depend on the 3D card.
Posted By: lucidman

Re: dot3 bumpmapping example - 09/25/03 08:12

The image shows Beta V6.11.3. Is this the latest beta? Where can I get It?

Thanks...
Posted By: Drew

Re: dot3 bumpmapping example - 10/24/03 18:03

JCL- How did you get both textures to show?
When I use the beta bump code, only the bump shows up...plus the effect doesn't ssem to work, looks like a bump map looking texture apllied normally...no change in lighting across the raised areas...
Thanks
Posted By: BionicHero

Re: dot3 bumpmapping example - 10/24/03 18:08

Bump mapping (and maybe other effects too) don't work in the latest beta how they are supposed to because of a bug that inverts model normals.
Posted By: Drew

Re: dot3 bumpmapping example - 10/24/03 18:20

bummer..thanks for the info
Posted By: ventilator

Re: dot3 bumpmapping example - 10/25/03 07:14

you could try this diffuse per pixel lighting shader.

the first texture of the model has to be the color map, the second one the bumpmap. instead of converting the bumpmap to a normalmap within the engine you could also use a normalmap directly. then you don't need the bmap_to_normals line. there are plugins for photoshop and the gimp at the nvidia website which can convert bumpmaps to normalmaps. you could also generate normalmaps out of a high poly version of the model. ati provides a tool for that...

i think because of the normal vector bug in the current beta, the light (from the sun) seems to come from strange directions. but that could also be caused by a faulty shader, it's hard to say. i think i will wait for the next beta with correct normals before i do more shader experiments...

Code:

action myentity
{
bmap_to_normals(bmap_for_entity(my,1),16); // convert the bumpmap to a normalmap with scale factor 16
my.material=mat_diffuseperpixel;
...
}

material mat_diffuseperpixel
{
flags=tangent;
effect=
"
texture texSkin1;
texture texSkin2;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSunDir;
vector vecFog;

technique diffuseperpixel
{
pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<texSkin2>;

VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
VertexShaderConstant[8]=<matWorldView>;
VertexShaderConstant[16]=<vecSunDir>;
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

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 base color
};
}
}
";
}


Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/25/03 16:43

hey this is nifty code!
one question..
how would you set it to get light vecs from static and dyamic lights.. if you have multiple lights would you have it always use the vec from the closest light?
anyway great code.. i was working with diffuse+spec lighting but having major trouble.. this is a step in the right direction ..
Posted By: ventilator

Re: dot3 bumpmapping example - 10/25/03 22:18

Quote:

how would you set it to get light vecs from static and dyamic lights.. if you have multiple lights would you have it always use the vec from the closest light?




i think currently you would have to find the nearest light in the entity's action and pass its position (or direction) to the shader with skill41. if you pass the light's position you would also have to change the shader from using a directional light source (the sun) to a point light source but that isn't difficult.

i think the new light management which is planned by conitec will make light handling a lot easier and more convenient.

shaders often use more than one light source and at the moment this would be tricky because there aren't enough skills to pass several light positions over to the shader...
Posted By: Drew

Re: dot3 bumpmapping example - 10/26/03 06:29

ventilator- very cool code... the textures seem inverted now, negative... any ideas?
thanks!!!
Posted By: ventilator

Re: dot3 bumpmapping example - 10/26/03 06:47

maybe you applied the textures to your model in the wrong order? it could look strange if the colormap gets converted to a normalmap!
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 06:48

I had that problem.. remeber to setup your starter funtion for the material.. and also it is better to make the normalmap yourself with a conversion program.. ATI has such tools on their website..

additional questions for Ventilator..
how do you convert the lighting model to use point lights?
also, can you pass light rgb values?
finally, im trying to setup the shader to use a specific normal map for each entity type.. im having trouble with this becasue i cant use bmap_for_entity in the skin declaration.. i cant see any other way to specify variable skins..
Posted By: ventilator

Re: dot3 bumpmapping example - 10/26/03 07:40

how do you convert the lighting model to use point lights?
in your entity action you pass the position of the light to the shader:

my.skill41=float(lightpos.x);
my.skill42=float(lightpos.y);
my.skill43=float(lightpos.z);
my.skill44=float(1);

instead of sundir you have to define vecSkill41 as a constant in the shader:

VertexShaderConstant[16]=<vecSkill41>;

then you have to calculate the light direction for each vertex:

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

...
i haven't really tested this though...

also, can you pass light rgb values?
yes, sure! you could use the material diffuse, ambient, specular colors (which are accessible through vecdiffuse,...) as light colors in the shader. alternatively entity or material skills could be used to pass the color information.

finally, im trying to setup the shader to use a specific normal map for each entity type.. im having trouble with this becasue i cant use bmap_for_entity in the skin declaration.. i cant see any other way to specify variable skins..
bumpmaps can be specified per model or per material. in my example i did it per model and converted the bumpmap in the entity's action.

specifying the bumpmap per material works like that:

bmap b_bumpmap=<bumpmap.tga>;
material mat_diffuseperpixel
{
skin1=b_bumpmap;
...

technique diffuseperpixel
{
pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<mtlSkin1>;
...

starter mat_diffuseperpixel_init()
{
bmap_to_normals(mat_diffuseperpixel.skin1,16);
}

you have to use a starter function for bmap_to_normals then!
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 08:26

thanks a lot for response!
OK.. maybe im dumb.. :P
i dont want to use the bmap_to_normal ...
i have made already a normal map.. and i need to somehow assign normal maps per entity.. see? how in the entity action can you tell it which map to use as the normal map.. and then pass it to shader?
Posted By: ventilator

Re: dot3 bumpmapping example - 10/26/03 08:31

oh! sorry, i think i didn't understand you correctly. you want to use different normal maps for entities which all use the same model?
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 13:00

no.. i guess im not being clear.. sorry

maybe i dont understand how your script works...
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.
Posted By: Drew

Re: dot3 bumpmapping example - 10/26/03 13:25

Quote:

maybe you applied the textures to your model in the wrong order? it could look strange if the colormap gets converted to a normalmap!




hmmm... I dont know how i would do that ;p
I used the code as is... the bump is there (inverted colors), but still doesn't seem to change with motion, its based on the sun right? Its really great that your are helping with this, thank you!

Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 14:57

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
Posted By: Drew

Re: dot3 bumpmapping example - 10/26/03 15:56

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
}
}


Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 16:02

ok i had the same problem using the bmap_to_normals command. Instead.. generate a normal map from your greyscale hightmap. You can do this via a plugin or a standalone app.. check ATI website, they have a good tool. once you have the normal map then you can just use it as is.. no need to invoke bmap_to_normals..
then it should work.
Posted By: Drew

Re: dot3 bumpmapping example - 10/26/03 16:09

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?


Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 16:52

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
Posted By: Drew

Re: dot3 bumpmapping example - 10/26/03 17:06

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
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/26/03 18:09

yes sure but damned if i know :P
im waiting for ventilator to comeback so i can ask a few more questions...

like first: for rgb color of the lights.. i have no clue what to do in the assembly..
Posted By: ventilator

Re: dot3 bumpmapping example - 10/26/03 22:49

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!
Posted By: ventilator

Re: dot3 bumpmapping example - 10/26/03 22:55

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
};
}
}
";
}


Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 03:05

ahh.. ok i now i get it... i didnt realize you could add mulitple skins in med.. lol.

ok your point light code seems to work correctly. Great work vent!
Maybe could you point me in the right direction about where in the assembly you add information about light rgb values?
Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 03:23

the simplest solution would be to just add a constant for the light color in the pixelshader:

Code:

PixelShader=
asm
{
ps.1.3
def c0,0.3,0.3,0.9,1.0 // light color rgba
tex t0 // sample colormap
tex t1 // sample normalmap
dp3 r1,t1_bx2,v0_bx2 // normal . light
mul r1,r1,c0 // modulate light intensity against light color
mul r0,t0,r1 // modulate light against color(t0)
};


(i haven't tested it! instead of mul r1,r1,c0 you could also try mul_x2 r1,r1,c0 or something like that...)

if you want to pass the color from outside of the shader it gets a little more complicated. i guess then you would have to pass it first to the vertex shader and from there to the pixelshader...
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 03:55

yup thast what im trying to work on..
im trying to take vecDiffuse and use to effect the vertex shader and somehow pass it on to the pixel shader.. but i just dont understand enough to do it. I dont get how it knows where to make the light a pure white value.. and how you can change that... i assume you have to put a "mul r0,-r0,c[vecdiffuse]" or something
Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 04:43

in the vertexshader you have to define vecdiffuse:
VertexShaderConstant[18]=<vecDiffuse>;

you can output vecdiffuse to oD1 in the vertexshader:
mov oD1,c18

and access it with v1 in the pixelshader:
mul_x2 r1,r1,v1 // modulate light intensity against vecdiffuse
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 05:17

for some reason i cant get vecdiffuse to pass the rgb values..
however.. you can use vecLight.. that does it

thnx a lot for yor help vent..

now im going to try to add a specular component..
Posted By: Drew

Re: dot3 bumpmapping example - 10/27/03 09:51

can you describe how you assign multiple skins in Med?
I opened my model, with standard color map...then open skins, import dot3 skin and add the skin after the first...is that close?

Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 10:05

yes, close!

if you open med's skin editor you should see your color map.

then do the following:

1. edit -> add new skin -> after last skin
2. switch to the second skin with the <next skin> icon
3. import your normalmap - it doesn't matter if you adapt the skin vertices or not
4. edit -> convert skin -> add mipmaps
5. save your model

normally information about which texture you are currently looking at should be visible in the statusbar. but there is a bug in the current version of med...
Posted By: Drew

Re: dot3 bumpmapping example - 10/27/03 10:18

excellent, thanks. works great! very bumpy

Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 10:18

screenshot please!
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 10:19

hey vent.. anotehr question
currently the shader doesnt respond to dynamic lights.. do you know how to add that? also you have any iea why veclight works but vec diffuse doesnt?
Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 10:25

currently the shader doesnt respond to dynamic lights.. do you know how to add that? also you have any iea why veclight works but vec diffuse doesnt?

vecdiffuse probably is 0 0 0 0 by default?

you have to find the nearest dynamic light yourself in your entity action and pass it as skill41. i guess the upcoming <new light management> will handle this a lot more convenient...
Posted By: Drew

Re: dot3 bumpmapping example - 10/27/03 10:31

crappy model, but you get the point...obviously looks right when its in motion...


Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 10:33

oh! a zombie! shouldn't the black parts be transparent? maybe the pixelshader needs some additions to handle that correctly...
Posted By: Drew

Re: dot3 bumpmapping example - 10/27/03 10:35

whoa...try turning on 'overlay' with this shader...sorta works... black 0,0,0 is alpha , plus the texture tends to go transparent in all the wrong places...
Thats ok, i dont need it for now, and I undertand this is a sort of hack until the bug is fixed...


Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 10:37

transparency isn't affected by the model normals bug. have you seen my overlay thread? -> http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=297998&page=0&view=collapsed&sb=5&o=&fpart=1 overlays work much better now with pixelshaders. no black borders anymore. the overlay shader could be combined with this one...
Posted By: Drew

Re: dot3 bumpmapping example - 10/27/03 10:49

hmmmm.... i tried but didn't work due to my limited knowledge of shaders...

Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 10:56

how do you actually ind a dynamic light?my nearest light function only seems to respond to statics..
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 ;
}
}



does this seem right? i am supposing that you cant find a dynamic light with scan_entity..but then how?

Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 11:01

hmmmm.... i tried but didn't work due to my limited knowledge of shaders...

pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<texSkin2>;

ZWriteEnable=true; // add these three lines
AlphaTestEnable=true;
CullMode=none;
...

PixelShader=
asm
{
ps.1.3
def c0,1,1,1,1
def c1,0,0,0,0
tex t0 // sample colormap
tex t1 // sample normalmap
mov r0,t0
cnd r0.a,r0.a,c0,c1
dp3 r1,t1_bx2,v0_bx2 // normal . light
mul r0.rgb,t0,r1
};

the transparency gets controlled with the alpha channel of the colormap. all alpha values less then 0.5 will be completely transparent and all values above 0.5 will be completely opaque. you have to experiment a little with the alphachannel to get the hang of it, but it works much better than normal overlays!
Posted By: ventilator

Re: dot3 bumpmapping example - 10/27/03 11:11

@matt: your function seems to make sense. i don't have the time at the moment to test this myself though!
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 11:16

k.. one thing tho.. i dont think im calling it in the right place.. im trying to use this on actor_walk_fight action.. where do you think would be the best place to call it
Posted By: ventilator

Re: dot3 bumpmapping example *DELETED* - 10/27/03 11:20

Post deleted by jcl

?
Posted By: Matt_Aufderheide

Re: dot3 bumpmapping example - 10/27/03 12:12

well i've determined that my function doesnt work correctly.. it seems to just return all the entities instead of just the first one it finds
Posted By: jcl

Re: dot3 bumpmapping example - 10/28/03 00:49

The model normals bug can be worked around by setting an intermediate frame, like 1.5.
© 2024 lite-C Forums