Original Post
I read over how to do in the pplication and it seems right, but don't I have to change the HLSL too? What do I write there? I can't seem to find the details on MSDN.
//--------------------------------------------------------------------------------------
// File: EffectPool.fx
//
// Contains shared effect variables and functions that remain the same every frame
// for all effects.
//--------------------------------------------------------------------------------------
shared cbuffer Matrices
{
matrix view : View;
matrix projection : Projection;
};
shared cbuffer Lights
{
struct AmbientLight
{
float4 intensity;
float4 color;
};
struct DirectionalLight
{
bool enabled;
float4 direction;
float4 color;
};
AmbientLight ambientLight;
DirectionalLight directionalLights[8];
};
//--------------------------------------------------------------------------------------
// File: default.fx
//
//--------------------------------------------------------------------------------------
matrix World : World;
Texture2D textureDiffuse;
SamplerState samplerLinear
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
//////// CONNECTOR DATA STRUCTURES ///////////
/* Data from application vertex buffer */
struct VS_INPUT
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
/* Data passed from vertex shader to pixel shader */
struct PS_INPUT
{
float4 position : SV_POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Simply transforms positions and normals
//
PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;
// Transform the position
matrix worldViewProjection = mul(world, view);
worldViewProjection = mul(worldViewProjection, projection);
output.position = mul(input.position, worldViewProjection );
// Transform the normal
output.normal = mul(input.normal, world);
normalize(output.normal);
// Copy the UV
output.uv = input.uv;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shaders
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Shades an object using 2 colored directional lights
//
float4 PS( PS_INPUT input ) : SV_Target
{
finalColor = textureDiffuse.Sample(samplerLinear, input.uv);
finalColor.a = 1;
return finalColor;
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Renders an object using 2 directional lights
//
technique10 Render
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}