Posted By: Tecizo
Normal Mapping Shader ändern - 03/03/08 16:55
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:
fx DAtei
Code:
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();
}
}