Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
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 (Ayumi), 900 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Env- & Specular Bumpmapping DX9 [Re: NMS] #32892
08/22/05 10:20
08/22/05 10:20
Joined: Nov 2003
Posts: 1,267
ef
C
Christoph_B Offline
Serious User
Christoph_B  Offline
Serious User
C

Joined: Nov 2003
Posts: 1,267
ef
this thread is almost one year old...


sef
Re: Env- & Specular Bumpmapping DX9 [Re: oliver2s] #32893
08/22/05 16:11
08/22/05 16:11
Joined: Jul 2002
Posts: 156
Thüringen
SFMAT4 Offline
Member
SFMAT4  Offline
Member

Joined: Jul 2002
Posts: 156
Thüringen
Hi,

I have a question about these shaders. Is there a possibillity to insert the alpha channel from the diffuse map? Maybe for using these shader on tga plants or somthing else. Thanks for help!

best regards
SF

Shader:

for main wdl file.
Code:
 
STARTER load_fx
{
effect_load(mat_env_bump,"env_bump.fx");
effect_load(mat_spec_bump,"spec_bump.fx");
}

ACTION test_ent1
{
my.material = mat_env_bump;
}



specular bumpmapping
Code:
 
float bumpiness = { 1.0f }; //Stärke des Bumpmappings
float specular_power = { 128.0f }; //Stärke des Lichts (1 = sehr stark, über 1 schwächer)
float Ka = { 1.0f }; //Gesamthelligkeit
float4 specular = { 1.0f, 0.956737f, 0.670380f, 1.0f }; //Specular Farbe
float4 ambient = { 0.37647f, 0.37647f, 0.24314f, 1.0f }; //Ambient Farbe alt: alles 1.0f
float4 diffuse = { 0.37647f, 0.37647f, 0.24314f, 1.0f }; //Diffuse Farbe alt: 0.839216f, 0.862341f, 0.890411f, 1.0f


float Kd = { 1.0f };
float Ks = { 1.0f };
float4 light_position = { -100.0f, 100.0f, -100.0f, 1.0f };
float4 eye_position = { 0.0f, 0.0f, -10.0f, 1.0f };
float4 vecViewPos;
float4 vecSunDir;
float4 vecAmbient;

float4x4 matWorldViewProj: register(c0);
float4x4 matMtl;

texture entSkin1;
texture entSkin2;

struct VS_INPUT_STRUCT
{
float4 position: POSITION;
float3 normal: NORMAL;
float2 texcoord0: TEXCOORD0;
float3 binormal: TEXCOORD1;
float3 tangent: TEXCOORD2;
};

