All pastes #381991 Raw Edit

Cody Brocious

public c v1 · immutable
·published 2007-03-05 06:18 UTC
rendered paste body
//--------------------------------------------------------------------------------------// File: Tutorial14.fx//// Copyright (c) Microsoft Corporation. All rights reserved.//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Constant Buffer Variables//--------------------------------------------------------------------------------------Texture2D g_txDiffuse;SamplerState samLinear{    Filter = MIN_MAG_MIP_LINEAR;    AddressU = Wrap;    AddressV = Wrap;};cbuffer cbConstant{    float3 vLightDir = float3(-0.577,0.577,-0.577);};cbuffer cbChangesEveryFrame{    matrix World;    matrix View;    matrix Projection;};struct VS_INPUT{    float3 Pos          : POSITION;         //position    float3 Norm         : NORMAL;           //normal    float2 Tex          : TEXCOORD0;        //texture coordinate};struct PS_INPUT{    float4 Pos : SV_POSITION;    float3 Norm : TEXCOORD0;    float2 Tex : TEXCOORD1;};struct QUADVS_INPUT{    float4 Pos : POSITION;    float2 Tex : TEXCOORD0;};struct QUADVS_OUTPUT{    float4 Pos : SV_POSITION;              // Transformed position    float2 Tex : TEXCOORD0;};//--------------------------------------------------------------------------------------// Blending States//--------------------------------------------------------------------------------------BlendState NoBlending{    BlendEnable[0] = FALSE;};BlendState SrcAlphaBlendingAdd{    BlendEnable[0] = TRUE;    SrcBlend = SRC_ALPHA;    DestBlend = ONE;    BlendOp = ADD;    SrcBlendAlpha = ZERO;    DestBlendAlpha = ZERO;    BlendOpAlpha = ADD;    RenderTargetWriteMask[0] = 0x0F;};BlendState SrcAlphaBlendingSub{    BlendEnable[0] = TRUE;    SrcBlend = SRC_ALPHA;    DestBlend = ONE;    BlendOp = SUBTRACT;    SrcBlendAlpha = ZERO;    DestBlendAlpha = ZERO;    BlendOpAlpha = ADD;    RenderTargetWriteMask[0] = 0x0F;};BlendState SrcColorBlendingAdd{    BlendEnable[0] = TRUE;    SrcBlend = SRC_COLOR;    DestBlend = ONE;    BlendOp = ADD;    SrcBlendAlpha = ZERO;    DestBlendAlpha = ZERO;    BlendOpAlpha = ADD;    RenderTargetWriteMask[0] = 0x0F;};BlendState SrcColorBlendingSub{    BlendEnable[0] = TRUE;    SrcBlend = SRC_COLOR;    DestBlend = ONE;    BlendOp = SUBTRACT;    SrcBlendAlpha = ZERO;    DestBlendAlpha = ZERO;    BlendOpAlpha = ADD;    RenderTargetWriteMask[0] = 0x0F;};//--------------------------------------------------------------------------------------// Depth/Stencil States//--------------------------------------------------------------------------------------DepthStencilState RenderWithStencilState{    DepthEnable = false;    DepthWriteMask = ZERO;    DepthFunc = Less;        // Setup stencil states    StencilEnable = true;    StencilReadMask = 0xFF;    StencilWriteMask = 0x00;        FrontFaceStencilFunc = Not_Equal;    FrontFaceStencilPass = Keep;    FrontFaceStencilFail = Zero;        BackFaceStencilFunc = Not_Equal;    BackFaceStencilPass = Keep;    BackFaceStencilFail = Zero;};//--------------------------------------------------------------------------------------// Scene Vertex Shader//--------------------------------------------------------------------------------------PS_INPUT VS( VS_INPUT input ){    PS_INPUT output = (PS_INPUT)0;        output.Pos = mul( float4(input.Pos,1), World );    output.Pos = mul( output.Pos, View );    output.Pos = mul( output.Pos, Projection );    output.Norm = mul( input.Norm, World );    output.Tex = input.Tex;        return output;}//-----------------------------------------------------------------------------// Quad Vertex Shaders//-----------------------------------------------------------------------------QUADVS_OUTPUT QuadVS( QUADVS_INPUT Input ){    QUADVS_OUTPUT Output;    Output.Pos = mul( Input.Pos, World );    Output.Pos = mul( Output.Pos, View );    Output.Pos = mul( Output.Pos, Projection );    Output.Tex = Input.Tex;    return Output;}QUADVS_OUTPUT ScreenQuadVS( QUADVS_INPUT Input ){    QUADVS_OUTPUT Output;    Output.Pos = Input.Pos;    Output.Tex = Input.Tex;    return Output;}//--------------------------------------------------------------------------------------// Pixel Shader//--------------------------------------------------------------------------------------float4 PS( PS_INPUT input) : SV_Target{    // Calculate lighting assuming light color is <1,1,1,1>    float fLighting = saturate( dot( input.Norm, vLightDir ) );    float4 outputColor = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting;    outputColor.a = 1;    return outputColor;}//--------------------------------------------------------------------------------------// Quad Pixel Shader//--------------------------------------------------------------------------------------float4 QuadPS( QUADVS_OUTPUT input) : SV_Target{    return g_txDiffuse.Sample( samLinear, input.Tex );}//--------------------------------------------------------------------------------------// Scene Techniques//--------------------------------------------------------------------------------------technique10 RenderScene{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, VS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, PS() ) );                SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}//--------------------------------------------------------------------------------------// RenderWithStencil - set the depth stencil state inside of the technique//--------------------------------------------------------------------------------------technique10 RenderWithStencil{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, ScreenQuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );        SetDepthStencilState( RenderWithStencilState, 0 );    }}//--------------------------------------------------------------------------------------// Quad Techniques:  Alpha blending state is set inside the technique//--------------------------------------------------------------------------------------technique10 RenderQuadSolid{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}//--------------------------------------------------------------------------------------technique10 RenderQuadSrcAlphaAdd{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}//--------------------------------------------------------------------------------------technique10 RenderQuadSrcAlphaSub{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( SrcAlphaBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}//--------------------------------------------------------------------------------------technique10 RenderQuadSrcColorAdd{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( SrcColorBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}//--------------------------------------------------------------------------------------technique10 RenderQuadSrcColorSub{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );                        SetBlendState( SrcColorBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );    }}