Jump to content
  • Advertisement
Sign in to follow this  

Little advice on XNA HLSL

This topic is 2611 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

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;

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();

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
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!