Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, SBGuy), 987 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Bump specular wiht sun ? #61326
12/29/05 21:36
12/29/05 21:36
Joined: Oct 2004
Posts: 1,856
TheExpert Offline OP
Senior Developer
TheExpert  Offline OP
Senior Developer

Joined: Oct 2004
Posts: 1,856
Anyone could give us some day a simple bump shader taking account of the sun
of the level defined in map properties ?

Re: Bump specular wiht sun ? [Re: TheExpert] #61327
12/30/05 07:22
12/30/05 07:22
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
This shader will do specular and diffuse normal mapping from the sun. Put color map+specmap in alpha channel in skin 1, normal map in skin 2.

define the material like this:
material mat_normalmap
{
flags=tangent;
}

after you load you level do this in a function:
effect_load(mat_normalmap,"normalmap.fx");
mat_normalmap.skill1=float(sun_pos.x);
mat_normalmap.skill2=float(sun_pos.z);
mat_normalmap.skill3=float(sun_pos.y);

then make an fx file called normalmap.fx with this code:

Code:
 
// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
//Only does sun light, no dynamic lights..

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewPos;
float4 vecFog;
float4 vecSkill1;

float4 ambientcolor={0.3,0.3,0.3,0.0}; //can also use vecLight here for true ambient color
float4 suncolor={0.8,0.8,0.7,0.0}; //define the suncolor here, couls al so pass it fomr the script in a mtl skill

texture entSkin1; //this is the color map with specular map in alpha ..32 bit
texture entSkin2; //this is the normal map .. 24 bit

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//sunlight
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 View4 : TEXCOORD3;

float3 Sun : TEXCOORD1;
float Fog : FOG;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
VS_OUTPUT1 Out = (VS_OUTPUT1)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

// float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
// Out.Fog = ofog;
Out.Fog = 10000;


float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

//sunlight
Out.Sun.xyz = mul(worldToTangentSpace, vecSkill1); // L

return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;
float3 View4 : TEXCOORD3;
float3 Sun : TEXCOORD1;
float Fog : FOG;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
float4 PS_PASS1( PS_INPUT1 psInStruct ):COLOR
{

float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
bumpNormal=normalize(bumpNormal);

float3 ViewDir4 = normalize(psInStruct.View4);

//sunlight
float3 Sun = normalize(psInStruct.Sun);
float4 diff7 = saturate(dot(bumpNormal, Sun)); // diffuse component
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - Sun); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir4)), 15);
float shadow7 = saturate(4 * diff7);

return
(
(ambientcolor * color) + //ambient

((shadow7* (color * diff7 + (spec7*color.w))) * suncolor)
);
}

// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{

pass P0
{
alphablendenable=false;
zenable=true;
zwriteenable=true;


//compile shaders
VertexShader = compile vs_1_1 VS_PASS1();
PixelShader = compile ps_2_0 PS_PASS1();
}



}




Sphere Engine--the premier A6 graphics plugin.
Re: Bump specular wiht sun ? [Re: Matt_Aufderheide] #61328
12/30/05 12:46
12/30/05 12:46
Joined: Oct 2004
Posts: 1,856
TheExpert Offline OP
Senior Developer
TheExpert  Offline OP
Senior Developer

Joined: Oct 2004
Posts: 1,856
Thanks a lot Matt

Caus the existing ones i found worked with fixed light, and not
good for a global lightening.

thanks again.

Re: Bump specular wiht sun ? [Re: TheExpert] #61329
12/30/05 14:46
12/30/05 14:46
Joined: Feb 2005
Posts: 63
Germany,
L
Logimator Offline
Junior Member
Logimator  Offline
Junior Member
L

Joined: Feb 2005
Posts: 63
Germany,
Excellent Shader The Bump-Mapping is one of the best i've seen. Thubs up for Matt again

@Matt, the only thing is, the Shader has Problems with transparent models which are in front of the shaded model. Do you think, this could be fixed ?

Re: Bump specular wiht sun ? [Re: Logimator] #61330
12/30/05 18:24
12/30/05 18:24
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
make sure that the entities you have this material assigned to have my.transparency=off and my.flare=off...

becasue it has a tga with alpha channel, the engine will automatically sort it as a transparent entity, when it shouldn't be.. so set those flags off in the action and it will be fine.


Sphere Engine--the premier A6 graphics plugin.
Re: Bump specular wiht sun ? [Re: Matt_Aufderheide] #61331
12/31/05 18:08
12/31/05 18:08
Joined: Feb 2005
Posts: 63
Germany,
L
Logimator Offline
Junior Member
Logimator  Offline
Junior Member
L

Joined: Feb 2005
Posts: 63
Germany,
Again Thumps up. Working now, looking perfect ! Matt's the Shader Guru

@Matt, do you have the same Shader working for Dynamic-Lights also ?

Re: Bump specular wiht sun ? [Re: Logimator] #61332
01/01/06 02:39
01/01/06 02:39
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
yes, you can try the Ultimate Lighting Shader, or buy the Sphere Engine which is better.. it has the shaders all ready, even if you dont use the other features you can use the model normal mapping shader with dynamic lights.


Sphere Engine--the premier A6 graphics plugin.
Re: Bump specular wiht sun ? [Re: Matt_Aufderheide] #61333
01/01/06 20:31
01/01/06 20:31
Joined: Oct 2004
Posts: 1,856
TheExpert Offline OP
Senior Developer
TheExpert  Offline OP
Senior Developer

Joined: Oct 2004
Posts: 1,856
For my part i'll never buy things that are free in open source 3D engines,
and that you can have directly !!

Re: Bump specular wiht sun ? [Re: TheExpert] #61334
01/07/06 13:37
01/07/06 13:37
Joined: Mar 2002
Posts: 221
USA
zefor Offline
Member
zefor  Offline
Member

Joined: Mar 2002
Posts: 221
USA
Not seeing bump or specular. do I need to assign an action? something like this?


Code:
 
action bumpout
{
my.material=mat_normalmap;
}



Still no result. I have color map with specular in alpha channel in skin1, saved as a 32 bit tga. I have my normal map in skin2 saved as 24 bit tga. ???

also tried this action
Code:
 action tryout
{
my.transparent = off;
my.flare = off;
}



Still a no go.

Last edited by zefor; 01/07/06 13:47.
Re: Bump specular wiht sun ? [Re: zefor] #61335
01/07/06 17:13
01/07/06 17:13
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
make sure you have this stuff in a function that loads after the level is loaded

effect_load(mat_normalmap,"normalmap.fx");
mat_normalmap.skill1=float(sun_pos.x);
mat_normalmap.skill2=float(sun_pos.z);
mat_normalmap.skill3=float(sun_pos.y);

you have to save the shader code in a file called normalmap.fx, and this file must be in your game's root directory, not in a subfolder.


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