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 (NewbieZorro, TipmyPip, AndrewAMD), 14,749 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
Rate Thread
Page 1 of 2 1 2
need help adding a shadowmap #76754
06/05/06 15:07
06/05/06 15:07
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
May I ask you to help me adding an other pass for a shadowmap to this shader...due to my lack of script understanding, I just don't manage myself.

Thanks a bunch!

Code:
// multirgb.wdl


// entSkin1 Texture Base
// entSkin2 RGB Mask

bmap tex1 = <rock.bmp>; // Texture Layer Red
bmap tex4 = <road.bmp>; // Texture Layer Green
bmap tex5 = <sand.bmp>; // Texture Layer Blue
bmap tex6 = <detailmap.tga>; // DetailMap

function multirgb_roughness() {
bmap_to_mipmap(mtl.Skin1);
bmap_to_mipmap(mtl.Skin2);
bmap_to_mipmap(mtl.Skin3);
bmap_to_mipmap(mtl.Skin4);

}

material multirgb {
flags = tangent;
skin1 = tex1;
skin2 = tex4;
skin3 = tex5;
skin4 = tex6;

event=multirgb_roughness;

effect
"
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Define your needed values
float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldInv;
float4x4 matWorldView;

float4 vecSunDir;
float4 vecSunDiffuse = float4(255.f/255.f, 255.f/255.f, 255.f/255.f, 1.f);
float4 vecLight;
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);

float4 vecFog;

// Define your textures
texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
texture mtlSkin4;
texture entSkin1;
texture entSkin2;


