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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 1,395 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 2 of 4 1 2 3 4
Re: SoilFog [Re: Rigoletto] #56171
09/26/05 12:31
09/26/05 12:31
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline
Expert
XNASorcerer  Offline
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
How can we use this?

Re: SoilFog [Re: task1] #56172
09/26/05 12:37
09/26/05 12:37
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Hi Rigoletto,

can you post the full shader here?
Maybe you have some hints for the graveyard?
- how would you animate it for best visual effect?
- could you perturb the result?

Just for the case a skelleton walks around through this scenery it would be nice to see an effect to the fog.
Ok, I really have a very dark scene in my current project. Some nice fog like yours could improve the mood.

-- slacer

Re: SoilFog [Re: slacer] #56173
09/26/05 14:06
09/26/05 14:06
Joined: Apr 2005
Posts: 1,058
Luzern
Nicolas_B Offline
Serious User
Nicolas_B  Offline
Serious User

Joined: Apr 2005
Posts: 1,058
Luzern
thank you.
nice job.

Re: SoilFog [Re: slacer] #56174
09/26/05 16:48
09/26/05 16:48
Joined: May 2003
Posts: 609
Rattenfängerstadt
Rigoletto Offline OP
Developer
Rigoletto  Offline OP
Developer

Joined: May 2003
Posts: 609
Rattenfängerstadt
Hi,

here is the full code. I try to add a function so that the heigh of the fog changes slightly, but i think if it´s too much you will see that it is a faked "volumetric" fog.

Interactive fog is just behind my knowledge, perhaps further.



Code:
 
