Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 2
Page 1 of 3 1 2 3
Fully working diffuse specular point lighting!! #20281
11/23/03 13:55
11/23/03 13:55
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
OK after a great deal of struggle i have completed a 2-pass diff+spec point light shader, complete with skill-based light positions and colors, attenuation maps, corrected blinn specular, and diffuse/spec gradation map. I have made some changes from the Wolfgang Engle version..but you will need the diffspec and pointlight maps from his RacorX10 example. The only improvement currently needed is a way to pass in multiple light sources at once.. so we can blend lights together.. as of now i have no idea how to do this, but i will work on it.. any input would be appreciated. The shader is ready now for most needs however..try constructing your entire worlds out of models, using planes for floor, cieling walls.. etc.. you will see how impressive this kind of lighting can be.

here is the shader:
Code:
bmap pointlight = <pointlight.tga>;
bmap diffspec = <diffspec.tga>;

material mat_diffspecpoint
{
skin1 = pointlight;
skin2 = diffspec;
event = mat_diffspecpoint_init;

flags = tangent;
effect =
"
texture mtlSkin1; //attenuation map
texture mtlSkin2; //diffspec map
texture entSkin1;
texture entSkin2;
matrix matWorldViewProj;
matrix matWorld;
vector vecViewPos;
vector vecSkill41; //light position
vector mtlSkill1; //light color

technique specpoint
{
pass p0
{

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

//light vector
VertexShaderConstant[12] = <vecSkill41>;


//Camera Information
VertexShaderConstant[16] = <vecViewPos>;

//range constant
VertexShaderConstant[33] = (0.005f, 0.55f, 0.0f, 0.0f);

//light color
VertexShaderConstant[40] = <mtlSkill1>;


Texture[0] = <mtlSkin1>; //pointlight attenuation
Texture[1] = <mtlSkin1>; //pointlight alpha

AddressU[0] = Clamp; // don't wrap around edges
AddressV[0] = Clamp;
AddressU[1] = Clamp; // don't wrap around edges
AddressV[1] = Clamp;

zWriteEnable=true; // enables writing to the z-buffer
AlphaBlendEnable=false; // disables alpha blending

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

; position in clip space
m4x4 oPos, v0, c8

; position in world space
m4x4 r2, v0, c0

; get light vector
add r10, r2, -c12

; Divide each component by the range value
mul r10, r10, c33.x

; multiply with 0.5 and add 0.5
mad r10, r10, c33.yyyy, c33.yyyy

; map the x and y components into the first texture
mov oT0.xy, r10.xy

; z-component v0
mov oT1.x, r10.z


};

PixelShader=
asm
{

ps.1.1

tex t0
tex t1
add r0, 1-t0, -t1.a

};
}


pass p1
{

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

//light vector
VertexShaderConstant[12] = <vecSkill41>;

//Camera Information
VertexShaderConstant[16] = <vecViewPos>;

//range constant
VertexShaderConstant[33] = (1.05f, 0.5f, 0f, 0.0f);

//light color
VertexShaderConstant[40] = <mtlSkill1>;

Texture[0] = <entSkin1>;
Texture[1] = <entSkin2>;
Texture[3] = <mtlSkin2>;

AddressU[3] = Clamp; // don't wrap around edges
AddressV[3] = Clamp;

zWriteEnable=true; // enables writing to the z-buffer
AlphaBlendEnable=true; // enable alpha blending

SrcBlend = zero;
DestBlend = SrcColor;

VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
float v8[3]; //tangent

}
asm
{
vs.1.1
; position in clip space
m4x4 oPos, v0, c8

m3x3 r3, v8, c0 ; generate tangent U
m3x3 r5, v3, c0 ; generate normal W

; Cross product
; generate binormal V
mul r0, -r3.zxyw, r5.yzxw ;
mad r4, -r3.yzxw, r5.zxyw,-r0 ;

; position in world space
m4x4 r2, v0, c0

; get light vector
add r10, r2, -c12

; normalize light vector
; always first normalize than transform
dp3 r11.x, r10.xyz, r10.xyz
rsq r11.xyz, r11.x
mul r10.xyz, r10.xyz, r11.xyz

;transform the light vector with U, V, W
dp3 oT2.x, r3, -r10
dp3 oT2.y, r4, -r10
dp3 oT2.z, r5, -r10

;position in world space
m4x4 r6, v0, c0

; get a vector toward the camera/eye V
add r6, r6, -c16

; normalize eye vector V
dp3 r8.x, r6.xyz, r6.xyz
rsq r8.xyz, r8.x
mul r6.xyz, r6.xyz, r8.xyz

add r6, r6, r10 ;
mul r6,r6,c33.y ;V+L / 2 --half vector

; normalize half angle
dp3 r8.x, r6.xyz, r6.xyz
rsq r8.xyz, r8.x
mul r6.xyz, r6.xyz, r8.xyz

//raise the specular power
mul r6, r6, c33.x

; transform the half angle vector into texture space
dp3 oT3.x,r3,-r6
dp3 oT3.y,r4,-r6
dp3 oT3.z,r5,-r6

;output uvs
mov oT0.xy, v7.xy
mov oT1.xy, v7.xy

;output light color
mov oD0,c40

};

PixelShader=
asm
{
ps.1.1

tex t0 ; color map in t0.rgb + specular map in t0.a
tex t1 ; normal map
texm3x2pad t2, t1_bx2 ; u = t1 dot (t2) light vector
texm3x2tex t3, t1_bx2 ; v = t1 dot (t3) half vector
; fetch texture 4 at u, v
; t3.rgb = (N dot L)
; t3.a = (N dot H)^16

; r0 = (diffuse * color) + ((N dot H)^16 * specular value)
mul r1.rgb, t3, t0 ; (N dot L) * base texture
+mul_x4 r1.a, t0.a, t3.a ; (N dot H)^16 * specular value
add r0, r1.a, r1

mul_x4 r0,r0,v0 ; modulate against light color

};
}

}
";
}



