Jump to content
  • Advertisement
Sign in to follow this  
Icebone1000

My(?) first transform, light and texture shader

This topic is 3050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, can someone check my first basic shader..it looks its working ok, but my lights are inverted in some way..I have those lights : g_vLiteDir[0] = XMVectorSet( -0.577f, -0.577f, -0.577f, 1.0f ); g_vLiteDir[1] = XMVectorSet( 0.0f, 0.0f, -1.0f, 1.0f ); But the illuminations comes from the botom and front...? Why are those inverted? heres the shader, I just mixed it from the first fx tutorials from the dx10 sdk

//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------

cbuffer cbChangers{
	matrix mWorld;	//space transformations-WORLD
	float4 vLiteDir[2];//LIGHT DIRECTION
};
cbuffer cbConstants{
	matrix mView; //space transformations-VIEW
	matrix mProjection;//space transformations-PROJECTION
	float4 vLiteColor[2];//LIGHT COLOR
};


//resources
Texture2D tex2D;
SamplerState samLinear{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
    AddressV = Wrap;
};




struct VS_INPUT{
	float4 Pos : POSITION;
	float3 Norm : NORMAL;
	float2 Tex : TEXCOORD;
};

struct PS_INPUT{
	float4 Pos : SV_POSITION;
	float3 Norm : NORMAL;
	float2 Tex : TEXCOORD;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input_p )
{
	PS_INPUT vs_output = (PS_INPUT)0;

	vs_output.Pos = mul( input_p.Pos, mWorld );
	vs_output.Pos = mul( vs_output.Pos, mView );
	vs_output.Pos = mul( vs_output.Pos, mProjection );

	vs_output.Norm = mul( input_p.Norm, mWorld );

	vs_output.Tex = input_p.Tex;

	return vs_output;//SV_POSITION + TEXCOORD
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input_p ) : SV_TARGET
{

	float4 finalcolor = 0;

	//normal.lite for the 2 lites:(saturate keeps on the range 0-1)
	for( int i = 0; i<2; i++ ){
		finalcolor += saturate( dot( (float3)vLiteDir, input_p.Norm ) * vLiteColor );
	}
	finalcolor.a = 1;//alpha

	finalcolor *= tex2D.Sample( samLinear, input_p.Tex );


	return finalcolor;//SV_TARGET
}

//--------------------------------------------------------------------------------------
technique11 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}




Share this post


Link to post
Share on other sites
Advertisement
When you do N (dot) L, your L vector should point from the surface to the light. If you're providing your shader with the direction your light is facing, you'll need to negate that vector to get the results you expect.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!