Gamestudio Links
Zorro Links
Newest Posts
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
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (ozgur, TipmyPip, AndrewAMD), 1,209 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Normalmap with alpha tga #46368
05/21/05 14:08
05/21/05 14:08
Joined: Sep 2003
Posts: 271
Germany
Chris3D Offline OP
Member
Chris3D  Offline OP
Member

Joined: Sep 2003
Posts: 271
Germany
Hello!
I have leaf-panels for a tree, and their textur has an alpha channel, so that a part of the textur is transparent. NOW, I give the panels my normalmap shader and they lose their transparency. So my question is how should I change my code to get the transparency of the alpha channel, with normalmapping?
Please help me, this is very relevant for my game!!!
Here is the standard fx code for normalmapping(only some unimportant things were changed):
Code:
 float4x4 matViewInv;

float3x3 WldToTan;

float4 vecViewPos;
float4 vecViewDir;

float4 vecLight;
float4 vecLightPos[8];
float4 vecLightColor[8];


texture entSkin1;
texture entSkin2;

dword mtlSkill1;

matrix matWorldViewProj;
matrix matWorld;
matrix matMtl;
matrix matWorldViewProjInv;

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

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

struct VS_OUTPUT
{
float4 oPosition : POSITION;
float2 Tex : TEXCOORD0;
float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;
};


VS_OUTPUT main_vs(float4 inPosition : POSITION, float2 inTex : TEXCOORD0, float3 inNormal : NORMAL, float3 inTangent : TEXCOORD2 )
{
VS_OUTPUT Out ;

Out.oPosition = mul(inPosition, matWorldViewProj);

WldToTan[0] = mul(inTangent, matWorld);
WldToTan[1] = mul(cross(inTangent, inNormal), matWorld);
WldToTan[2] = mul(inNormal, matWorld);

Out.Tex = inTex.xy*1; //Scale the texture UV's


float4 Pos_World = mul( inPosition, matWorld);

float LightRange1 = 0.0001;
float LightRange2 = 0.0001;

//light 1
float3 Light1 = Pos_World - vecLightPos[1];
Out.Light1.xyz = mul(WldToTan, -Light1);

float3 Viewer1 = Pos_World - vecViewDir;
Out.View1.xzy = mul(WldToTan, -Viewer1);

Out.Att1 = Light1 * LightRange1;
//light 2
float3 Light2 = Pos_World - vecLightPos[2];
Out.Light2.xyz = mul(WldToTan, -Light2);

float3 Viewer2 = Pos_World - vecViewDir;
Out.View2.xzy = mul(WldToTan, -Viewer2);

Out.Att2 = Light2 * LightRange2;

return Out;
}

struct PS_INPUT0
{
float2 Tex : TEXCOORD0;
float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;
float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;
};

float4 main_ps(PS_INPUT0 IN): COLOR
{

float3 ViewDir = normalize(IN.View1);
float4 color;
float3 bumpNormal;

float2 OffsetTex = IN.Tex;
color = tex2D(sColorMap, OffsetTex);
bumpNormal =(2 * (tex2D(sBumpMap, OffsetTex )))- 1.0;
float4 gloss = tex2D( sBumpMap, OffsetTex);

//light1
float3 LightDir1 = normalize(IN.Light1);
float3 ViewDir1 = normalize(IN.View1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1));
float shadow1 = saturate(2 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1);
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 8);
float4 Attenuation1 = saturate(dot(IN.Att1, IN.Att1));

//light2
float3 LightDir2 = normalize(IN.Light2);
float3 ViewDir2 = normalize(IN.View2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2));
float shadow2 = saturate(2 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2);
float4 spec2 = pow(saturate(dot(Reflect2,ViewDir2)), 8);
float4 Attenuation2 = saturate(dot(IN.Att2, IN.Att2));

return (
(0.2 * color) + //ambient
((shadow1 * (color * diff1 + (spec1)) * (1 -Attenuation1))*vecLightColor[1])+
((shadow2 * (color * diff2 + (spec2)) * (1 -Attenuation2))*vecLightColor[2])
);

//return (0.2 * color + color* diff1 * vecLightColor[1]+diff2 * vecLightColor[2]);

}


technique Parallax
{
pass P0
{
texture[0]=<entSkin1>;
zWriteEnable=true;
alphaBlendEnable=false;
alphaTestEnable=true;
DitherEnable = True;
alphaRef=<mtlSkill1>;
alphaFunc=greater;
srcblend=SRCALPHA;
destblend=DESTALPHA;
VertexShader = compile vs_2_0 main_vs();
PixelShader = compile ps_2_0 main_ps();
}
}



Re: Normalmap with alpha tga [Re: Chris3D] #46369
05/21/05 14:38
05/21/05 14:38
Joined: Mar 2005
Posts: 110
MI
paulshort Offline
Member
paulshort  Offline
Member

Joined: Mar 2005
Posts: 110
MI
I have the same problem with my toon shader...

Re: Normalmap with alpha tga [Re: paulshort] #46370
05/21/05 16:23
05/21/05 16:23
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
well the problem is you are trying to combine fixed functions with a pixel shader, this cant work because the pixel shader overrids your FF commands. Heres what you do:

get rid of the lest line in your pixel shader where it returns, and put this

Code:


float4 finalcolor =(0.2 * color) + ((shadow1 * (color * diff1 + (spec1)) * (1 -Attenuation1))*vecLightColor[1])+ ((shadow2 * (color * diff2 + (spec2)) * (1 -Attenuation2))*vecLightColor[2]));

finalcolor.a = color.a;

if (finalcolor.a>0.5)
{
finalcolor.a=1;
}

else
{
finalcolor.a=0.0;
}

return finalcolor;



Re: Normalmap with alpha tga [Re: Matt_Aufderheide] #46371
05/21/05 19:55
05/21/05 19:55
Joined: Sep 2003
Posts: 271
Germany
Chris3D Offline OP
Member
Chris3D  Offline OP
Member

Joined: Sep 2003
Posts: 271
Germany
Thanks Matt, you get credits!


website coming soon!

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