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 (BrainSailor), 862 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Problems with Bump Mapping Shader #80528
07/06/06 18:55
07/06/06 18:55
Joined: Oct 2004
Posts: 150
Germany
T
tkunze Offline OP
Member
tkunze  Offline OP
Member
T

Joined: Oct 2004
Posts: 150
Germany
Hello,

currently i try to port an bumpmapping shader but i am not able to get a good result. My problem are the 2 lines in the vertex shader (marked in red)where in the original implementation vecLightDir and vecEye is used. I tried to map this to vecSunDir, vecViewDir ... but i always get a result like shown in the pictures above.

The next problem is the roof of the house model. It is tiled into 6 surfaces, pointing to the same area in the texture.

The shader calculates the light impact for each area and not for the whole roof (The lightning is for each surface dark on the upper right side and bright on the lower left side and not for the whole roof). Is there something what can be changed in the shader or is it necessary that the roof is only one surface to get the proper light calculation.

The demo project can be downloaded with Link to BumpMapping Shader (10 MB).

Any help is appreciated.





Code:
  material bumpmapping_version2 {

effect
"
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Define your needed values
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLight;
float4 vecSunDir;
float4 vecViewDir;
float4 vecViewPos;

// Define your textures
texture entSkin1;
texture entSkin2;

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};

sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};


// Define the output of your vertexshader
struct VS_OUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 View : TEXCOORD2;
};

struct VS_IN
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
};

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 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

float3x3 worldToTangentSpace;

worldToTangentSpace[0]=mul(In.Tangent, matWorld);
worldToTangentSpace[1]=mul(cross(In.Tangent,In.Normal), matWorld);
worldToTangentSpace[2]=mul(In.Normal, matWorld);

Out.Tex=In.Tex;

float4 PosWorld = mul(In.Pos, matWorld);

Out.Light = mul(worldToTangentSpace, vecLight);
// In the Original Shader: Out.Light = mul(worldToTangentSpace, vecLightDir);

Out.View = mul(worldToTangentSpace, vecViewPos - PosWorld);
// In the Original Shader: Out.View = mul(worldToTangentSpace, vecEye - PosWorld);


return Out;
}


float4 ps(
float2 Tex : TEXCOORD0,
float3 Light: TEXCOORD1,
float3 View : TEXCOORD2
) : COLOR
{
float4 Color = tex2D(ColorMapSampler, Tex);
float3 Normal = (2*(tex2D(BumpMapSampler,Tex)))-1.0;

float3 LightDir = normalize(Light);
float3 ViewDir = normalize(View);

float Diffuse=saturate(dot(Normal,LightDir));

float3 Reflect = normalize(2*Diffuse * Normal - LightDir);

float Specular = pow(saturate(dot(Reflect,ViewDir)),3);

return 0.2 * Color + Color * Diffuse + Specular;
}

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



Re: Problems with Bump Mapping Shader [Re: tkunze] #80529
07/06/06 20:44
07/06/06 20:44
Joined: Mar 2005
Posts: 969
ch
Loopix Offline
User
Loopix  Offline
User

Joined: Mar 2005
Posts: 969
ch
welding the vertices in MED should indeed solve the lighting issue (in the top middle of the roof, some vertices still need to be merged). For getting a softer, less agressive specularity...I hope one of the shader gurus can help

Thats what I got with some slight code tweaking and vertex welding


Re: Problems with Bump Mapping Shader [Re: Loopix] #80530
07/06/06 21:05
07/06/06 21:05
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
float Specular = pow(saturate(dot(Reflect,ViewDir)),3);

Alter this line to have more or less specularity.


Follow me on twitter
Re: Problems with Bump Mapping Shader [Re: Loopix] #80531
07/06/06 21:09
07/06/06 21:09
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
That however doesnt address the underlying problem...

You are probably not passing in a correct tangent. This is likely because your material is not set up right--you need to have something like this:

material normalmap
{
flags=tangent;
....
}

then in your effect change the tangent input definition from
float3 Tangent : TANGENT;

to
float3 Tangent : TEXCOORD2;

also, the "vecLight" variable is NOT a light direction or position vector, it's a rgb color. You should use vecSunDir (which is a normnalized direction vector)


Sphere Engine--the premier A6 graphics plugin.
Re: Problems with Bump Mapping Shader [Re: Matt_Aufderheide] #80532
07/27/06 17:37
07/27/06 17:37
Joined: Jun 2006
Posts: 11
V
versus2 Offline
Newbie
versus2  Offline
Newbie
V

Joined: Jun 2006
Posts: 11
bumpmap1 code works for me
but bumpmap2 produces just a black surface
what´s wrong??

Re: Problems with Bump Mapping Shader [Re: versus2] #80533
08/12/06 12:31
08/12/06 12:31
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline
User
sheefo  Offline
User

Joined: Jul 2006
Posts: 783
London, UK
Try this code, I took it from the normalmap shaders and took away everything apart from the bumpmapping stuff:
Code:

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8]; //light position
float4 vecLightColor[8]; //light position
float4 vecViewPos;

texture entSkin1;
texture entSkin2;

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};

struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light : TEXCOORD2;
float3 View : TEXCOORD3;
float3 Att : TEXCOORD4;
};
VS_OUTPUT vs(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);
float LightRange = 0.00001;
//light 1
float3 Light = PosWorld - vecLightPos[1] ;
Out.Light.xyz = mul(worldToTangentSpace, -Light); // L
float3 Viewer1 = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, -Viewer1); // V
Out.Att = Light * LightRange; // Point light
return(Out);
}
struct PS_INPUT
{
float2 Tex : TEXCOORD0;
float3 Light : TEXCOORD2;
float3 View : TEXCOORD3;
float3 Att : TEXCOORD4;
};
float4 ps(PS_INPUT psInStruct) : COLOR
{
float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D(BumpMapSampler, psInStruct.Tex);
//light1
float3 LightDir1 = normalize(psInStruct.Light);
float3 ViewDir1 = normalize(psInStruct.View);
float4 diff1 = saturate(dot(bumpNormal, LightDir1)); // diffuse component
float shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1); // R
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);
float4 Attenuation1 = saturate(dot(psInStruct.Att, psInStruct.Att));

return((0.3 * color) + ((shadow1 * (color * diff1 + (spec1 * gloss.w)) * (1 - Attenuation1)) * vecLightColor[1]));
}
////////////////////////////////////////////////////////////
// Bumpmap
////////////////////////////////////////////////////////////
technique bumpmap
{
pass p0
{
AlphaBlendEnable = false;
SrcBlend = zero;

VertexShader = compile vs_2_0 vs();
PixelShader = compile ps_2_0 ps();
}
}



Re: Problems with Bump Mapping Shader [Re: sheefo] #80534
08/17/06 19:06
08/17/06 19:06
Joined: Jun 2006
Posts: 11
V
versus2 Offline
Newbie
versus2  Offline
Newbie
V

Joined: Jun 2006
Posts: 11
same result..

Re: Problems with Bump Mapping Shader [Re: versus2] #80535
08/17/06 19:55
08/17/06 19:55
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline
User
sheefo  Offline
User

Joined: Jul 2006
Posts: 783
London, UK
I might now a way. We can do the same for the watershader, take everything away apart from the bumpmapping code...?


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