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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (alibaba, vicknick), 1,492 guests, and 4 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
Normal Mapping Shader ändern #186830
03/03/08 16:55
03/03/08 16:55
Joined: Jul 2006
Posts: 63
Deutschland
T
Tecizo Offline OP
Junior Member
Tecizo  Offline OP
Junior Member
T

Joined: Jul 2006
Posts: 63
Deutschland
Ich benutze den Normal Mapping Shader von Guitar und habe ein Problem mit der Sonne. Damit die Sonne angezeigt wird wird der Specular Wert verändert. Aber wenn ich ein Material ohne Specular benutzen möchte klappt das ja nicht da die Sonne dann nicht angezeigt wird. Ich kenn mich in dem bereich Shadder überhaupt nicht aus und wollte fragen ob mir jemand helfen kann dies zu verändern.

wdl Datei
Code:

function effect_startup()
{
effect_load(mat_NM, fxNM);
var SLF;
while(1)
{
SLF = 0;
ifdef staAmb;
SLF += 1;
endif;
ifdef staFake;
SLF += 2;
endif;
vec_set(mat_NM.specular_blue, sun_color);
mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888);
wait(1);
}
}



fx DAtei
Code:

//--------------------------------------------------------------
// Normal Mapping Shader
//
// Matt_Aufderheide, Bloodline, William, xXxGuitar511
// -------------------------------------------------------------

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewPos;
float4 vecFog;
float3 vecSunDir;
float4 vecLightPos[8];
float4 vecLightColor[8];
float4 mtlSkill1;
float4 vecAmbient;
float4 vecDiffuse;
float4 vecSpecular;
float4 vecEmissive;
float4 vecLight;
float fAmbient;
float fAlpha;
float fAlbedo;

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


float doFog(float3 WPos)
{
return(1 - (distance(WPos, vecViewPos) - vecFog.x) * (vecFog.z));
}


// -------------------------------------------------------------
// Pass 1
// -------------------------------------------------------------

struct VS_INPUT1
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
float3 Tangent : TEXCOORD2;
};

struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float3 Sun : TEXCOORD2;
float4 Light1 : TEXCOORD3;
float Fog : FOG;
};

struct PS_INPUT1
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float3 Sun : TEXCOORD2;
float4 Light1 : TEXCOORD3;
};


VS_OUTPUT1 VS_PASS1(VS_INPUT1 In)
{
VS_OUTPUT1 Out = (VS_OUTPUT1)0;
Out.Pos = mul(In.Pos, matWorldViewProj);
float3 PosWorld = mul(In.Pos, matWorld);
Out.Fog = doFog(PosWorld);
Out.Tex = In.Tex;

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

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, -Viewer);

// Sun
Out.Sun = mul(worldToTangentSpace, -vecSunDir);

// Light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1);
Out.Light1.w = length(Light1)/vecLightPos[0].w;

return Out;
}

float4 PS_PASS1(PS_INPUT1 In) : COLOR
{

float4 inColor = tex2D(ColorMapSampler, In.Tex) * vecDiffuse;
float4 outColor = tex2D(BumpMapSampler, In.Tex);
float3 bumpNormal = 2*outColor.xyz - 1;
float gloss = outColor.w * fAlbedo;
float3 ViewDir = normalize(In.View);
outColor = 0;

float3 sunDir = normalize(In.Sun);
float4 sunDiff = saturate(dot(bumpNormal, sunDir));
float4 sunShadow = saturate(4 * sunDiff);
float3 sunReflect = normalize(2 * sunDiff * bumpNormal - sunDir);
float4 sunSpec = pow(saturate(dot(sunReflect, ViewDir)), 15);
float4 sunOut = (inColor*sunDiff + sunSpec*gloss) * sunShadow * vecSpecular;

float4 ambOut = 0;
float SLF = round(mtlSkill1.a*10);
if (SLF == 2 || SLF == 3)
{ambOut += (inColor*sunDiff*vecLight*vecEmissive*3 + sunSpec*gloss*length(vecLight)) * sunShadow;}
if (SLF == 1 || SLF == 3)
{ambOut += vecLight*vecEmissive*inColor;}

outColor = ambOut;

float4 Light1 = In.Light1;
float3 LightDir1 = normalize(Light1.xyz);
float4 diff1 = saturate(dot(bumpNormal, LightDir1));
float4 shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1);
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir)), 15);
float4 Att1 = saturate(dot(Light1.w, Light1.w));

outColor = (vecAmbient + fAmbient)*inColor + sunOut + ambOut +
(shadow1 * (inColor * diff1 + (spec1*gloss)) * (1 - Att1))*vecLightColor[0];
outColor.a = inColor.a * fAlpha;

return outColor;
}


// -------------------------------------------------------------
// Pass 2
// -------------------------------------------------------------

struct VS_INPUT2
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
float3 Tangent : TEXCOORD2;
};

struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float4 Light2 : TEXCOORD2;
float4 Light3 : TEXCOORD3;
};

struct PS_INPUT2
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float4 Light2 : TEXCOORD2;
float4 Light3 : TEXCOORD3;
};


VS_OUTPUT2 VS_PASS2(VS_INPUT2 In)
{
VS_OUTPUT2 Out = (VS_OUTPUT2)0;
Out.Pos = mul(In.Pos, matWorldViewProj);
float3 PosWorld = mul(In.Pos, matWorld);
Out.Tex = In.Tex;

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

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, - Viewer);

// light 2
float3 Light2 = PosWorld - vecLightPos[1];
Out.Light2.xyz = mul(worldToTangentSpace, -Light2);
Out.Light2.w = length(Light2)/vecLightPos[1].w;

