// Geometric Tools, Inc.
// http://www.geometrictools.com
// Copyright (c) 1998-2005.  All Rights Reserved
//
// The Wild Magic Library (WM3) source code is supplied under the terms of
// the license agreement
//     http://www.geometrictools.com/License/WildMagic3License.pdf
// and may not be copied or disclosed except in accordance with the terms
// of that agreement.

#include "Wm3CharcoalPShader.h"
using namespace Wm3;

WM3_IMPLEMENT_RTTI(Wm3,CharcoalPShader,PixelShader);
WM3_IMPLEMENT_STREAM(CharcoalPShader);
WM3_IMPLEMENT_DEFAULT_STREAM(CharcoalPShader,PixelShader);
WM3_IMPLEMENT_DEFAULT_NAME_ID(CharcoalPShader,PixelShader);

//----------------------------------------------------------------------------
CharcoalPShader::CharcoalPShader ()
{
    // shader program (load the type of the current renderer)
    m_acProgram = ms_aacProgram[Renderer::GetType()];

    // shader constants
    int iType, iOption, iReg, iRegQuantity;
    ShaderConstant* pkConst;

    // user defined vector (register 0)
    // Constants
    iType = ShaderConstant::SC_USER_DEFINED;
    iOption = ShaderConstant::SCO_NONE;
    iReg = 0;
    iRegQuantity = 1;
    pkConst = new ShaderConstant(iType,iOption,iReg,iRegQuantity);
    m_kConstant.Append(pkConst);
}
//----------------------------------------------------------------------------
CharcoalPShader::~CharcoalPShader ()
{
}
//----------------------------------------------------------------------------
const char* CharcoalPShader::ms_aacProgram[Renderer::RT_QUANTITY] =
{
"!!ARBfp1.0\n"
"# ARB_fragment_program generated by NVIDIA Cg compiler\n"
"# cgc version 1.1.0003, build date Jul  7 2003  11:55:19\n"
"# command line args: -q -profile arbfp1 -entry pmain\n"
"#vendor NVIDIA Corporation\n"
"#version 1.0.02\n"
"#profile arbfp1\n"
"#program pmain\n"
"#semantic pmain.contrastTexture\n"
"#semantic pmain.RandomTexture\n"
"#semantic pmain.PaperTexture\n"
"#semantic pmain.Constants\n"
"#var float4 i_f4Color : $vin.COLOR : COLOR : 0 : 1\n"
"#var float2 i_f2TexCon : $vin.TEXCOORD0 : TEXCOORD0 : 1 : 1\n"
"#var float2 i_f2TexRan : $vin.TEXCOORD1 : TEXCOORD1 : 2 : 1\n"
"#var float2 i_f2TexPap : $vin.TEXCOORD2 : TEXCOORD2 : 3 : 1\n"
"#var float4 o_f4Col : $vout.COLOR : COLOR : 4 : 1\n"
"#var sampler2D contrastTexture :  : texunit 0 : 5 : 1\n"
"#var sampler2D RandomTexture :  : texunit 1 : 6 : 1\n"
"#var sampler2D PaperTexture :  : texunit 2 : 7 : 1\n"
"#var float4 Constants :  : c[0] : 8 : 1\n"
"PARAM u0 = program.local[0];\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
"TEX R0.x, fragment.texcoord[1], texture[1], 2D;\n"
"TEX R1, fragment.texcoord[2], texture[2], 2D;\n"
"ADD R0.x, fragment.texcoord[0].x, R0.x;\n"
"ADD_SAT R1, R1, u0.y;\n"
"MOV R2.y, fragment.texcoord[0].y;\n"
"MOV R2.x, R0.x;\n"
"TEX R0, R2, texture[0], 2D;\n"
"ADD R2, fragment.color.primary, -R0;\n"
"MAD R0, u0.x, R2, R0;\n"
"MUL result.color, R1, R0;\n"
"END\n"
"# 10 instructions, 3 R-regs, 0 H-regs.\n"
"# End of program\n"
,
"// DX9 Pixel Shader by NVIDIA Cg compiler\n"
"	ps_2_0\n"
"// cgc version 1.1.0003, build date Jul  7 2003  11:55:19\n"
"// command line args: -q -profile ps_2_0 -entry pmain -profileopts dcls -strict\n"
"//vendor NVIDIA Corporation\n"
"//version 1.0.02\n"
"//profile ps_2_0\n"
"//program pmain\n"
"//semantic pmain.contrastTexture\n"
"//semantic pmain.RandomTexture\n"
"//semantic pmain.PaperTexture\n"
"//semantic pmain.Constants\n"
"//var float4 i_f4Color : $vin.COLOR : COLOR : 0 : 1\n"
"//var float2 i_f2TexCon : $vin.TEXCOORD0 : TEXCOORD0 : 1 : 1\n"
"//var float2 i_f2TexRan : $vin.TEXCOORD1 : TEXCOORD1 : 2 : 1\n"
"//var float2 i_f2TexPap : $vin.TEXCOORD2 : TEXCOORD2 : 3 : 1\n"
"//var float4 o_f4Col : $vout.COLOR : COLOR : 4 : 1\n"
"//var sampler2D contrastTexture :  : texunit 0 : 5 : 1\n"
"//var sampler2D RandomTexture :  : texunit 1 : 6 : 1\n"
"//var sampler2D PaperTexture :  : texunit 2 : 7 : 1\n"
"//var float4 Constants :  : c[0] : 8 : 1\n"
"	dcl_2d	s0\n"
"	dcl_2d	s1\n"
"	dcl_2d	s2\n"
"	dcl	v0\n"
"	dcl	t0.xy\n"
"	dcl	t1.xy\n"
"	dcl	t2.xy\n"
"texld   r0, t1, s1\n"
"texld   r1, t2, s2\n"
"add     r0.x, t0.x, r0.x\n"
"add_sat r1, r1, c0.y\n"
"mov     r2.y, t0.y\n"
"mov     r2.x, r0.x\n"
"texld   r0, r2, s0\n"
"add     r2, v0, -r0\n"
"mad     r0, c0.x, r2, r0\n"
"mul     r0, r1, r0\n"
"mov     oC0, r0\n"
"// 11 instructions, 3 R-regs.\n"
"// End of program\n"
};



