Original Post
Hello ok heres my problem... i create a mesh from xfile... fine i place it in the world....fine i use Vertex/Pixelshader 3.0, but im very new to that :) it changes Lightning when scaled... scale bigger gets brighter scale smaller gets darker with FixedFunction Pipe i can use Renderstate.NormalizeNormals how can i use that in my shader?
IMG I'm sure it something very simple.... heeelp
IMG
static const int MAX_LIGHTS = 20;
//--------------------------------------------------------------------------------------
// Variables from Outer Space
//--------------------------------------------------------------------------------------
//Matrizen
float4x4 eff_World : WORLD; // World
float4x4 eff_VP : VIEWPROJECTION; // View + Projektion
//Materials
float4 eff_MaterialAmbient : MATERIALAMBIENT; // Material's ambient color
float4 eff_MaterialDiffuse : MATERIALDIFFUSE; // Material's diffuse color
//Light
float4 eff_LightAmbient; // Ambient Light
float4 eff_LightDiffuse[MAX_LIGHTS]; // Array of Light's diffuse color
float4 eff_LightPosition[MAX_LIGHTS]; // Array Light's Position in world space
//Texture
bool eff_HasTexture;
texture eff_Texture1; // Color texture for mesh
int eff_NumberLights = 1;
//--------------------------------------------------------------------------------------
// Texture samplers
//--------------------------------------------------------------------------------------
sampler MeshTextureSampler = sampler_state
{
Texture = <eff_Texture1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
struct VSTEXTURE_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR;
float2 TexCoord : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
VSTEXTURE_OUTPUT VSTexture(
float4 VertexPosition : POSITION,
float3 VertexNormal : NORMAL,
float2 VertexTexCoord : TEXCOORD0
)
{
VSTEXTURE_OUTPUT Out;
//-----------------------------------------------------------------------------
//Calc VertexPosition + Normale
//-----------------------------------------------------------------------------
// position (view space)
float4 tPositionWorldSpace = mul( VertexPosition, eff_World);
// Normal (World)
float3 tNormalWorldSpace = mul(VertexNormal, (float3x3)eff_World);
//-----------------------------------------------------------------------------
// scan Lights and calculate total Diffuse
//-----------------------------------------------------------------------------
float4 vTotalLightDiffuse = float4(0,0,0,0);
float power =2;
for(int i=0; i<eff_NumberLights; i++ )
{
float3 tNormalLightDir = normalize(tPositionWorldSpace - eff_LightPosition[0]);
float4 LightFact = max(0,dot( tNormalWorldSpace, -tNormalLightDir));
// Look here....Calculating Lightning
// Baselight(Ambiente) + Ambiente * AmbLight + Diffuse * DiffLight
// Thought it has to be:
// Ambiente * AmbLight + Diffuse * DiffLight
// but its soooo dark
vTotalLightDiffuse.rgb += eff_LightAmbient * LightFact * power
+ eff_MaterialAmbient * eff_LightAmbient * LightFact*power
+ eff_MaterialDiffuse * eff_LightDiffuse * LightFact*power;
}
//-----------------------------------------------------------------------------
// Output Section
//-----------------------------------------------------------------------------
// position transformed to View+Projecion
Out.Position = mul(tPositionWorldSpace, eff_VP);
Out.Diffuse.a = eff_MaterialDiffuse.a;
Out.Diffuse.rgb = vTotalLightDiffuse;
//-----------------------------------------------------------------------------
// TextureCoords, only pass through
//-----------------------------------------------------------------------------
if ( eff_HasTexture )
{
Out.TexCoord = VertexTexCoord;
}
else
{
Out.TexCoord =0;
}
return Out;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Pixel shader Input structure
//--------------------------------------------------------------------------------------
struct PS_INPUT
{
float2 TextureUV : TEXCOORD0;
float4 Diffuse : COLOR0;
};
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Pixel shader output structure
//--------------------------------------------------------------------------------------
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};
//--------------------------------------------------------------------------------------
//PIXEL SHADER
//--------------------------------------------------------------------------------------
PS_OUTPUT RenderScenePS( PS_INPUT In)
{
PS_OUTPUT Output;
// Lookup mesh texture and modulate it with diffuse
if( eff_HasTexture )
{
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
}
else
{
Output.RGBColor = In.Diffuse;
}
return Output;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique TSkinOnly
{
pass P0
{
VertexShader = compile vs_3_0 VSTexture();
PixelShader = compile ps_3_0 RenderScenePS();
}
}