struct VS_OUTPUT_STRUCT
{
float4 position: POSITION;
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

VS_OUTPUT_STRUCT VS( VS_INPUT_STRUCT vsInStruct )
{
VS_OUTPUT_STRUCT vsOutStruct; //** Declare the output struct

//**-----------------------------------------------------------
//** Calculate the pixel position using the perspective matrix.
//**-----------------------------------------------------------
vsOutStruct.position = mul(vsInStruct.position, matWorldViewProj );

//**----------------------------------------------
//** Pass the bump and base texture coords through
//**----------------------------------------------
vsOutStruct.bump_map = vsInStruct.texcoord0;

//**--------------------------------------------
//** Calculate the light vector in object space,
//** and then transform it into texture space.
//**--------------------------------------------
float3 temp_light_position = mul( vecAmbient, matMtl );
float3 temp_light_vector = temp_light_position - vsInStruct.position;
vsOutStruct.light_vector.x = dot( temp_light_vector, vsInStruct.tangent );
vsOutStruct.light_vector.y = dot( temp_light_vector, vsInStruct.binormal );
vsOutStruct.light_vector.z = dot( temp_light_vector, vsInStruct.normal );

//**-------------------------------------------
//** Calculate the view vector in object space,
//** and then transform it into texture space.
//**-------------------------------------------
float3 temp_eye_position = mul( vecViewPos, matMtl );
float3 temp_view_vector = temp_eye_position - vsInStruct.position;
float3 temp_view_vector2;
temp_view_vector2.x = dot( temp_view_vector, vsInStruct.tangent );
temp_view_vector2.y = dot( temp_view_vector, vsInStruct.binormal );
temp_view_vector2.z = dot( temp_view_vector, vsInStruct.normal );

//**-------------------------
//** Calculate the half angle
//**-------------------------
vsOutStruct.half_angle = vsOutStruct.light_vector + temp_view_vector2;

return vsOutStruct; //** Return the resulting output struct
}

sampler base_map = sampler_state
{
texture=(entSkin1);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

sampler bump_map = sampler_state
{
texture=(entSkin2);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

struct PS_INPUT_STRUCT
{
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

struct PS_OUTPUT_STRUCT
{
float4 color0: COLOR0;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: PS_INPUT_STRUCT, derived from the output of
//** the associated vertex shader
//** Returns: PS_OUTPUT_STRUCT
//**---------------------------------------------------------
PS_OUTPUT_STRUCT PS( PS_INPUT_STRUCT psInStruct )
{
PS_OUTPUT_STRUCT psOutStruct; //** Declare the output struct

//**------------------------------------------------------
//** Retreive the base color and bump components from the
//** respective textures, based on the passed bump coords.
//**------------------------------------------------------
float3 base = tex2D( base_map, psInStruct.bump_map );
float3 bump = tex2D( bump_map, psInStruct.bump_map );

//**----------------------------------------------------
//** Normalize the passed vectors from the vertex shader
//**----------------------------------------------------
float3 normalized_light_vector = normalize( psInStruct.light_vector );
float3 normalized_half_angle = normalize( psInStruct.half_angle );

//**--------------------------------------------------------
//** "Smooth out" the bump based on the bumpiness parameter.
//** This is simply a linear interpolation between a "flat"
//** normal and a "bumped" normal. Note that this "flat"
//** normal is based on the texture space coordinate basis.
//**--------------------------------------------------------
float3 smooth = { 0.5f, 0.5f, 1.0f };
bump = lerp( smooth, bump, bumpiness );
bump = normalize( ( bump * 2.0f ) - 1.0f );

//**---------------------------------------------------------
//** These dot products are used for the lighting model
//** equations. The surface normal dotted with the light
//** vector is denoted by n_dot_l. The normal vector
//** dotted with the half angle vector is denoted by n_dot_h.
//**---------------------------------------------------------
float4 n_dot_l = dot( bump, normalized_light_vector );
float4 n_dot_h = dot( bump, normalized_half_angle );

//**--------------------------------------
//** Calculate the resulting pixel color,
//** based on our lighting model.
//** Ambient + Diffuse + Specular
//**--------------------------------------
psOutStruct.color0.rgb =
( base * ambient * Ka ) +
( base * diffuse * Kd * max( 0, n_dot_l ) ) +
( specular * Ks * pow( max( 0, n_dot_h ), specular_power ) );
psOutStruct.color0.a = 1.0f; //** Set the alpha component manually

return psOutStruct; //** Return the resulting output struct
}


technique spec_bump
{
pass Single_Pass
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}
}



environment bumpmapping:
Code:
 
float Ka = { 0.9f }; //Gesamthelligkeit
float reflectance = { 0.5f }; //Stärke des Environment Mappings
float specular_power = { 64.0f }; //Stärke des Lichts (1 = stark, über 1 = schwächer)
float bumpiness = { 0.8f }; //Stärke des Bump Mappings
float4 ambient = { 1.0f, 1.0f, 1.0f, 1.0f }; //Ambient Farbe
float4 diffuse = { 0.839216f, 0.863241f, 0.890411f, 1.0f }; //Diffuse Farbe
float4 specular = { 1.0f, 0.956737f, 0.670380f, 1.0f}; //Specular Farbe


float Kd = { 1.0f };
float Ks = { 1.0f };
float reflection_clarity = { 3.0f };

texture mtlSkin1;
texture mtlSkin2;

texture entSkin1;
texture entSkin2;

float4x4 matWorldViewProj: register(c0);
float4 vecSunDir: register(c8);
float4 vecViewPos: register(c9);
float4x4 matWorldView: register(c10);
float4x4 matViewInv;
float4x4 matMtl;
float4 vecAmbient;


struct VS_INPUT_STRUCT
{
float4 position: POSITION;
float3 normal: NORMAL;
float2 texcoord0: TEXCOORD0;
float3 binormal: TEXCOORD1;
float3 tangent: TEXCOORD2;
};

struct VS_OUTPUT_STRUCT
{
float4 position: POSITION;
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
float3 basis1: TEXCOORD3;
float3 basis2: TEXCOORD4;
float3 basis3: TEXCOORD5;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: VS_INPUT_STRUCT, derived from the stream
//** mapping parameters defined in the workspace
//** Returns: VS_OUTPUT_STRUCT
//**---------------------------------------------------------
VS_OUTPUT_STRUCT VS( VS_INPUT_STRUCT vsInStruct )
{
VS_OUTPUT_STRUCT vsOutStruct; //** Declare the output struct

vsOutStruct.position = mul(vsInStruct.position, matWorldViewProj );
float3 position = mul( vsInStruct.position, matViewInv );

//**----------------------------------------------
//** Pass the bump and base texture coords through
//**----------------------------------------------
vsOutStruct.bump_map = vsInStruct.texcoord0;

//**--------------------------------------------
//** Calculate the light vector in object space,
//** and then transform it into texture space.
//**--------------------------------------------
float3 temp_light_position = mul( vecAmbient, matMtl );
float3 temp_light_vector = temp_light_position - vsInStruct.position;
vsOutStruct.light_vector.x = dot( temp_light_vector, vsInStruct.tangent );
vsOutStruct.light_vector.y = dot( temp_light_vector, vsInStruct.binormal );
vsOutStruct.light_vector.z = dot( temp_light_vector, vsInStruct.normal );

//**-------------------------------------------
//** Calculate the view vector in object space,
//** and then transform it into texture space.
//**-------------------------------------------
float3 temp_eye_position = mul( vecViewPos, matMtl );
float3 temp_view_vector = temp_eye_position - vsInStruct.position;
float3 temp_view_vector2;
temp_view_vector2.x = dot( temp_view_vector, vsInStruct.tangent );
temp_view_vector2.y = dot( temp_view_vector, vsInStruct.binormal );
temp_view_vector2.z = dot( temp_view_vector, vsInStruct.normal );

//**-------------------------
//** Calculate the half angle
//**-------------------------
vsOutStruct.half_angle = vsOutStruct.light_vector + temp_view_vector2;

//**-----------------------------------------
//** Construct the transpose of the tangent
//** space basis vectors, so we can transform
//** the reflection vector from texture space
//** into view space
//**-----------------------------------------
vsOutStruct.basis1.x = vsInStruct.tangent.x;
vsOutStruct.basis1.y = vsInStruct.binormal.x;
vsOutStruct.basis1.z = vsInStruct.normal.x;
vsOutStruct.basis2.x = vsInStruct.tangent.y;
vsOutStruct.basis2.y = vsInStruct.binormal.y;
vsOutStruct.basis2.z = vsInStruct.normal.y;
vsOutStruct.basis3.x = vsInStruct.tangent.z;
vsOutStruct.basis3.y = vsInStruct.binormal.z;
vsOutStruct.basis3.z = vsInStruct.normal.z;

return vsOutStruct; //** Return the resulting output struct
}


sampler base_map = sampler_state
{
texture=(entSkin1);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

sampler bump_map = sampler_state
{
texture=(entSkin2);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

sampler environment_map = sampler_state
{
texture=(mtlSkin2);
};

struct PS_INPUT_STRUCT
{
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
float3 basis1: TEXCOORD3;
float3 basis2: TEXCOORD4;
float3 basis3: TEXCOORD5;
};

struct PS_OUTPUT_STRUCT
{
float4 color0: COLOR0;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: PS_INPUT_STRUCT, derived from the output of
//** the associated vertex shader
//** Returns: PS_OUTPUT_STRUCT
//**---------------------------------------------------------
float4x4 matWorldViewInv;

PS_OUTPUT_STRUCT PS( PS_INPUT_STRUCT psInStruct )
{
PS_OUTPUT_STRUCT psOutStruct;

//**----------------------------------------
//** Get the base and bump map texture coord
//**----------------------------------------
float4 bump_coord = { psInStruct.bump_map, 0.0f, reflection_clarity };

//**------------------------------------------------------
//** Retreive the base color and bump components from the
//** respective textures, based on the passed bump coords.
//**------------------------------------------------------
float3 base = tex2D( base_map, bump_coord );
float3 bump = tex2D( bump_map, bump_coord );

//**--------------------------------------------------
//** Includes MIP bias to help clairify the reflection
//**--------------------------------------------------
float3 reflection_bump = tex2Dbias( bump_map, bump_coord );

//**----------------------------------------------------
//** Normalize the passed vectors from the vertex shader
//**----------------------------------------------------
float3 normalized_light_vector = normalize( psInStruct.light_vector );
float3 normalized_half_angle = normalize( psInStruct.half_angle );

//**--------------------------------------------------------
//** "Smooth out" the bumps based on the bumpiness parameter.
//** This is simply a linear interpolation between a "flat"
//** normal and a "bumped" normal. Note that this "flat"
//** normal is based on the texture space coordinate basis.
//**--------------------------------------------------------
float3 smooth;
smooth.r = 0.5f;
smooth.g = 0.5f;
smooth.b = 1.0f;
bump = lerp( smooth, bump, bumpiness );
bump = normalize( ( bump * 2.0f ) - 1.0f );
reflection_bump = lerp( smooth, reflection_bump, bumpiness );
reflection_bump = normalize( ( reflection_bump * 2.0f ) - 1.0f );

//**---------------------------------------------
//** Translate the reflection normal from texture
//** space into view space, so we can case the
//** reflection vector into an environment map.
//**---------------------------------------------
float3 reflection = reflection_bump;
reflection.x = dot( reflection_bump, psInStruct.basis1 );
reflection.y = dot( reflection_bump, psInStruct.basis2 );
reflection.z = dot( reflection_bump, psInStruct.basis3 );
float3 reflection_vector = mul( matMtl, reflection );
reflection_vector = normalize( reflection_vector );

//**------------------------------------------
//** Calculate the resulting reflection color.
//**------------------------------------------
float3 reflection_color = texCUBE( environment_map, reflection_vector );

//**----------------------------------------------------------
//** The following modifiers are used to enhance the effect of
//** the basic reflection idea. Normally, specular / gloss
//** maps will take the place of these modifiers.
//**----------------------------------------------------------
float3 result_color = lerp( base, reflection_color, base * reflectance );
float3 modified_specular_color = specular * base;
float3 modified_specular_coefficient = Ks * base;

//**---------------------------------------------------------
//** These dot products are used for the lighting model
//** equations. The surface normal dotted with the light
//** vector is denoted by n_dot_l. The normal vector
//** dotted with the half angle vector is denoted by n_dot_h.
//**---------------------------------------------------------
float3 n_dot_l = dot( bump, normalized_light_vector );
float3 n_dot_h = dot( bump, normalized_half_angle );

//**--------------------------------------
//** Calculate the resulting base color,
//** based on our lighting model.
//** Ambient + Diffuse + Specular
//**--------------------------------------
psOutStruct.color0.rgb =
( result_color * ambient * Ka ) +
( result_color * diffuse * Kd * max( 0, n_dot_l ) ) +
( modified_specular_color * modified_specular_coefficient * pow( max( 0, n_dot_h ), specular_power ) );

//**------------------------------------
//** Interpolate the resulting color
//** based on the reflectance parameter.
//**------------------------------------
psOutStruct.color0.a = 1.0f; //** Set the alpha component manually

return psOutStruct; //** Return the resulting output struct
}

technique env_bump
{
pass Single_Pass
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}
}




www.easyparticle.com Das Leben ist ein scheiß Spiel. Aber die Grafik ist verdammt Geil!
Page 2 of 2 1 2

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