//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings
sampler sTex1 = sampler_state
{
Texture = <entSkin2>; // RGB Mask
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex2 = sampler_state
{
Texture = <entSkin1>; // Texture Base
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex3 = sampler_state
{
Texture = <mtlSkin1>; // Texture Layer Red
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex4 = sampler_state
{
Texture = <mtlSkin2>; // Texture Layer Green
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex5 = sampler_state
{
Texture = <mtlSkin3>; // Texture Layer Blue
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex6 = sampler_state
{
Texture = <mtlSkin4>; // Detailmap for Base Texture
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

struct TMULTI_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float Fog : FOG;
float4 Color : COLOR0;
float2 Tex1 : TEXCOORD0;
float2 Tex2 : TEXCOORD1;
float2 Tex3 : TEXCOORD2;
float2 Tex4 : TEXCOORD3;
float2 Tex5 : TEXCOORD5;
float2 Tex6 : TEXCOORD6;
};




float DoFog(float4 Pos) {
float3 P = mul(Pos,matWorldView);// apply the linear fog formula
return saturate((vecFog.y-P.z) * vecFog.z);
}


TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{

TMULTI_VS_OUT Out;

// transform the vector position to screen coordinates
Out.Pos = mul(inPos,matWorldViewProj);

// rotate and normalize the normal
float3 N = normalize(mul(inNormal,matWorldInv));

// Add sun light
float3 objSunDir = normalize(mul(-vecSunDir.xyz, matWorldInv));
float sunDiff = max(dot(inNormal, objSunDir), 0);
Out.Color = float4(vecSunDiffuse.rgb * sunDiff, 1);

// Add point lights
for(int i = 0; i <= 5; i++)
{
// Diffuse lighting
float4 objLightPos = mul(float4(vecLightPos[i].xyz, 1), matWorldInv);
float4 objLightDir = objLightPos - inPos;
float4 objLightDirN = normalize(objLightDir);
float diffLight = max(dot(objLightDirN, inNormal), 0);

// Calculate attenuation factor
float falloffFactor = 0;
if(vecLightPos[i].w > 0)
{
float linearDistance = length(objLightDir)/vecLightPos[i].w;
if(linearDistance < 1) falloffFactor = 1 - linearDistance;
}
diffLight *= falloffFactor;

// Add to final result
Out.Color.rgb += vecLightColor[i].rgb * diffLight;
}


Out.Fog = DoFog(inPos);

// scale the texture coordinates for the masked textures
Out.Tex1 = inTexCoord0.xy; // Tile Mask
Out.Tex2 = inTexCoord0.xy; // Tile Base Texture
Out.Tex3 = inTexCoord0.xy*30; // Tile Texture Layer Red (rock)
Out.Tex4 = inTexCoord0.xy*100; // Tile Texture Layer Green (road)
Out.Tex5 = inTexCoord0.xy*180; // Tile Texture Layer detailmap
Out.Tex6 = inTexCoord0.xy*80; // Tile Texture Layer blue (sand)
return Out;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
// pixelshader
float4 ps( TMULTI_VS_OUT In ) : COLOR
{
float4 MaskColor = tex2D(sTex1,In.Tex1);
float4 BaseColor = tex2D(sTex2,In.Tex2);
float4 RedColor = tex2D(sTex3,In.Tex3);
float4 GreenColor = tex2D(sTex4,In.Tex4);
float4 BlueColor = tex2D(sTex5,In.Tex5);
float4 DetailColor = tex2D(sTex6,In.Tex5);

BaseColor = BaseColor + DetailColor - 0.5;

float4 BaseRed = lerp(BaseColor,RedColor,MaskColor.r);
float4 BaseGreen = lerp(BaseRed,GreenColor,MaskColor.g);
float4 FinalColor = lerp(BaseGreen,BlueColor,MaskColor.b);
FinalColor *=(In.Color+0.15)*3;
FinalColor.a = 1.0f; // prevent transparency

return FinalColor;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
technique mytechnique
{
// Define your passes
pass p0
{
VertexShader = compile vs_2_0 TMulti_VS();
PixelShader = compile ps_2_0 ps();
}
}
";
}

ACTION multi_rgb {

my.material=multirgb;

}



Re: need help adding a shadowmap [Re: Loopix] #76755
06/06/06 06:39
06/06/06 06:39
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
hm, you could do so, but as you would need a shadowmap anyway, why dont you mix the shadows into the base map (sTex2)? i dont know if it would benefit anything if you'd use a shader to mix a shadowmap

Re: need help adding a shadowmap [Re: ello] #76756
06/06/06 10:21
06/06/06 10:21
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
well...then I could have shaows only where the basemap shows up...but there are other textures too. I think best would be a shadowmap pass. Would be great if you could help me

Re: need help adding a shadowmap [Re: Loopix] #76757
06/06/06 10:33
06/06/06 10:33
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
set up a sampler:

...
texture entSkin3; //entSkin3 contains the shadowmap
sampler shadowMap= sampler_state
{
Texture = <entSkin3>; // Texture Base
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
...

add this to the pixelshader before that line (FinalColor.a = 1.0f; // prevent transparency):

...
float4 shadow = tex2D(shadowMap,In.Tex1);
FinalColor = FinalColor*shadow; // maybe you will want to have it brighter ...*(shadow+0.2)
...

its untested but should do the job

Re: need help adding a shadowmap [Re: ello] #76758
06/06/06 10:49
06/06/06 10:49
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hey thanks! I will give it a try

Re: need help adding a shadowmap [Re: Loopix] #76759
06/06/06 18:49
06/06/06 18:49
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Works perfect! Everytime I post something in this shader forum, I get a first time working answer. This is really great...big thank to all my shader gods

Re: need help adding a shadowmap [Re: Loopix] #76760
06/06/06 22:12
06/06/06 22:12
Joined: Jun 2005
Posts: 39
Australia
S
Static707 Offline
Newbie
Static707  Offline
Newbie
S

Joined: Jun 2005
Posts: 39
Australia
Could someone clarify what the shadow map actually does?

Cheers

Static

Re: need help adding a shadowmap [Re: Static707] #76761
06/07/06 08:07
06/07/06 08:07
Joined: Nov 2003
Posts: 1,659
San Francisco
JetpackMonkey Offline
Serious User
JetpackMonkey  Offline
Serious User

Joined: Nov 2003
Posts: 1,659
San Francisco
Will this actually place a shadow map on a polymesh model?

Or will this somehow replace the default shadowmap generated by WED?

Or ... ?

Re: need help adding a shadowmap [Re: JetpackMonkey] #76762
06/07/06 08:39
06/07/06 08:39
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
this will place any shadowmap you have as an image. it can be colored or just black n white. handpainted or prerendered by your 3d app


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: need help adding a shadowmap [Re: ello] #76763
06/07/06 08:56
06/07/06 08:56
Joined: Nov 2003
Posts: 1,659
San Francisco
JetpackMonkey Offline
Serious User
JetpackMonkey  Offline
Serious User

Joined: Nov 2003
Posts: 1,659
San Francisco
Thanks, ello. I see, and will it only place a shadow on my model, or will it also be projected on my character and other objects which come between the shadowmap and the 'light source'?

Page 1 of 2 1 2

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