All pastes #2066327 Raw Edit

Something

public text v1 · immutable
#2066327 ·published 2011-05-21 19:00 UTC
rendered paste body
// Camera settings.
float4x4 World;
float4x4 View;
float4x4 Projection;

// The light direction is shared between the Lambert and Toon lighting techniques.
float3 LightDirection = normalize(float3(1, 0.4, 0.2));

// Settings controlling the Lambert lighting technique.
float3 DiffuseLight = 0.5;
float3 AmbientLight = 0.5;

// Is texturing enabled?
bool TextureEnabled;

// The main texture applied to the object, and a sampler for reading it.
texture Texture;

sampler Sampler = sampler_state
{
    Texture = (Texture);
    
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    
    AddressU = Wrap;
    AddressV = Wrap;
};

struct LightingVertexShaderInput
{
    float4 Position : POSITION0;
    float3 Normal : NORMAL0;
    float2 TextureCoordinate : TEXCOORD0;
};

struct LightingVertexShaderOutput
{
    float4 Position : POSITION0;
    float2 TextureCoordinate : TEXCOORD0;
    float LightAmount : TEXCOORD1;
};

struct LightingPixelShaderInput
{
    float2 TextureCoordinate : TEXCOORD0;
    float LightAmount : TEXCOORD1;
};

LightingVertexShaderOutput LightingVertexShader(LightingVertexShaderInput input)
{
    LightingVertexShaderOutput output;

    // Apply camera matrices to the input position.
    output.Position = mul(mul(mul(input.Position, World), View), Projection);
    output.TextureCoordinate = input.TextureCoordinate;

	output.LightAmount = dot(input.Normal, LightDirection);
    
    return output;
}

float4 LightingPixelShader(LightingPixelShaderInput input) : COLOR0
{
    float4 color = TextureEnabled ? tex2D(Sampler, input.TextureCoordinate) : 0;

    color.rgb *= saturate(input.LightAmount) * DiffuseLight + AmbientLight;
    
    return color;
}

technique Lighting
{
    pass P0
    {
        VertexShader = compile vs_2_0 LightingVertexShader();
        PixelShader = compile ps_2_0 LightingPixelShader();
    }
}