Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
0 registered members (), 683 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Per-Pixel Lighting #27784
05/22/04 15:40
05/22/04 15:40
Joined: Mar 2004
Posts: 102
T
Taros Offline OP
Member
Taros  Offline OP
Member
T

Joined: Mar 2004
Posts: 102
Hi! I was trying to convert this example here.. I managed to run it but i got really weird results (sort of a void effect like it cuts out the shape of an object into game space, anyway weird.)

I probably messed up something real bad but i thought that it would only be unshaded or untextured model or something, not this

Code:
 

bmap tDiffuse = "difuse.tga";
bmap tBump = "normals.tga";
bmap tNormalizer = "normals.tga";
bmap tAtenuationXY = "AtenuationXY.bmp";
bmap tAtenuationZ = "AtenuationZ.bmp";

////////////// PHONG/BLINN SHADING /////////////////////////////////

MATERIAL mat_PHONG
{

//flags = tangent;

effect=
"

matrix matWorldViewProj;
matrix matView;

Texture tDiffuse;
Texture tBump;
Texture tNormalizer;
Texture tAtenuationXY;
Texture tAtenuationZ;


Vector vecSkill41;
Vector vecViewPos;
Vector vecSunDir;
Vector vecLight;
vector vColorLight;


Technique phong_shading
{
pass p0
{
ALPHABLENDENABLE = True;
SrcBlend = ONE;
DestBlend = ONE;
ColorWriteEnable = 0xf;

Texture[0] = <tDiffuse>;
Texture[1] = <tBump>;
Texture[2] = <tNormalizer>;
Texture[3] = <tNormalizer>;
Texture[4] = <tAtenuationXY>;
Texture[5] = <tAtenuationZ>;

AddressU[0] = Wrap;
AddressV[0] = Wrap;

AddressU[1] = Wrap;
AddressV[1] = Wrap;

AddressU[2] = Clamp;
AddressV[2] = Clamp;

AddressU[3] = Clamp;
AddressV[3] = Clamp;

AddressU[4] = Clamp;
AddressV[4] = Clamp;

AddressU[5] = Clamp;
AddressV[5] = Clamp;

VertexShaderConstant[0] = <matWorldViewProj>;
VertexShaderConstant1[8] = <vecLight>;
VertexShaderConstant1[9] = <vecLight>;//{0.0033f,0.0f,0.0f,0.0f}; // 1/lightrange tj. vScaleLight
VertexShaderConstant1[10] = <matView>;

PixelShaderConstant1[1] = <vColorLight>; // vColorLight
///////////////////////////////////////////////////////////

VertexShader =
decl
{
stream 0;
float v0[3]; //Position
float v1[2]; //Tangent
float v2[3]; //Binormal
float v3[3]; //Normal
float v4[3]; //Texcoord
}

asm
{
vs.1.1

//-------------------------------
//Constant registers
//-------------------------------
// c0-c3 - world*view*proj
// c8 - light position(In object space)
// c9 - 1 / lightRange
// c10 - vPosViewer(In object space)
def c6, 0.5, 0, 0, 0 // Helper constant
def c7, 2, -1, 0, 0 // Helper constant

//------------------------------
// Input registers
//------------------------------

// dcl_position v0
// dcl_tangent v1
// dcl_binormal v2
// dcl_normal v3
// dcl_texcoord v4
//
//------------------------------
// output position
//------------------------------
//
m4x4 oPos, v0, c0

//------------------------------
// Compute the tangent space matrix to transform from object space to tangent space
//------------------------------
//
mad r7.xyz, c7.x, v1, c7.y //bias vector tangent to (-1,1)
mad r8.xyz, c7.x, v2, c7.y //bias vector binormal to (-1,1)
mad r9.xyz, c7.x, v3, c7.y //bias vector normal to (-1,1)

//------------------------------
// Compute L vector in tangent space
//------------------------------
//
add r10, -v0, c8 // light position - vPos
dp3 r7.w, r10, r10 // Normalize (lightpostion-vPos)
rsq r7.w, r7.w
mul r11.xyz, r10, r7.w

m3x3 oT1.xyz, r11, r7 // t1 = L vector in tangent space

//------------------------------
// Compute H vector in tangent space
//------------------------------
//
add r4, -v0, c4 // V vector
add r6, r10, r4 // L + V
dp3 r6.w, r6, r6 // Normalize (L+V)
rsq r6.w, r6.w
mul r5.xyz, r6, r6.w

m3x3 oT2.xyz, r5, r7 // t2 = H vector in tangent space


//------------------------------
// output texture coordinates
//------------------------------
//
mov oT0.xy, v4 // t0 = texture coordinate


//------------------------------
// compute texture coordinates for attenuation
//------------------------------
//
mul r2.xyz, r10, c9 // (light position - vertex pos) / lightRange
mad r4.xyz, r2, c6.x, c6.x // map to 0 to 1 range

mov oT3.xy, r4 // t3 = texture coordinates for attenuation texture 1

mov oT4.x, r4.z // t4 = texture coordinates for attenuation texture 2
mov oT4.y, c6.w
};


pixelShader=
asm
{
ps.1.4

//-------------------------------
//Constant registers
//-------------------------------
// c1 - lightColor
def c0, 4.0f, 1.0f, 0.0f, -0.75f // helper constant

//------------------------------
// Load textures
//------------------------------
//
texld r0,t0 // Diffuse
texld r1,t0 // Normal
texld r2,t1 // L
texld r3,t2 // H
texld r4,t3 // attenuation texture 1
texld r5,t4 // attenuation texture 2

//------------------------------
// compute output color
//------------------------------
//
dp3_sat r2.w,r1_bx2,r3_bx2 // max(0,dot(N,H))
dp3_sat r1.rgb,r2_bx2,r1_bx2 // max(0,dot(N,L))
+mad_x4_sat r2.w,r2.w,r2.w,c0.w // specular = saturate(4*(dot(N,H)^2-0.75))
mul_sat r5.rgb,r4,r5 // attenuation = attenuation(x,y)*attenuation(z)
+mul r2.w,r2.w,r2.w // specular = specular*specular
mul_sat r0.rgb,r0,r1 // diffuse = max(0,dot(N,L))*diffuse color
+mul_x2_sat r2.w,r2.w,r1.w // specular = saturate(specular*gloss*2)
add_sat r0.rgb,r0,r2.w // color = saturate(diffuse + specular)
mul r0.rgb,r0,c1 // color = color*lightColor
mul r0.rgb,r0,r5 // color = color*attenuation
};
}
}
";
}

action Shader_Phong
{
my.material = mat_PHONG;
}







You can get an working example and a full c++ code from the above link.

If someone could make this work it would mean this: We could do something simmilar to Far Cry or even Doom 3.

Far Cry has this tool called Poly Bump that is free for non-commercial use. So you make a very detailed model and this tool creates a normal map for that model. Then you make a low poly model (1000-1500 poly's) and using the lighting metod above and the normal map you get a very detailed model that is still low poly. Anyway it would be cool

Good Luck!

Re: Per-Pixel Lighting [Re: Taros] #27785
05/24/04 05:46
05/24/04 05:46
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
If I was going to fiddle with this I would:
Change the stream declarations to how it is documneted that we get them passed from the engine. Then change the references in the ASM accordingly.
Then I would change the code to calculate the binormal in the shader code as opposed to trying to get it from the stream.

Regardless, it may be hit or miss and a fair amount of frustration.

Good luck!!

Re: Per-Pixel Lighting [Re: Taros] #27786
05/24/04 06:02
05/24/04 06:02
Joined: May 2004
Posts: 14
B
bulljack Offline
Newbie
bulljack  Offline
Newbie
B

Joined: May 2004
Posts: 14
I have the same problem,look at my post"normap question about A6.2 and rendermonkey?"


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