|
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn),
581
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: shader to(single)textures (mulititex model) in
[Re: broozar]
#84109
08/09/06 18:48
08/09/06 18:48
|
Joined: Jun 2005
Posts: 4,875
broozar
OP
Expert
|
OP
Expert
Joined: Jun 2005
Posts: 4,875
|
k what's wrong with it? fx: Code:
// ------------------------------------------------------------- // Diffuse and specular shader for models // ------------------------------------------------------------- //Only does sun light, no dynamic lights..
float4x4 matWorldViewProj; float4x4 matWorld; float4 vecViewPos; float4 vecFog; float4 vecSkill1;
float4 vecLight; float4 suncolor={0.8,0.8,0.7,0.0}; //define the suncolor here, couls al so pass it fomr the script in a mtl skill
texture mtlSkin1;//this is the color map with specular map in alpha ..32 bit texture mtlSkin2; //this is the normal map .. 24 bit
sampler ColorMapSampler = sampler_state { Texture = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; }; sampler BumpMapSampler = sampler_state { Texture = <mtlSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////// //sunlight /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------- // Output channels // ------------------------------------------------------------- struct VS_OUTPUT1 { float4 Pos : POSITION; float2 Tex : TEXCOORD0;
float3 View4 : TEXCOORD3; float3 Sun : TEXCOORD1; float Fog : FOG; }; // ------------------------------------------------------------- // vertex shader function (input channels) // ------------------------------------------------------------- VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 ) { VS_OUTPUT1 Out = (VS_OUTPUT1)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 ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z); // Out.Fog = ofog; Out.Fog = 10000;
float3 Viewer4 = PosWorld - vecViewPos; Out.View4 = mul(worldToTangentSpace, -Viewer4); // V
//sunlight Out.Sun.xyz = mul(worldToTangentSpace, vecSkill1); // L
return Out; } struct PS_INPUT1 { float2 Tex : TEXCOORD0; float3 View4 : TEXCOORD3; float3 Sun : TEXCOORD1; float Fog : FOG; }; // ------------------------------------------------------------- // Pixel Shader (input channels):output channel // ------------------------------------------------------------- float4 PS_PASS1( PS_INPUT1 psInStruct ):COLOR { float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map bumpNormal=normalize(bumpNormal);
float3 ViewDir4 = normalize(psInStruct.View4);
//sunlight float3 Sun = normalize(psInStruct.Sun); float4 diff7 = saturate(dot(bumpNormal, Sun)); // diffuse component float3 Reflect7 = normalize(2 * diff7 * bumpNormal - Sun); // R float4 spec7 = pow(saturate(dot(Reflect7, ViewDir4)), 15); float shadow7 = saturate(4 * diff7); return ( (vecLight * color) + //ambient
((shadow7* (color * diff7 + (spec7*color.w))) * suncolor) ); } // ------------------------------------------------------------- // techniques// // ------------------------------------------------------------- technique two_pass { pass P0 { alphablendenable=false; zenable=true; zwriteenable=true; //compile shaders VertexShader = compile vs_1_1 VS_PASS1(); PixelShader = compile ps_2_0 PS_PASS1(); } }
wdl: Code:
material wire{ effect="mtlly.fx"; skin1=front; skin2=front3d; flags=tangent; }
starter mtls{ wait(10); ent_mtlset (podL, wire, 5); wire.skill1=float(sun_pos.x); wire.skill2=float(sun_pos.z); wire.skill3=float(sun_pos.y); }
effect_load doesn't change anything.
|
|
|
Re: shader to(single)textures (mulititex model) in
[Re: broozar]
#84114
08/14/06 19:54
08/14/06 19:54
|
Joined: Aug 2005
Posts: 1,185 Ukraine
Lion_Ts
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,185
Ukraine
|
|
|
|
|