// light 3
float3 Light3 = PosWorld - vecLightPos[2] ;
Out.Light3.xyz = mul(worldToTangentSpace, -Light3);
Out.Light3.w = length(Light3)/vecLightPos[2].w;

return Out;
}

float4 PS_PASS2(PS_INPUT2 In) : COLOR
{

float4 inColor = tex2D(ColorMapSampler, In.Tex);
float4 outColor = tex2D(BumpMapSampler, In.Tex);
float3 bumpNormal = 2*outColor.xyz - 1;
float gloss = outColor.w * fAlbedo;
float3 ViewDir = normalize(In.View);
outColor = 0;

//light2
float4 Light2 = In.Light2;
float3 LightDir2 = normalize(Light2.xyz);
float4 diff2 = saturate(dot(bumpNormal, LightDir2));
float4 shadow2 = saturate(4 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2);
float4 spec2 = pow(saturate(dot(Reflect2, ViewDir)), 15);
float4 Att2 = saturate(dot(Light2.w, Light2.w));

//light3
float4 Light3 = In.Light3;
float3 LightDir3 = normalize(Light3.xyz);
float4 diff3 = saturate(dot(bumpNormal, LightDir3));
float4 shadow3 = saturate(4 * diff3);
float3 Reflect3 = normalize(2 * diff3 * bumpNormal - LightDir3);
float4 spec3 = pow(saturate(dot(Reflect3, ViewDir)), 15);
float4 Att3 = saturate(dot(Light3.w, Light3.w));

outColor += ((shadow2 * (inColor * diff2 + (spec2*gloss)) * (1 - Att2))*vecLightColor[1]);
outColor += ((shadow3 * (inColor * diff3 + (spec3*gloss)) * (1 - Att3))*vecLightColor[2]);
outColor.a = inColor.a;
return outColor;
}


// -------------------------------------------------------------
// Render
// -------------------------------------------------------------

technique SpecularNormalMapping_20
{
pass P1
{
alphaBlendEnable = false;
srcBlend = zero;
//
VertexShader = compile vs_2_0 VS_PASS1();
PixelShader = compile ps_2_0 PS_PASS1();
}
//
pass P2
{
alphaBlendEnable = true;
alphaTestEnable = true;
srcBlend = One;
destBlend = One;
fogEnable = false;
VertexShader = compile vs_2_0 VS_PASS2();
PixelShader = compile ps_2_0 PS_PASS2();
}
}



Re: Normal Mapping Shader ändern [Re: Tecizo] #186831
03/03/08 21:00
03/03/08 21:00
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
I don't speak much german, I'm still learning...

...You want to change the shader so that it does not use the specular channel for the sun?


xXxGuitar511
- Programmer
Re: Normal Mapping Shader ändern [Re: xXxGuitar511] #186832
03/04/08 14:19
03/04/08 14:19
Joined: Jul 2006
Posts: 63
Deutschland
T
Tecizo Offline OP
Junior Member
Tecizo  Offline OP
Junior Member
T

Joined: Jul 2006
Posts: 63
Deutschland
Yes I want to use this shader with without the specular channel. But I can't set it to 0 because then there is no sun.

Re: Normal Mapping Shader ändern [Re: Tecizo] #186833
03/04/08 16:53
03/04/08 16:53
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline
Serious User
Dark_samurai  Offline
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
It's logical that you can't see a highlight on the surface of the model when you set it to 0. Or did I missunderstood you?

Dark_Samurai


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version
Re: Normal Mapping Shader ändern [Re: Dark_samurai] #186834
03/04/08 19:34
03/04/08 19:34
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
...Let me look into my shader for more details...

First option would be to reduce the alpha of your normal map. The specular channel does not control specularity (strange, I know). Instead, the alpha channel of the normal map is used to give you per-pixel access...


xXxGuitar511
- Programmer
Re: Normal Mapping Shader ändern [Re: xXxGuitar511] #186835
03/05/08 12:24
03/05/08 12:24
Joined: Jul 2006
Posts: 63
Deutschland
T
Tecizo Offline OP
Junior Member
Tecizo  Offline OP
Junior Member
T

Joined: Jul 2006
Posts: 63
Deutschland
@Dark_samurai
If I set the specular to 0 I can't see the on this model. With the other lights I haven't any problem.

@xXxDisciple
Thank you it seems work.

Re: Normal Mapping Shader ändern [Re: Tecizo] #186836
03/05/08 14:15
03/05/08 14:15
Joined: Jul 2006
Posts: 63
Deutschland
T
Tecizo Offline OP
Junior Member
Tecizo  Offline OP
Junior Member
T

Joined: Jul 2006
Posts: 63
Deutschland
I have found one more problem. What can I do if I want to change the specular chanel dynamic?

Re: Normal Mapping Shader ändern [Re: Tecizo] #186837
03/06/08 07:05
03/06/08 07:05
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
...I used a certain variable to control the overall specularity of a model, but I don't remember what it is. Let me look again...

Quote:

- Albedo property of model controls its specularity (glossyness) in addition to the alpha channel of the normal map




...Found it


xXxGuitar511
- Programmer
Re: Normal Mapping Shader ändern [Re: xXxGuitar511] #186838
03/06/08 12:20
03/06/08 12:20
Joined: Jul 2006
Posts: 63
Deutschland
T
Tecizo Offline OP
Junior Member
Tecizo  Offline OP
Junior Member
T

Joined: Jul 2006
Posts: 63
Deutschland
Yes! It works. Thanks!


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