Sign in to follow this  
Yoyoyoyo

Little advice on XNA HLSL

Recommended Posts

Hi, ive just started on HLSL and ive looked through every tutorial on the subject, but it's not clicking for me.

I just want to add a directional light and have my normals that are already generated spring into action.

Here's my effect code;
[code]

float4x4 World;
float4x4 View;
float4x4 Projection;

// TODO: add effect parameters here.

float AmbientIntensity = 1.9;
float4 AmbientColor = float4(0.5,0.5,0.8,1);

Texture mytexture;

sampler ColoredTextureSampler = sampler_state
{

texture = <mytexture> ;
magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;
AddressU = mirror; AddressV = mirror;

};






struct VertexShaderInput
{
float4 Position : POSITION0;

// TODO: add input channels such as texture
// coordinates and vertex colors here.

float2 textureCoordinates : TEXCOORD0;
float4 AmbientColor : COLOR0;
float AmbientIntensity :COLOR1;
float2 UV : TEXCOORD1;
float3 Normal : TEXCOORD2;


};





struct VertexShaderOutput
{
float4 Position : POSITION0;

// TODO: add vertex shader outputs such as colors and texture
// coordinates here. These values will automatically be interpolated
// over the triangle, and provided as input to your pixel shader.


float2 textureCoordinates : TEXCOORD0;



};






VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);

// TODO: add your vertex shader code here.


output.textureCoordinates = input.textureCoordinates;



return output;
}







float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
// TODO: add your pixel shader code here.

float4 output = tex2D(ColoredTextureSampler, input.textureCoordinates) *(AmbientColor * AmbientIntensity);
//output.AmbientColor *AmbientIntensity;
return output;








//return float4(0.8, 0.6, 0.3, 1);
}


technique Technique1
{
pass Pass1
{
// TODO: set renderstates here.

VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}


[/code]


If anyone can suggest where and how i'd add the code for a directional light it would be much appreciated!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this