material stone_tga
{
// Define your bitmaps as skins
skin1 = alphamap;
skin2 = effectmap;

effect
"
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Define your needed values
float4x4 matWorldViewProj; //
float4x4 matWorldView; //
float4x4 matWorld; // entity position/direction
float4 vecFog; // fog parameters
float4 vecViewPos; //
float4 vecTime; //

// Define your textures
texture entSkin1; // level texture
texture entSkin2; // shadow texture
texture mtlSkin1; // alpha texture
texture mtlSkin2; // effect texture

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings
sampler sBase = sampler_state // level texture
{
Texture = <entSkin1>; // Give your texture here
MipFilter = Linear; // None | Point | Linear | Anisotropic | PyramidalQuad | GaussianQuad
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap; // Wrap | Mirror | Clamp | Border | MirrorOnce
AddressV = Wrap;
AddressW = Wrap;
BorderColor = {255, 0, 0, 0}; // Color for AddressUVW with Border
};

sampler sShadow = sampler_state // shadow texture
{
Texture = <entSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

sampler sAlpha = sampler_state // alpha texture
{
Texture = <mtlSkin1>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

sampler sGrass = sampler_state // grass texture
{
Texture = <mtlSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Input and output structs
//
// Possible input values for vertexshader
//
// POSITION[n] position
// BLENDWEIGHT[n] blend weights
// BLENDINDICES[n] blend indices
// NORMAL[n] normal vector
// PSIZE[n] point size
// COLOR[n] diffuse and specular color
// TEXCOORD[n] texture coordinates
// TANGENT[n] tangent
// BINORMAL[n] binormal
// TESSFACTOR[n] tessellation factor
//
// Possible output values for vertexshader
//
// POSITION Position
// PSIZE Point size
// FOG Vertex fog
// COLOR[n] Color (example: COLOR0)
// TEXCOORD[n] Texture coordinates (example: TEXCOORD0)
//
//
// Possible input values for pixelshader
//
// COLOR[n] diffuse and specular color
// TEXCOORD[n] texture coordinates
//
// Possible output values for pixelshader
//
// COLOR[n] diffuse and specular color
// TEXCOORD[n] texture coordinates
// DEPTH[n] Depth (example: DEPTH0)
//

// Define the input of your vertexshader
struct VS_IN
{
float4 Pos : POSITION;
float2 Shadow : TEXCOORD0;
float2 Base : TEXCOORD1;
float2 Alpha : TEXCOORD2;
float2 Grass : TEXCOORD3;
};

// Define the output of your vertexshader
struct VS_OUT
{
float4 Pos : POSITION;
float2 Shadow : TEXCOORD0; // Shadow is binded to TEXCOORD0, so it get transported to the pixelshader
float2 Base : TEXCOORD1;
float2 Alpha : TEXCOORD2;
float2 Grass : TEXCOORD3;
float Fog : FOG;
};

// Define the input for your pixelshader
struct PS_IN
{
float2 Shadow : TEXCOORD0; // The ouput of the vertexshader is given through TEXCOORD0
float2 Base : TEXCOORD1;
float2 Alpha : TEXCOORD2;
float2 Grass : TEXCOORD3;
};

// Define the output for your pixelshader
struct PS_OUT
{
float4 Color : COLOR; // We only give a color value back
};

//////////////////////////////////////////////////////////////////////////////////////////////////////
// functions
float4 sfInvert( float4 value )
{
return 1 - value;
}

float4 sfNegate( float4 value )
{
return - value;
}

float4 sfSepia( float4 value )
{
float4 vGrey = float4( 0.3, 0.59, 0.11, 0 );
float4 vSepia = float4( 0.9, 0.70, 0.30, 1 );
return dot( value, vGrey) * vSepia;
}

float4 sfGrey( float4 value )
{
float4 vBW = float4( 0.3, 0.59, 0.11, 0 );
return dot( value, vBW);
}

float4 sfBlackWhite( float4 value, float level) // PS 1.4
{
float4 vBW = float4( 0.3, 0.59, 0.11, 0 );
value = dot( value, vBW );
value = 1 - step( value, level );
return value;
}

float4 sfPosterize( float4 value, float level ) // PS 1.4
{
if ( value.r < level ) value.r = 0; else value.r *= 1.0f;
if ( value.g < level ) value.g = 0; else value.g *= 1.0f;
if ( value.b < level ) value.b = 0; else value.b *= 1.0f;
return value;
}

float AddFog(float3 Pos)
{
float value;
float3 P = mul( Pos, matWorld );
value = 1 - ( distance( P, vecViewPos ) - vecFog.x ) * vecFog.z;
return value;
}

float _AddSoilFog(float3 Pos)
{
float value;
float3 P = mul( Pos, matWorld );
value = 1 - ( distance( P, vecViewPos ) - vecFog.x ) * vecFog.z;
//value = value + ( P.y / 60 ) * (1 - ( distance( P, vecViewPos ) - vecFog.x ) * vecFog.z) / 16;
value = value + ( P.y / 60 );
return value;
}

float AddSoilFog(float3 Pos)
{
float value;
float low;
float high;
float3 P = mul( Pos, matWorld );
high = 1 - ( distance( P, vecViewPos ) - vecFog.x ) * vecFog.z;
low = ( P.y / 30 ); // min. low fog
value = lerp( high, low, 0.2); // mixing high and low fog
return value;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// vertexshader
VS_OUT vs( VS_IN In )
{
VS_OUT Out = ( VS_OUT ) 0; // Declare your output

Out.Pos = mul( In.Pos, matWorldViewProj ); // Transform the ouput to the view

Out.Shadow = In.Shadow; // Get the shadow texture for the current position
Out.Base = In.Base; // Get the level texture for the current position
Out.Alpha = In.Base; // Cause alpha/grass texture have no current positions (they ar not applied to level geo)
Out.Grass = In.Base; // we use the positions of the level texture

Out.Alpha.y = In.Base.y - 0.5; // Shift the alpha to the bottom

Out.Fog = AddSoilFog( In.Pos );

return Out;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// pixelshader
PS_OUT ps( PS_IN In )
{
PS_OUT Out = ( PS_OUT ) 0; // Declare your output

float4 color; // Declare your needed variables
float4 shadow;
float4 alpha;
float4 grass;

color = tex2D( sBase, In.Base.xy ); // Get color of the texture sBase at the position In.Base.xy
shadow = tex2D( sShadow, In.Shadow.xy ); // ..
alpha = tex2D( sAlpha, In.Alpha.xy ); // ..
grass = tex2D( sGrass, In.Grass.xy ); // ..

color = lerp( color, grass, alpha); // Interpolates between color and grass via alpha
color = color * shadow; // and apply the shadow

Out.Color = color; // Write the output
return Out; // and give it back

// For more functions like tex2D or lerp take a look at
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/highlevellanguageshaders/intrinsicfunctions/intrinsicfunctions.asp
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
technique test
{
// Define your passes
pass p0
{
// Compile your shaders
VertexShader = compile vs_1_0 vs();
PixelShader = compile ps_1_0 ps();
}
}
";
}



Re: SoilFog [Re: Rigoletto] #56175
09/26/05 16:53
09/26/05 16:53
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline
Expert
XNASorcerer  Offline
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Can this code work with terrains or models?

Re: SoilFog [Re: XNASorcerer] #56176
09/26/05 16:59
09/26/05 16:59
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Thank you man

-- slacer

Re: SoilFog [Re: slacer] #56177
09/27/05 00:19
09/27/05 00:19
Joined: Oct 2003
Posts: 2,628
IL,US
FeiHongJr Offline
Expert
FeiHongJr  Offline
Expert

Joined: Oct 2003
Posts: 2,628
IL,US
Thank you indeed, the screen shot looks impressive. Cant wait to try it out in a level of my own.

OT ... Lovin my new Gfx card


http://www.freewebs.com/otama_syndicate/index.htm - Each master to his own technique.

- Not me said the bee, Nor I said the fly.
Re: SoilFog [Re: XNASorcerer] #56178
09/27/05 17:41
09/27/05 17:41
Joined: May 2003
Posts: 609
Rattenfängerstadt
Rigoletto Offline OP
Developer
Rigoletto  Offline OP
Developer

Joined: May 2003
Posts: 609
Rattenfängerstadt
Yes, it works with modells and terrain.

Re: SoilFog [Re: Rigoletto] #56179
09/28/05 17:10
09/28/05 17:10
Joined: Jun 2005
Posts: 4,875
broozar Offline
Expert
broozar  Offline
Expert

Joined: Jun 2005
Posts: 4,875
humm... sorry but how is it supposed to work?
i am using your shader with level geometry and get this result:



why can´t i get any depth/fog height as in your pic? why´s all so flat?!

Last edited by DaBro0zar; 09/28/05 17:11.
Re: SoilFog [Re: broozar] #56180
09/28/05 17:36
09/28/05 17:36
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline
Expert
Rhuarc  Offline
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Because it needs to be applied to all of the textures you want the fog to show up on...


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Page 2 of 4 1 2 3 4

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