and here is the entity action i use to pass light data.. note that currently you cant pass light positions objects in the map... but i am working on that..
also note that if you use this shader on everything and make your world out of models/terrains, you have no need at all of WED light entities, and thus the 8-light limit isnt a problem!

Code:
ACTION worldmodel
{
MY.passable=OFF;
MY.shadow=ON;
my.flare=off;
my.transparent=off;

my.skill41=float(-320); //x
my.skill42=float(32); //z
my.skill43=float(-224); //y
my.skill44=float(1);

my.skill51=100; //R
my.skill52=100; //G
my.skill53=100; //B

mat_diffspecpoint.skill1 = pixel_for_vec(vector(my.skill53,my.skill52,my.skill51),100,8888);

MY.material= mat_diffspecpoint;

}




Sphere Engine--the premier A6 graphics plugin.
Re: Fully working diffuse specular point lighting!! [Re: Matt_Aufderheide] #20282
11/23/03 15:44
11/23/03 15:44
Joined: Aug 2003
Posts: 378
Marion,N.C. USA
Whisper Offline
Senior Member
Whisper  Offline
Senior Member

Joined: Aug 2003
Posts: 378
Marion,N.C. USA
i feel sure you had set up and event for your revised code.
doesn't work for me until i remove, the following..

event = mat_diffspecpoint_init;

other than that part of the code line it works.

Re: Fully working diffuse specular point lighting!! [Re: Whisper] #20283
11/24/03 01:45
11/24/03 01:45
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
good job! thanks for sharing it! ...could you post a screenshot of the shader in action? i have no time to try it at the moment.

Re: Fully working diffuse specular point lighting!! [Re: ventilator] #20284
11/25/03 03:01
11/25/03 03:01
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
sounds great! cna you better describe what it does and the maps needed? also, do you have a quick screenshot?
thanks for sharing, looking forward to trying it!!



Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: Fully working diffuse specular point lighting!! [Re: Matt_Aufderheide] #20285
11/25/03 10:10
11/25/03 10:10

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Wow! How long does it take to write a code?

I can't wait to get my feet wet in Managed DirectX 9 using C# when I get into college but I'm stuck with GED for now. I do know that Conitec won't have plans to support C# for SDK...

Re: Fully working diffuse specular point lighting!! [Re: Matt_Aufderheide] #20286
12/19/03 10:08
12/19/03 10:08
Joined: Dec 2003
Posts: 118
zero Offline
Member
zero  Offline
Member

Joined: Dec 2003
Posts: 118
its not working???? i mean no errors but i put it on a mdl and it wont do anything? i had to take snap shots of the dds to make a tga??? that it?

Re: Fully working diffuse specular point lighting!! [Re: Matt_Aufderheide] #20287
12/19/03 11:04
12/19/03 11:04
Joined: Sep 2003
Posts: 3,236
San Diego, CA
M
Marco_Grubert Offline
Expert
Marco_Grubert  Offline
Expert
M

Joined: Sep 2003
Posts: 3,236
San Diego, CA
I'll look at the ShaderX code, but I am surprised that you would need maps at all. Isn't this regular Phong shading?

Re: Fully working diffuse specular point lighting!! [Re: Marco_Grubert] #20288
12/19/03 12:21
12/19/03 12:21
Joined: Dec 2003
Posts: 118
zero Offline
Member
zero  Offline
Member

Joined: Dec 2003
Posts: 118
well Marco care to help me otu with the right code :-) plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz heheheh thanks

Re: Fully working diffuse specular point lighting!! [Re: zero] #20289
12/19/03 12:23
12/19/03 12:23
Joined: Dec 2003
Posts: 118
zero Offline
Member
zero  Offline
Member

Joined: Dec 2003
Posts: 118
mabe u can tell me... im really not sure how to asign a shader to an action with out sumthing like MY.material= mat_diffspecpoint; otherwise what do u have to asign

Re: Fully working diffuse specular point lighting!! [Re: zero] #20290
12/19/03 12:43
12/19/03 12:43
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
the code i have posted is correct. It is however not just regular phong shading.. it is point light diff+spec phong/blinn shading.. that means you need first a point light attenuation map and its alpha, an illumination map and its alpha for specular, a normal map for the model as entskin2, and also a specular map in the entskin1 alpha. As i asaid download the RacorX files and take the DDS files there and then import them into photoshop.. to do this you need a DDS importer.. there are several available.. try the nvidia developer website...
assaign the material as you said.. my.material = mat_pointdiffspec;




Sphere Engine--the premier A6 graphics plugin.
Page 1 of 3 1 2 3

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