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 2 1 2
Normalmapping shader (ps1.1) #50902
08/06/05 16:26
08/06/05 16:26
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline OP
Expert
Rhuarc  Offline OP
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Code:
extern float4x4 matWorldViewProj;
extern float4x4 matWorldInv;
extern float4x4 matWorld;

float4 vecLightPos[8];
float4 vecLightColor[8];

float4 vecAmbient;
float4 vecDiffuse;

texture entSkin1; // diffuse
texture entSkin2; // normals

sampler2D diffuseSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

sampler2D normalSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};


// vertex input
struct VertexIn {
float4 Position : POSITION; //in object space
float2 UV : TEXCOORD0; //in object space
float4 Normal : NORMAL; //in object space
float3 T : TEXCOORD2; //in object space
};

//vertex output
struct VertexOut {
float4 HPosition : POSITION;

float2 texCoord0 : TEXCOORD0;
float2 texCoord1 : TEXCOORD1;
float3 LightVector : TEXCOORD2;
};

//vertex shader*************************************
VertexOut DiffuseBumpVS(VertexIn IN)
{
//create the vertex out struct
VertexOut OUT;

OUT.texCoord0 = IN.UV; //pass coords for diffuse map
OUT.texCoord1 = IN.UV; //pass coords for normal map
// compute the 3x3 tranform from tangent space to object space
float3x3 objToTangentSpace;
objToTangentSpace[0] = IN.T;
objToTangentSpace[1] = cross(IN.T, IN.Normal);
objToTangentSpace[2] = IN.Normal;

//put the vert position in world space
float4 worldSpacePos = mul(IN.Position, matWorld);

//cast a ray to the light
float4 normLightVec = mul(vecLightPos[1], matWorld) - worldSpacePos;

//transform the light vector to object space
float3 objnormLightVec = mul(normLightVec, matWorldInv).xyz;
objnormLightVec = normalize(objnormLightVec);

// transform light vector from object space to tangent space and pass it as a color
OUT.LightVector = 0.5 * mul(objToTangentSpace, objnormLightVec) + 0.5;

// transform position to projection space
OUT.HPosition = mul(IN.Position, matWorldViewProj);

return OUT;
}


//pixel shader*************************************
float4 myps(VertexOut IN):COLOR
{
float4 col;

//get the color from the diffuse texture
float4 texColor = tex2D(diffuseSampler, IN.texCoord0);

//get the color from the normal map and convert to normal
float4 bumpNormal = (2 * (tex2D(normalSampler, IN.texCoord1)-0.5));

//unpack the light vector to [-1,1]
float3 lightVector = 2* (IN.LightVector - 0.5);

//compute the angle to the light and clamp at zero
float bump = max(dot(bumpNormal,lightVector),0);

//compute final color (diffuse + ambient)
float4 diffuse = texColor * bump * vecLightColor[1];
float4 ambient = texColor * vecAmbient*0.5;
col = diffuse + ambient;
col.a = 1.0;

return col;
}

technique diffuseBump
{
pass p0
{
ZEnable = true;
ZWriteEnable = true;
CullMode = CCW;
VertexShader = compile vs_1_1 DiffuseBumpVS();
PixelShader = compile ps_1_1 myps();
}
}



Converted from: http://www.monitorstudios.biz/bcloward/resources_shaders.html

Entskin1 - diffuse map
Entskin2 - normal map

Supports 1 point light.

-Rhuarc


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: Normalmapping shader (ps1.1) [Re: Rhuarc] #50903
08/06/05 18:52
08/06/05 18:52
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline
User
BoH_Havoc  Offline
User

Joined: Jun 2004
Posts: 655
to your left
good job [Rhuarc]

exspecially giving the source of the shader is a good idea as shader-n00bs like myself can try to understand the steps of how to convert a shader to be used with 3dgs


Shade-C EVO Lite-C Shader Framework
Re: Normalmapping shader (ps1.1) [Re: BoH_Havoc] #50904
08/07/05 10:22
08/07/05 10:22
Joined: Mar 2003
Posts: 1,095
Germany
nightshade Offline
Serious User
nightshade  Offline
Serious User

Joined: Mar 2003
Posts: 1,095
Germany
Don't works :-(, to many Errors :'(. But screens lookin' very nice!

Re: Normalmapping shader (ps1.1) [Re: nightshade] #50905
08/07/05 22:48
08/07/05 22:48
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
you say it supports a point light.. how do you calculate attenuation? as far as i can see it doesnt have any at all. It seems you need another pass with an attenuation factor.

Re: Normalmapping shader (ps1.1) [Re: Matt_Aufderheide] #50906
08/08/05 00:09
08/08/05 00:09
Joined: Sep 2004
Posts: 1,214
Austin, Texas
Josh_Arldt Offline
Senior Developer
Josh_Arldt  Offline
Senior Developer

Joined: Sep 2004
Posts: 1,214
Austin, Texas
Thanks Rhuarc.
This is cool!

The light seems to have to be placed far away from the model for the light to shine on it... I have the light attached to a camera.

Here's a picture of the bumpmapping so everyone can see what it looks like in the A6.



Re: Normalmapping shader (ps1.1) [Re: Josh_Arldt] #50907
08/08/05 03:29
08/08/05 03:29
Joined: Mar 2005
Posts: 123
O
oronll Offline
Member
oronll  Offline
Member
O

Joined: Mar 2005
Posts: 123
why cant anyone get GS sunlight to work with these shaders?

Re: Normalmapping shader (ps1.1) [Re: oronll] #50908
08/08/05 08:59
08/08/05 08:59
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
what is the extern... for??


www.earthcontrol.de
quoted: We want to maintain a clean, decent, American family suited forum look... which means you may post zombies or chainsaw massacres, but no erotic.
Re: Normalmapping shader (ps1.1) [Re: ello] #50909
08/08/05 12:47
08/08/05 12:47
Joined: Mar 2003
Posts: 1,095
Germany
nightshade Offline
Serious User
nightshade  Offline
Serious User

Joined: Mar 2003
Posts: 1,095
Germany
ello, why It doesn't worked?

Re: Normalmapping shader (ps1.1) [Re: nightshade] #50910
08/08/05 13:25
08/08/05 13:25
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
could be many causes for that. wrong copying, wrong engine version


www.earthcontrol.de
quoted: We want to maintain a clean, decent, American family suited forum look... which means you may post zombies or chainsaw massacres, but no erotic.
Re: Normalmapping shader (ps1.1) [Re: ello] #50911
08/08/05 14:02
08/08/05 14:02
Joined: Mar 2005
Posts: 80
S
SirSven Offline
Junior Member
SirSven  Offline
Junior Member
S

Joined: Mar 2005
Posts: 80
Can somebody help me?

I get always the error that the model has the same color like my background and fog!
I have one dynamic light next to the model!



Page 1 of 2 1 2

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