Gamestudio Links
Zorro Links
Newest Posts
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
HLSL Normal mapping for PS_1_4!! (works GREAT!) #35109
10/17/04 12:11
10/17/04 12:11
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline OP
Expert
Rhuarc  Offline OP
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Screenshot:


Just plug this into a script, and assign normalMap_ent to the entity .

Enjoy!

EDIT: I'm going to add specular and dynamic lights (only one possible) soon and update this post with the changes )

UPDATE: Added Specular, change lines in red. Specular value ranges from 0-1, 1 being little specular, 0 being full specular.

Code:
/**************************************************************/

// HLSL NormalMapping Shader
// -------------------------
// By: Daniel "Rhuarc" Niezgocki
// Requires: []VS 1.1
// []PS 1.4
// Skin1: Texture
// Skin2: Normal Map
//
// Usage: Free to use, credit is nice, but not required.
/**************************************************************/


function normalMap_init
{
mat_inverse(mtl.matrix, matWorld);
}


material normalMap_fx {
flags=tangent;
event = normalMap_init;


effect="
// VertexShader ------------------

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecSunPos;
float4 vecViewPos;
float4x4 matMtl;

texture entSkin1;
texture entSkin2;

sampler base_map = sampler_state
{
texture = (entSkin1);
};

sampler bump_map = sampler_state
{
texture = (entSkin2);
};

struct VS_INPUT_STRUCT
{
float4 position : POSITION;
float3 normal : NORMAL;
float3 texcoord0 : TEXCOORD0;
float3 tangent : TEXCOORD2;
};

struct VS_OUTPUT_STRUCT
{
float4 position : POSITION;
float2 bump_map : TEXCOORD0;
float3 light_angle : TEXCOORD1;
};

VS_OUTPUT_STRUCT mainVS( VS_INPUT_STRUCT vsInStruct )
{
VS_OUTPUT_STRUCT vsOutStruct;
vsOutStruct.position = mul( vsInStruct.position, matWorldViewProj );

float3 position = mul( matWorld, vsInStruct.position );

vsOutStruct.bump_map = vsInStruct.texcoord0;

float3 light_normal_vector = mul( vsInStruct.normal, matWorld );

vsOutStruct.light_angle = light_normal_vector;

return vsOutStruct;
};

// PixelShader -------------------

float bumpiness = 0.5;
float specular = 0.5;
float4 vecAmbient;
float4 vecDiffuse;
float4 vecSpecular;
float vecViewDir;
struct PS_INPUT_STRUCT
{
float2 bump_map : TEXCOORD0;
float3 light_angle : TEXCOORD1;
};

struct PS_OUTPUT_STRUCT
{
float4 color0 : COLOR0;
};

PS_OUTPUT_STRUCT mainPS( PS_INPUT_STRUCT psInStruct )
{
PS_OUTPUT_STRUCT psOutStruct;

float3 base = tex2D( base_map, psInStruct.bump_map );
float3 bump = tex2D( bump_map, psInStruct.bump_map );

// Uncompress vectors ([0, 1] -> [-1, 1])
float3 lightVectorFinal = (psInStruct.light_angle - 0.5);
float3 bumpNormalVectorFinal = bumpiness * (bump - 0.5);

// Compute diffuse factor
float diffuse = dot(bumpNormalVectorFinal, lightVectorFinal);

psOutStruct.color0.rgb = ( diffuse * base + + max(diffuse-specular,0));
psOutStruct.color0.a = 1.0f;
return psOutStruct;
};

technique normalMap
{
pass P0
{
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_1_4 mainPS();
}
}
";
}

action normalMap_ent
{
my.material = normalMap_fx;
}



Last edited by [Rhuarc]; 10/17/04 22:25.
Re: HLSL Normal mapping for PS_1_4!! (works GREAT!) [Re: Rhuarc] #35110
10/17/04 12:43
10/17/04 12:43
Joined: Oct 2002
Posts: 815
NY USA
R
Red Ocktober Offline
Developer
Red Ocktober  Offline
Developer
R

Joined: Oct 2002
Posts: 815
NY USA
wow... lookin' good Rhu...

lemme test it out and compare it with the code you put up previously in the level thread...

oh yeah, THANKS for sharing


--Mike

Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Red Ocktober] #35111
10/17/04 12:45
10/17/04 12:45
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline OP
Expert
Rhuarc  Offline OP
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Just keep in mind that this only works for models at this point. It won't work for levels yet... We'll see how the level version of it ends up (there's a lot of factors and workarounds planned, lol)

-Rhuarc


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Rhuarc] #35112
10/17/04 12:46
10/17/04 12:46
Joined: Oct 2002
Posts: 815
NY USA
R
Red Ocktober Offline
Developer
Red Ocktober  Offline
Developer
R

Joined: Oct 2002
Posts: 815
NY USA
understand... no problem...

models is great for right now...

--Mike

Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Red Ocktober] #35113
10/17/04 13:25
10/17/04 13:25
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline OP
Expert
Rhuarc  Offline OP
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Updated shader above with specular... It's cheap, but it works .

0.9 seems to be the best value for the specular variable...

-Rhuarc


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Rhuarc] #35114
10/17/04 15:39
10/17/04 15:39
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
Thats great, thanks! works very well!! REALLY appreciate the contribution.
can it use level ambient color in the future? also, point light and/or object light sources would be great.. then ill work on a flashlight effecct, hopefully the light source could be attached, moving a specular over the objects...I did it with the older dx8 normal map code, but the light would get stuck on an ebject...
Thanks again!

Last edited by Drew; 10/17/04 16:11.

Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Drew] #35115
10/17/04 20:00
10/17/04 20:00
Joined: May 2004
Posts: 164
Germany
D
DARKLORD Offline
Member
DARKLORD  Offline
Member
D

Joined: May 2004
Posts: 164
Germany
Whats with skin3?

Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Drew] #35116
10/17/04 22:27
10/17/04 22:27
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline OP
Expert
Rhuarc  Offline OP
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Quote:

Thats great, thanks! works very well!! REALLY appreciate the contribution.
can it use level ambient color in the future? also, point light and/or object light sources would be great.. then ill work on a flashlight effecct, hopefully the light source could be attached, moving a specular over the objects...I did it with the older dx8 normal map code, but the light would get stuck on an ebject...
Thanks again!



I'm glad it works well for you . I'm gonna look into the ambient lighting as well as work on those object lightsources.

Quote:

Whats with skin3?



Ah, I still had it in there from trying it with level textures...


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Rhuarc] #35117
10/18/04 05:02
10/18/04 05:02
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
If you need an example of point lighting innormal mappingm look at my normal mapping tutorial in 'tutorials'..the dx8 code has that (by Matt H.)

Re: HLSL Normal mapping for PS_1_4!! (works GREAT [Re: Drew] #35118
10/27/04 09:02
10/27/04 09:02
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
any updates on this one?

thanks

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