Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,359 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Gouraud Shading #44159
04/12/05 14:54
04/12/05 14:54
Joined: May 2004
Posts: 164
Germany
D
DARKLORD Offline OP
Member
DARKLORD  Offline OP
Member
D

Joined: May 2004
Posts: 164
Germany
Hello

is it possible to change this shader so that i get an effect like in MED with Gouraud Shaded. So that vertices which are oblique in the camera view are shaded.

(I don't need dynamic light and the shadow map so if you have to remove them there's no problem)

Thanks!!!

Code:
 MATERIAL mtl_terrainmulti_standard
{
skin2 = sand_01;
skin3 = gras_01;
skin4 = schnee_01;

event = create_mipmap;

effect = "

#define GREENMASK

//#define SHADOWMAP

//#define DXLIGHTING // compile vs_2_0

float4x4 matWorld;
float4x4 matWorldInv;
float4x4 matWorldView;
float4x4 matWorldViewProj;

float4 vecSunDir;
float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f);
float4 vecFog;
float4 vecLight;

Texture entSkin1; // Red/green for blending, blue for shadow
Texture mtlSkin2; // Basic tiled terrain texture
Texture mtlSkin3; // Red masked tiled texture
Texture mtlSkin4; // Green masked tiled texture

float4 vecSkill41;

float4 vecLightPos[8]; // preset this with light positions (xyz) and ranges (w)
float4 vecLightColor[8]; // preset this with light colors
float3 vecFalloff = float3(0.f, 0.f, 1.5f);

sampler sMaskTex = sampler_state
{
Texture = <entSkin1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler sBaseTex = sampler_state
{
Texture = <mtlSkin2>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler sRedTex = sampler_state
{
Texture = <mtlSkin3>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

#ifdef GREENMASK
sampler sGreenTex = sampler_state
{
Texture = <mtlSkin4>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};
#endif

float4 DoSunLight(float3 N)
{
return vecSunDiffuse * dot(N,-vecSunDir);
}

float4 DoPointLight(float3 P, float3 N, int i)
{
float3 D = (float3)vecLightPos[i]-P;
float NdotL = dot(N,normalize(D));
float4 Color = vecLightColor[i] * NdotL;
float fac = 0.f;
if (NdotL >= 0.f && vecLightPos[i].w > 0.f)
{
float LD = length(D)/vecLightPos[i].w;
#ifdef DXLIGHTING
if (LD < 1.3f)
fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD);
#else // linear Lighting
if (LD < 1.f)
fac = 1.f - LD;
#endif
}
return Color * fac;
}

float DoFog(float3 Pos)
{
float3 P = mul(Pos,matWorldView);
return saturate((vecFog.y-P.z) * vecFog.z);
}

struct TMULTI_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float4 Color: COLOR0;
float Fog: FOG;
float2 MaskCoord : TEXCOORD0;
float2 BaseCoord : TEXCOORD1;
float2 RedCoord : TEXCOORD2;
#ifdef GREENMASK
float2 GreenCoord : TEXCOORD3;
#endif
};

TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{
TMULTI_VS_OUT Out;
Out.Pos = mul(inPos,matWorldViewProj);
float3 N = normalize(mul(inNormal,matWorldInv));
//float3 N = normalize(inNormal);
float3 P = mul(inPos,matWorld);
Out.Color = vecSkill41.w + DoSunLight(N);
for (int i=0; i<6; i++)
Out.Color += DoPointLight(P,N,i);
Out.Fog = DoFog(inPos);
Out.MaskCoord = inTexCoord0.xy;
Out.BaseCoord = inTexCoord0.xy * vecSkill41.x;
Out.RedCoord = inTexCoord0.xy * vecSkill41.y;
#ifdef GREENMASK
Out.GreenCoord = inTexCoord0.xy * vecSkill41.z;
#endif
return Out;
}

float4 TMulti_PS(TMULTI_VS_OUT In): COLOR
{
float4 MaskColor = tex2D(sMaskTex,In.MaskCoord);
float4 BaseColor = tex2D(sBaseTex,In.BaseCoord);
float4 RedColor = tex2D(sRedTex,In.RedCoord);
#ifdef GREENMASK
float4 GreenColor = tex2D(sGreenTex,In.GreenCoord);
float4 BaseRed = lerp(BaseColor,RedColor,MaskColor.r);
float4 FinalColor = lerp(BaseRed,GreenColor,MaskColor.g);
#else
float4 FinalColor = lerp(BaseColor,RedColor,MaskColor.r);
#endif
#ifdef SHADOWMAP
FinalColor *= MaskColor.b + vecSkill41.w;
#else
FinalColor *= In.Color;
#endif
FinalColor.a = 1.0f; // prevent transparency
return FinalColor;
}

technique tmulti3
{
pass one
{
sampler[0] = (sMaskTex);
sampler[1] = (sBaseTex);
sampler[2] = (sRedTex);
#ifdef GREENMASK
sampler[3] = (sGreenTex);
#endif

VertexShader = compile vs_1_1 TMulti_VS();
PixelShader = compile ps_1_1 TMulti_PS();
}
}
";
}



Last edited by DARKLORD; 04/13/05 07:37.
Re: Gouraud Shading [Re: DARKLORD] #44160
04/14/05 18:37
04/14/05 18:37
Joined: May 2004
Posts: 164
Germany
D
DARKLORD Offline OP
Member
DARKLORD  Offline OP
Member
D

Joined: May 2004
Posts: 164
Germany
Maybe I have to be a bit clearer with my problem.

OK how you can see I have my terrain with the shader you can see above, but it's very hard to find out whether there is a hill or not!


So if you look to the picture for a couple of time you will find the hill but it's of course much to difficult.


So perhaps somebody has another idea how to fix this problem, but my first idea was Gouraud Shading.

I hope somebody know what I mean and is be able to help me.

Thanks

Re: Gouraud Shading [Re: DARKLORD] #44161
04/15/05 00:50
04/15/05 00:50
Joined: Aug 2003
Posts: 169
Tennessee, US
Ahriman Offline
Member
Ahriman  Offline
Member

Joined: Aug 2003
Posts: 169
Tennessee, US
is your terrain being edited in real-time at all using vec_to_mesh commands?

Re: Gouraud Shading [Re: Ahriman] #44162
04/15/05 11:18
04/15/05 11:18
Joined: May 2004
Posts: 164
Germany
D
DARKLORD Offline OP
Member
DARKLORD  Offline OP
Member
D

Joined: May 2004
Posts: 164
Germany
Yes it is.

Re: Gouraud Shading [Re: DARKLORD] #44163
04/17/05 17:42
04/17/05 17:42
Joined: Apr 2005
Posts: 64
Italy - Rome
_
_Tommo_ Offline
Junior Member
_Tommo_  Offline
Junior Member
_

Joined: Apr 2005
Posts: 64
Italy - Rome
so you need to use Ent_fixnormals(entity)
t adjust the lights on the terrain

Re: Gouraud Shading [Re: _Tommo_] #44164
04/17/05 19:40
04/17/05 19:40
Joined: May 2004
Posts: 164
Germany
D
DARKLORD Offline OP
Member
DARKLORD  Offline OP
Member
D

Joined: May 2004
Posts: 164
Germany
Thanks _Tommo_ thats great, what I need, better than shader
(5 Stars)

Mfg DARKLORD

Last edited by DARKLORD; 04/17/05 19:40.

Moderated by  Blink, Hummel, Superku 

Gamestudio download | 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