|
|
Re: Loading skins in real time
[Re: lostclimate]
#121184
04/03/07 18:25
04/03/07 18:25
|
Joined: Nov 2003
Posts: 1,659 San Francisco
JetpackMonkey
OP
Serious User
|
OP
Serious User
Joined: Nov 2003
Posts: 1,659
San Francisco
|
Quote:
well i can modify your script to use mtlskins instead of entskins and you can just use bmaps
Thanks for the link HeelX, that would be a teriffic feature. I am kind of surprised it isn't already implemented.
Lostclimate, wow is that difficult to modify? I just want a simple normalmapping shader that can do that... do you know of one out there for this?
Thanks for the tips! JPM
|
|
|
Re: Loading skins in real time
[Re: lostclimate]
#121186
04/03/07 21:13
04/03/07 21:13
|
Joined: Nov 2003
Posts: 1,659 San Francisco
JetpackMonkey
OP
Serious User
|
OP
Serious User
Joined: Nov 2003
Posts: 1,659
San Francisco
|
Oot thanks lostclimate, how about just using Bloodline's enhanced version of Matt's normal map shader? I'm new to normal map shaders, so if there is something that would be faster/lighter, I am open to recommendations. I really just want to put em into my game and see what it looks like and what kind of performance hit it would be. Thanks a ton! JPM Code:
// ------------------------------------------------------------- // Diffuse and specular shader for models // ------------------------------------------------------------- // [18/3/06 Bloodline] - Added ambient and a 3rd light
float4x4 matWorldViewProj; float4x4 matWorld; float4 vecLightPos[8]; //light position float4 vecLightColor[8]; //light color float4 vecViewPos;
// Change ambient here float4 Ambient = { 0.6f, 0.6f, 0.6f, 1.0f };
texture entSkin1; //this is the color map texture entSkin2; //this is the normal map
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; };
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //first pass /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------- // Output channels // ------------------------------------------------------------- struct VS_OUTPUT0 { float4 Pos : POSITION; float2 Tex : TEXCOORD0;
float3 Light1 : TEXCOORD2; float3 View1 : TEXCOORD3; float3 Att1 : TEXCOORD4;
float3 Light2 : TEXCOORD5; float3 View2 : TEXCOORD6; float3 Att2 : TEXCOORD7;
float3 Light3 : TEXCOORD8; float3 View3 : TEXCOORD9; float3 Att3 : TEXCOORD10;
};
// ------------------------------------------------------------- // vertex shader function (input channels) // ------------------------------------------------------------- VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 ) { VS_OUTPUT0 Out = (VS_OUTPUT0)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 = 1/vecLightPos[0].w; float LightRange2 = 1/vecLightPos[1].w; float LightRange3 = 1/vecLightPos[2].w;
//light 1 float3 Light1 = PosWorld - vecLightPos[0] ; Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L
float3 Viewer1 = PosWorld - vecViewPos; Out.View1 = mul(worldToTangentSpace, -Viewer1); // V
Out.Att1 = Light1 * LightRange; // Point light
//light 2 float3 Light2 = PosWorld - vecLightPos[1] ; Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L
float3 Viewer2 = PosWorld - vecViewPos; Out.View2 = mul(worldToTangentSpace, -Viewer2); // V
Out.Att2 = Light2 * LightRange2; // Point light
//light 3 float3 Light3 = PosWorld - vecLightPos[2] ; Out.Light3.xyz = mul(worldToTangentSpace, -Light3); // L
float3 Viewer3 = PosWorld - vecViewPos; Out.View3 = mul(worldToTangentSpace, -Viewer3); // V
Out.Att3 = Light3 * LightRange3; // Point light
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;
float3 Light3 : TEXCOORD8; float3 View3 : TEXCOORD9; float3 Att3 : TEXCOORD10;
};
float4 PS_PASS0( PS_INPUT0 psInStruct ):COLOR
{
float4 color = tex2D(sColorMap, psInStruct.Tex); // fetch color map float3 bumpNormal = 2 * (tex2D(sBumpMap, psInStruct.Tex) - 0.5); // fetch bump map float4 gloss = tex2D( sBumpMap, psInStruct.Tex );
//light1 float3 LightDir1 = normalize(psInStruct.Light1); float3 ViewDir1 = normalize(psInStruct.View1); 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.Att1, psInStruct.Att1));
//light2 float3 LightDir2 = normalize(psInStruct.Light2); float3 ViewDir2 = normalize(psInStruct.View2); float4 diff2 = saturate(dot(bumpNormal, LightDir2)); // diffuse component float shadow2 = saturate(4 * diff2); float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2); // R float4 spec2 = pow(saturate(dot(Reflect2, ViewDir2)), 15); float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));
//light3 float3 LightDir3 = normalize(psInStruct.Light3); float3 ViewDir3 = normalize(psInStruct.View3); float4 diff3 = saturate(dot(bumpNormal, LightDir3)); // diffuse component float shadow3 = saturate(4 * diff3); float3 Reflect3 = normalize(2 * diff3 * bumpNormal - LightDir3); // R float4 spec3 = pow(saturate(dot(Reflect3, ViewDir3)), 15); float4 Attenuation3 = saturate(dot(psInStruct.Att3, psInStruct.Att3));
return ( (0.1 * color + 0.2 * Ambient) + ((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])+ ((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])+ ((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[2]) ); }
// ------------------------------------------------------------- // techniques// // ------------------------------------------------------------- technique two_pass { pass P0 { alphablendenable=false; srcblend=zero;
VertexShader = compile vs_3_0 VS_PASS0(); PixelShader = compile ps_3_0 PS_PASS0(); }
}
|
|
|
Re: Loading skins in real time
[Re: JetpackMonkey]
#121187
04/03/07 22:25
04/03/07 22:25
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Try adding the mtlSkin's to the [NM] shader I posted in the UserContributions...
It works great, and it would only be a short/simple modification to switch to the mtlSkin's...
xXxGuitar511 - Programmer
|
|
|
|