Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (fogman, Grant, AndrewAMD, juanex), 989 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Specular lighting shader #18976
10/29/03 09:08
10/29/03 09:08
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
Here is a specular lighting shader..right now it doesnt include fog.. and the ambient light is hardcoded in the pixel shader.. maybe someone can improve it:

Code:
material mat_specular

{

flags = tangent;
effect =
"
texture texSkin1;
texture texSkin2;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSkill41;
vector vecFog;
vector vecLight;
vector vecDiffuse;
vector vecAmbient;
vector vecSpecular;

technique specular
{
pass p0
{

//load matrices
VertexShaderConstant[0] = <matWorld>; //World Matrix
VertexShaderConstant[4] = <matWorldViewProj>; //World*View*Proj Matrix

//Material properties of object
VertexShaderConstant[9] = <vecLight>; //Diffuse
VertexShaderConstant[16] = <vecSkill41>; //Light Direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);

//Camera Information
VertexShaderConstant[24] = <matWorldView>;


Texture[0] = <texSkin1>;
Texture[1] = <texSkin2>;


VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
float v8[3]; //tangent
}
asm
{
vs.1.1
//tranform position
m4x4 oPos,v0,c4

mov oT0,v7 // output uvs
mov oT1,v7 // output uvs

mov oD0,c9 //output light color

//tsb generation
m3x3 r3,v8,c0 //gen normal
m3x3 r5,v3,c0 //gen tangent

//gen binormal via Cross product
mul r0,-r3.zxyw,r5.yzxw;
mad r4,-r3.yzxw,r5.zxyw,-r0;

//specular
m4x4 r2,v0,c24 //transform position

//get a vector toward the camera
add r2,-r2,c24

dp3 r11.x, r2.xyz,r2.xyz //load the square into r11
rsq r11.xyz,r11.x //get the inverse of the square
mul r2.xyz, r2.xyz,r11.xyz //multiply, r0 = -(camera vector)

add r2.xyz,r2.xyz,-c16 //get half angle

//normalize
dp3 r11.x,r2.xyz,r2.xyz //load the square into r1
rsq r11.xyz,r11.x //get the inverse of the square
mul r2.xyz,r2.xyz,r11.xyz //multiply, r2 = HalfAngle

//transform the half angle vector
dp3 r8.x,r3,r2
dp3 r8.y,r4,r2
dp3 r8.z,r5,r2

//half-angle in oD1
mad oD1.xyz,r8.xyz,c20,c20 //mutiply by a half to bias, then add half


};

PixelShader=
asm
{

ps.1.1
def c0,0.1f,0.1f,0.1f,0.1f //ambient value
tex t0 //sample base map
tex t1 //sample normal
dp3 r0,t1_bx2,v1_bx2; //dot(normal,half)

mul r1,r0,r0; //raise it to 32nd power
mul r0,r1,r1;

mul_x4 r1,r1,v0 // modulate light intensity against light color
add r1,r1,c0 //add light

//assemble final color
mul r0,t0,r1

};
}
}
";
}



Last edited by Matt_Aufderheide; 10/31/03 18:45.

Sphere Engine--the premier A6 graphics plugin.
Re: Specular lighting shader [Re: Matt_Aufderheide] #18977
10/29/03 09:11
10/29/03 09:11
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
(edit)
Thats excellent! Adds a great metallic look to my bumpmaps, Thank you for sharing!!!


Last edited by Drew____Dr_Jelly; 10/29/03 14:41.

Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: Specular lighting shader [Re: Drew] #18978
10/31/03 18:47
10/31/03 18:47
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
i made an error :P

i didnt transform the specualr vvalue to right matrix.. anyway i fixed it in the edited post.. the upshot is now the highlights will move a bit as you move around the camera.. like real highlights


Sphere Engine--the premier A6 graphics plugin.
Re: Specular lighting shader [Re: Matt_Aufderheide] #18979
10/31/03 19:19
10/31/03 19:19
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
looks fantastic! The highlight is much stronger , and the bump seems much better...Thanks!!!


Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: Specular lighting shader [Re: Matt_Aufderheide] #18980
11/02/03 20:56
11/02/03 20:56
Joined: Aug 2003
Posts: 2,122
Berlin, Germany
checkbutton Offline

Expert
checkbutton  Offline

Expert

Joined: Aug 2003
Posts: 2,122
Berlin, Germany
Can you please post a Screenshot? As I'm not a beta-tester, and even don't own the A6, I can't test it myself.



I don't have a homepage, for god's sake!
Re: Specular lighting shader [Re: checkbutton] #18981
11/05/03 11:56
11/05/03 11:56
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
doesn't seem to work in the latest beta 6.12.7
maybe its because they fixed the bug?



Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: Specular lighting shader [Re: Drew] #18982
11/05/03 12:07
11/05/03 12:07
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
hrrmm.. works for me ... however you may to have to invoke mtl.enable_render = on; in the init function. otehr than that.. i dunno
the shader code is unrelated to the model bug.. so i cant see how it would be affected ..

oh you may need to set the frame number in the action you use to assign the material.. for some reason if i dont set the frame number ..like my.frame=1or something.. the material wont intialize soemtimes..this wont be a problem on a normally animated model.. but on a static model this could happen

Last edited by Matt_Aufderheide; 11/05/03 12:08.

Sphere Engine--the premier A6 graphics plugin.
Re: Specular lighting shader [Re: Matt_Aufderheide] #18983
11/05/03 12:36
11/05/03 12:36
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
ARGHHH..im sorry, I was using some old script or something.
Plus Its a new level, outdoorsm, so I didnt have a light near the object...
works good...



Last edited by Drew__Dr_Jelly; 11/05/03 12:42.

Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1