Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
1 registered members (AndrewAMD), 1,534 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help to apply a ambient , albedo to a terrain shad #61003
12/25/05 23:18
12/25/05 23:18
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Hi.
I am using the multitexture shader from here. And I would like to make the terrain to be affected by its ambient and albedo propreties, but with no results.

This is the changed code ( It doesn't give errors but it doesn't change the ambient):
Code:
 
// entSkin1 Texture Base
// entSkin2 Texture Layer Red

bmap tex1 = <EarthRoad.bmp>;
bmap tex4 = <Rock.bmp>;
bmap tex5 = <grass7.bmp>;
bmap tex6 = <detailmap.tga>;

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 vecFog;

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

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

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings
sampler sTex1 = sampler_state
{
Texture = <entSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex2 = sampler_state
{
Texture = <entSkin1>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex3 = sampler_state
{
Texture = <mtlSkin1>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex4 = sampler_state
{
Texture = <mtlSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex5 = sampler_state
{
Texture = <mtlSkin3>;
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;
float4 Color : COLOR0;
float Fog : FOG;
float2 Tex1 : TEXCOORD0;
float2 Tex2 : TEXCOORD1;
float2 Tex3 : TEXCOORD2;
float2 Tex4 : TEXCOORD3;
float2 Tex5 : TEXCOORD5;
float2 Tex6 : TEXCOORD6;
};

//////////////////////////////////////////////////////////////////////
// return the sun light on the surface
float4 DoSunLight(float3 N)
{
// modulate the sunlight by the surface angle
return vecSunDiffuse * dot(N,-vecSunDir);
}


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 ambient and sun light
Out.Color = vecSkill41.w + DoSunLight(N);

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*20; // Tile Texture Layer Red
Out.Tex4 = inTexCoord0.xy*20; // Tile Texture Layer Green
Out.Tex5 = inTexCoord0.xy*20; // Tile Texture Layer Blue
Out.Tex6 = inTexCoord0.xy*20; // Tile Texture Layer Detailmap
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.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.ambient = 10;
my.albedo = 100;
my.material=multirgb;
}



Thanks.

Re: Help to apply a ambient , albedo to a terrain [Re: XNASorcerer] #61004
12/26/05 05:41
12/26/05 05:41
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
simply setting these
my.ambient = 10;
my.albedo = 100;

wont do anything of course because this is a shader.. the normal directx material properties have no meaning for shaders. you would need to code the into the shader the lighitng properties.

Anyway, in this shader the lighting isnt even applied anyway.. thid is not coded correctly..The sunlight is calculated in the vertex shader but not even applied in the pixel sahder, and there are no pointlights calculated at all. This is not a useful shader..


Sphere Engine--the premier A6 graphics plugin.
Re: Help to apply a ambient , albedo to a terrain [Re: Matt_Aufderheide] #61005
12/26/05 23:26
12/26/05 23:26
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Quote:

simply setting these
my.ambient = 10;
my.albedo = 100;

wont do anything of course because this is a shader.. the normal directx material properties have no meaning for shaders. you would need to code the into the shader the lighitng properties.





I know that. That is why I added these lines:
Code:
 
float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f);
float4 DoSunLight(float3 N)
{
// modulate the sunlight by the surface angle
return vecSunDiffuse * dot(N,-vecSunDir);
}

...

Out.Color = vecSkill41.w + DoSunLight(N);




Quote:

... The sunlight is calculated in the vertex shader but not even applied in the pixel sahder ...




Yes, I was forgoting to put this: "FinalColor *= In.Color;" inside the pixel shader. With this I can see some ambient, but what I need is to be able to change it by the terrain ambient value.

Quote:

... and there are no pointlights calculated at all...




What do you mean by pointlights? Maybe dynamic lights? If so, I am not there yet.

Last edited by Sorcerer; 12/26/05 23:28.
Re: Help to apply a ambient , albedo to a terrain [Re: XNASorcerer] #61006
12/27/05 08:21
12/27/05 08:21
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
i you cant use the ambeint values from sctipt in a shader.. directly.. the best way is to simply assign a skill a value, and pass that intot skill41 as a vector


Sphere Engine--the premier A6 graphics plugin.

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