Fix line endings. WHAMMY.
This commit is contained in:
@@ -1,191 +1,191 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef LOCALD3DTYPES_H
|
||||
#define LOCALD3DTYPES_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
|
||||
#include <d3d10.h>
|
||||
#include <d3dx10.h>
|
||||
|
||||
struct IDirect3D10BaseTexture
|
||||
{
|
||||
ID3D10Resource *m_pBaseTexture;
|
||||
ID3D10ShaderResourceView *m_pSRView;
|
||||
ID3D10RenderTargetView *m_pRTView;
|
||||
};
|
||||
|
||||
class CDx10Types
|
||||
{
|
||||
public:
|
||||
typedef struct IDirect3D10BaseTexture IDirect3DTexture;
|
||||
// FIXME: What is this called now ?
|
||||
// typedef ID3D10TextureCube IDirect3DCubeTexture;
|
||||
typedef ID3D10Texture3D IDirect3DVolumeTexture;
|
||||
typedef ID3D10Device IDirect3DDevice;
|
||||
typedef D3D10_VIEWPORT D3DVIEWPORT;
|
||||
typedef ID3D10Buffer IDirect3DIndexBuffer;
|
||||
typedef ID3D10Buffer IDirect3DVertexBuffer;
|
||||
typedef ID3D10VertexShader IDirect3DVertexShader;
|
||||
typedef ID3D10PixelShader IDirect3DPixelShader;
|
||||
typedef ID3D10ShaderResourceView IDirect3DSurface;
|
||||
typedef ID3DX10Font ID3DXFont;
|
||||
typedef ID3D10Query ID3DQuery;
|
||||
|
||||
typedef ID3D10Device *LPDIRECT3DDEVICE;
|
||||
typedef ID3D10Buffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef ID3D10Buffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
#endif // defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
|
||||
|
||||
#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
#ifdef _DEBUG
|
||||
#define D3D_DEBUG_INFO 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct IDirect3DTexture9;
|
||||
struct IDirect3DBaseTexture9;
|
||||
struct IDirect3DCubeTexture9;
|
||||
struct IDirect3D9;
|
||||
struct IDirect3DDevice9;
|
||||
struct IDirect3DSurface9;
|
||||
struct IDirect3DIndexBuffer9;
|
||||
struct IDirect3DVertexBuffer9;
|
||||
struct IDirect3DVertexShader9;
|
||||
struct IDirect3DPixelShader9;
|
||||
struct IDirect3DVolumeTexture9;
|
||||
|
||||
typedef struct _D3DLIGHT9 D3DLIGHT9;
|
||||
typedef struct _D3DADAPTER_IDENTIFIER9 D3DADAPTER_IDENTIFIER9;
|
||||
typedef struct _D3DCAPS9 D3DCAPS9;
|
||||
typedef struct _D3DVIEWPORT9 D3DVIEWPORT9;
|
||||
typedef struct _D3DMATERIAL9 D3DMATERIAL9;
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
|
||||
class CDx9Types
|
||||
{
|
||||
public:
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
typedef void *HardwareShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The vertex and pixel shader type
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int VertexShader_t;
|
||||
typedef int PixelShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Bitpattern for an invalid shader
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INVALID_SHADER ( 0xFFFFFFFF )
|
||||
#define INVALID_HARDWARE_SHADER ( NULL )
|
||||
|
||||
#define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD
|
||||
#define D3DRS_NOTSUPPORTED D3DRS_FORCE_DWORD
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
// not supported, keeping for port ease
|
||||
#define D3DSAMP_SRGBTEXTURE D3DSAMP_NOTSUPPORTED
|
||||
#define D3DRS_LIGHTING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DIFFUSEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SHADEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LASTPIXEL D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DITHERENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGCOLOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGTABLEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGSTART D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGDENSITY D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_RANGEFOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TEXTUREFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_CLIPPING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENT D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGVERTEXMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_COLORVERTEX D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LOCALVIEWER D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALIZENORMALS D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENTMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_EMISSIVEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_VERTEXBLEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_A D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_B D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_C D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_PATCHEDGESTYLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DEBUGMONITORTOKEN D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_INDEXEDVERTEXBLENDENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TWEENFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POSITIONDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ANTIALIASEDLINEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_X D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Y D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Z D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_W D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ENABLEADAPTIVETESSELLATION D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SRGBWRITEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DLOCK_DISCARD 0
|
||||
#define D3DUSAGE_DYNAMIC 0
|
||||
#define D3DUSAGE_AUTOGENMIPMAP 0
|
||||
#define D3DDEVTYPE_REF D3DDEVTYPE_HAL
|
||||
#define D3DENUM_WHQL_LEVEL 0
|
||||
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING D3DCREATE_HARDWARE_VERTEXPROCESSING
|
||||
#define D3DDMT_ENABLE 0
|
||||
|
||||
typedef enum D3DSHADEMODE
|
||||
{
|
||||
D3DSHADE_FLAT = 0,
|
||||
D3DSHADE_GOURAUD = 0,
|
||||
};
|
||||
|
||||
#endif // _X360
|
||||
|
||||
#endif // LOCALD3DTYPES_H
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef LOCALD3DTYPES_H
|
||||
#define LOCALD3DTYPES_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
|
||||
#include <d3d10.h>
|
||||
#include <d3dx10.h>
|
||||
|
||||
struct IDirect3D10BaseTexture
|
||||
{
|
||||
ID3D10Resource *m_pBaseTexture;
|
||||
ID3D10ShaderResourceView *m_pSRView;
|
||||
ID3D10RenderTargetView *m_pRTView;
|
||||
};
|
||||
|
||||
class CDx10Types
|
||||
{
|
||||
public:
|
||||
typedef struct IDirect3D10BaseTexture IDirect3DTexture;
|
||||
// FIXME: What is this called now ?
|
||||
// typedef ID3D10TextureCube IDirect3DCubeTexture;
|
||||
typedef ID3D10Texture3D IDirect3DVolumeTexture;
|
||||
typedef ID3D10Device IDirect3DDevice;
|
||||
typedef D3D10_VIEWPORT D3DVIEWPORT;
|
||||
typedef ID3D10Buffer IDirect3DIndexBuffer;
|
||||
typedef ID3D10Buffer IDirect3DVertexBuffer;
|
||||
typedef ID3D10VertexShader IDirect3DVertexShader;
|
||||
typedef ID3D10PixelShader IDirect3DPixelShader;
|
||||
typedef ID3D10ShaderResourceView IDirect3DSurface;
|
||||
typedef ID3DX10Font ID3DXFont;
|
||||
typedef ID3D10Query ID3DQuery;
|
||||
|
||||
typedef ID3D10Device *LPDIRECT3DDEVICE;
|
||||
typedef ID3D10Buffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef ID3D10Buffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
#endif // defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
|
||||
|
||||
#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
#ifdef _DEBUG
|
||||
#define D3D_DEBUG_INFO 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct IDirect3DTexture9;
|
||||
struct IDirect3DBaseTexture9;
|
||||
struct IDirect3DCubeTexture9;
|
||||
struct IDirect3D9;
|
||||
struct IDirect3DDevice9;
|
||||
struct IDirect3DSurface9;
|
||||
struct IDirect3DIndexBuffer9;
|
||||
struct IDirect3DVertexBuffer9;
|
||||
struct IDirect3DVertexShader9;
|
||||
struct IDirect3DPixelShader9;
|
||||
struct IDirect3DVolumeTexture9;
|
||||
|
||||
typedef struct _D3DLIGHT9 D3DLIGHT9;
|
||||
typedef struct _D3DADAPTER_IDENTIFIER9 D3DADAPTER_IDENTIFIER9;
|
||||
typedef struct _D3DCAPS9 D3DCAPS9;
|
||||
typedef struct _D3DVIEWPORT9 D3DVIEWPORT9;
|
||||
typedef struct _D3DMATERIAL9 D3DMATERIAL9;
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
|
||||
class CDx9Types
|
||||
{
|
||||
public:
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
typedef void *HardwareShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The vertex and pixel shader type
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int VertexShader_t;
|
||||
typedef int PixelShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Bitpattern for an invalid shader
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INVALID_SHADER ( 0xFFFFFFFF )
|
||||
#define INVALID_HARDWARE_SHADER ( NULL )
|
||||
|
||||
#define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD
|
||||
#define D3DRS_NOTSUPPORTED D3DRS_FORCE_DWORD
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
// not supported, keeping for port ease
|
||||
#define D3DSAMP_SRGBTEXTURE D3DSAMP_NOTSUPPORTED
|
||||
#define D3DRS_LIGHTING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DIFFUSEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SHADEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LASTPIXEL D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DITHERENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGCOLOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGTABLEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGSTART D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGDENSITY D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_RANGEFOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TEXTUREFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_CLIPPING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENT D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGVERTEXMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_COLORVERTEX D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LOCALVIEWER D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALIZENORMALS D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENTMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_EMISSIVEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_VERTEXBLEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_A D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_B D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_C D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_PATCHEDGESTYLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DEBUGMONITORTOKEN D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_INDEXEDVERTEXBLENDENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TWEENFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POSITIONDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ANTIALIASEDLINEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_X D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Y D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Z D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_W D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ENABLEADAPTIVETESSELLATION D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SRGBWRITEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DLOCK_DISCARD 0
|
||||
#define D3DUSAGE_DYNAMIC 0
|
||||
#define D3DUSAGE_AUTOGENMIPMAP 0
|
||||
#define D3DDEVTYPE_REF D3DDEVTYPE_HAL
|
||||
#define D3DENUM_WHQL_LEVEL 0
|
||||
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING D3DCREATE_HARDWARE_VERTEXPROCESSING
|
||||
#define D3DDMT_ENABLE 0
|
||||
|
||||
typedef enum D3DSHADEMODE
|
||||
{
|
||||
D3DSHADE_FLAT = 0,
|
||||
D3DSHADE_GOURAUD = 0,
|
||||
};
|
||||
|
||||
#endif // _X360
|
||||
|
||||
#endif // LOCALD3DTYPES_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,439 +1,439 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// This is what all vs/ps (dx8+) shaders inherit from.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef BASEVSSHADER_H
|
||||
#define BASEVSSHADER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderlib/cshader.h"
|
||||
#include "shaderlib/BaseShader.h"
|
||||
#include "convar.h"
|
||||
#include <renderparm.h>
|
||||
|
||||
#ifdef _X360
|
||||
#define SUPPORT_DX8 0
|
||||
#define SUPPORT_DX7 0
|
||||
#else
|
||||
#define SUPPORT_DX8 1
|
||||
#define SUPPORT_DX7 1
|
||||
#endif
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper macro for vertex shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
#define BEGIN_VS_SHADER_FLAGS(_name, _help, _flags) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, _flags )
|
||||
#define BEGIN_VS_SHADER(_name,_help) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, 0 )
|
||||
|
||||
|
||||
// useful parameter initialization macro
|
||||
#define INIT_FLOAT_PARM( parm, value ) \
|
||||
if ( !params[(parm)]->IsDefined() ) \
|
||||
{ \
|
||||
params[(parm)]->SetFloatValue( (value) ); \
|
||||
}
|
||||
|
||||
// useful pixel shader declaration macro for ps20/20b c++ code
|
||||
#define SET_STATIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \
|
||||
{ \
|
||||
DECLARE_STATIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
SET_STATIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
DECLARE_STATIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
SET_STATIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
}
|
||||
|
||||
#define SET_DYNAMIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \
|
||||
{ \
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
SET_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
SET_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base class for shaders, contains helper methods.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseVSShader : public CBaseShader
|
||||
{
|
||||
public:
|
||||
|
||||
// Loads bump lightmap coordinates into the pixel shader
|
||||
void LoadBumpLightmapCoordinateAxes_PixelShader( int pixelReg );
|
||||
|
||||
// Loads bump lightmap coordinates into the vertex shader
|
||||
void LoadBumpLightmapCoordinateAxes_VertexShader( int vertexReg );
|
||||
|
||||
// Pixel and vertex shader constants....
|
||||
void SetPixelShaderConstant( int pixelReg, int constantVar );
|
||||
|
||||
// Pixel and vertex shader constants....
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar );
|
||||
|
||||
// This version will put constantVar into x,y,z, and constantVar2 into the w
|
||||
void SetPixelShaderConstant( int pixelReg, int constantVar, int constantVar2 );
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar, int constantVar2 );
|
||||
|
||||
// Helpers for setting constants that need to be converted to linear space (from gamma space).
|
||||
void SetVertexShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
void SetPixelShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
|
||||
void SetVertexShaderConstant( int vertexReg, int constantVar );
|
||||
|
||||
// set rgb components of constant from a color parm and give an explicit w value
|
||||
void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue );
|
||||
|
||||
// GR - fix for const/lerp issues
|
||||
void SetPixelShaderConstantFudge( int pixelReg, int constantVar );
|
||||
|
||||
// Sets light direction for pixel shaders.
|
||||
void SetPixelShaderLightColors( int pixelReg );
|
||||
|
||||
// Sets vertex shader texture transforms
|
||||
void SetVertexShaderTextureTranslation( int vertexReg, int translationVar );
|
||||
void SetVertexShaderTextureScale( int vertexReg, int scaleVar );
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar );
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Set pixel shader texture transforms
|
||||
void SetPixelShaderTextureTranslation( int pixelReg, int translationVar );
|
||||
void SetPixelShaderTextureScale( int pixelReg, int scaleVar );
|
||||
void SetPixelShaderTextureTransform( int pixelReg, int transformVar );
|
||||
void SetPixelShaderTextureScaledTransform( int pixelReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Moves a matrix into vertex shader constants
|
||||
void SetVertexShaderMatrix3x4( int vertexReg, int matrixVar );
|
||||
void SetVertexShaderMatrix4x4( int vertexReg, int matrixVar );
|
||||
|
||||
// Loads the view matrix into vertex shader constants
|
||||
void LoadViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the projection matrix into vertex shader constants
|
||||
void LoadProjectionMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the model->view matrix into vertex shader constants
|
||||
void LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads a scale/offset version of the viewport transform into the specified constant.
|
||||
void LoadViewportTransformScaledIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Sets up ambient light cube...
|
||||
void SetAmbientCubeDynamicStateVertexShader( );
|
||||
float GetAmbientLightCubeLuminance( );
|
||||
|
||||
// Helpers for dealing with envmaptint
|
||||
void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar, int alphaVar, bool bConvertFromGammaToLinear = false );
|
||||
|
||||
// Helper methods for pixel shader overbrighting
|
||||
void EnablePixelShaderOverbright( int reg, bool bEnable, bool bDivideByTwo );
|
||||
|
||||
// Helper for dealing with modulation
|
||||
void SetModulationVertexShaderDynamicState();
|
||||
void SetModulationPixelShaderDynamicState( int modulationVar );
|
||||
void SetModulationPixelShaderDynamicState_LinearColorSpace( int modulationVar );
|
||||
void SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int modulationVar, float flScale );
|
||||
|
||||
// Sets a color + alpha into shader constants
|
||||
void SetColorVertexShaderConstant( int nVertexReg, int colorVar, int alphaVar );
|
||||
void SetColorPixelShaderConstant( int nPixelReg, int colorVar, int alphaVar );
|
||||
|
||||
|
||||
#ifndef GAME_SHADER_DLL
|
||||
//
|
||||
// Standard shader passes!
|
||||
//
|
||||
|
||||
void InitParamsUnlitGeneric_DX8(
|
||||
int baseTextureVar,
|
||||
int detailScaleVar,
|
||||
int envmapOptionalVar,
|
||||
int envmapVar,
|
||||
int envmapTintVar,
|
||||
int envmapMaskScaleVar,
|
||||
int nDetailBlendMode );
|
||||
|
||||
void InitUnlitGeneric_DX8(
|
||||
int baseTextureVar,
|
||||
int detailVar,
|
||||
int envmapVar,
|
||||
int envmapMaskVar );
|
||||
|
||||
// Dx8 Unlit Generic pass
|
||||
void VertexShaderUnlitGenericPass( int baseTextureVar, int frameVar,
|
||||
int baseTextureTransformVar,
|
||||
int detailVar, int detailTransform, bool bDetailTransformIsScale,
|
||||
int envmapVar, int envMapFrameVar, int envmapMaskVar,
|
||||
int envmapMaskFrameVar, int envmapMaskScaleVar, int envmapTintVar,
|
||||
int alphaTestReferenceVar,
|
||||
int nDetailBlendModeVar,
|
||||
int nOutlineVar,
|
||||
int nOutlineColorVar,
|
||||
int nOutlineStartVar,
|
||||
int nOutlineEndVar,
|
||||
int nSeparateDetailUVsVar
|
||||
);
|
||||
|
||||
// Helpers for drawing world bump mapped stuff.
|
||||
void DrawModelBumpedSpecularLighting( int bumpMapVar, int bumpMapFrameVar,
|
||||
int envMapVar, int envMapVarFrame,
|
||||
int envMapTintVar, int alphaVar,
|
||||
int envMapContrastVar, int envMapSaturationVar,
|
||||
int bumpTransformVar,
|
||||
bool bBlendSpecular, bool bNoWriteZ = false );
|
||||
void DrawWorldBumpedSpecularLighting( int bumpmapVar, int envmapVar,
|
||||
int bumpFrameVar, int envmapFrameVar,
|
||||
int envmapTintVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar,
|
||||
int bumpTransformVar, int fresnelReflectionVar,
|
||||
bool bBlend, bool bNoWriteZ = false );
|
||||
|
||||
const char *UnlitGeneric_ComputeVertexShaderName( bool bMask,
|
||||
bool bEnvmap,
|
||||
bool bBaseTexture,
|
||||
bool bBaseAlphaEnvmapMask,
|
||||
bool bDetail,
|
||||
bool bVertexColor,
|
||||
bool bEnvmapCameraSpace,
|
||||
bool bEnvmapSphere );
|
||||
|
||||
const char *UnlitGeneric_ComputePixelShaderName( bool bMask,
|
||||
bool bEnvmap,
|
||||
bool bBaseTexture,
|
||||
bool bBaseAlphaEnvmapMask,
|
||||
bool bDetail,
|
||||
bool bMultiplyDetail,
|
||||
bool bMaskBaseByDetailAlpha );
|
||||
|
||||
void DrawWorldBaseTexture( int baseTextureVar, int baseTextureTransformVar, int frameVar, int colorVar, int alphaVar );
|
||||
void DrawWorldBumpedDiffuseLighting( int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar, bool bMultiply, bool bSSBump );
|
||||
void DrawWorldBumpedSpecularLighting( int envmapMaskVar, int envmapMaskFrame,
|
||||
int bumpmapVar, int envmapVar,
|
||||
int bumpFrameVar, int envmapFrameVar,
|
||||
int envmapTintVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar,
|
||||
int bumpTransformVar, int fresnelReflectionVar,
|
||||
bool bBlend );
|
||||
void DrawBaseTextureBlend( int baseTextureVar, int baseTextureTransformVar,
|
||||
int baseTextureFrameVar,
|
||||
int baseTexture2Var, int baseTextureTransform2Var,
|
||||
int baseTextureFrame2Var, int colorVar, int alphaVar );
|
||||
void DrawWorldBumpedDiffuseLighting_Base_ps14( int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar, int baseTextureVar, int baseTextureTransformVar, int frameVar );
|
||||
void DrawWorldBumpedDiffuseLighting_Blend_ps14( int bumpmapVar, int bumpFrameVar, int bumpTransformVar,
|
||||
int baseTextureVar, int baseTextureTransformVar, int baseTextureFrameVar,
|
||||
int baseTexture2Var, int baseTextureTransform2Var, int baseTextureFrame2Var);
|
||||
void DrawWorldBumpedUsingVertexShader( int baseTextureVar, int baseTextureTransformVar,
|
||||
int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar,
|
||||
int envmapMaskVar, int envmapMaskFrame,
|
||||
int envmapVar,
|
||||
int envmapFrameVar,
|
||||
int envmapTintVar, int colorVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar, int frameVar, int fresnelReflectionVar,
|
||||
bool doBaseTexture2,
|
||||
int baseTexture2Var,
|
||||
int baseTextureTransform2Var,
|
||||
int baseTextureFrame2Var,
|
||||
bool bSSBump
|
||||
);
|
||||
|
||||
// Sets up hw morphing state for the vertex shader
|
||||
void SetHWMorphVertexShaderState( int nDimConst, int nSubrectConst, VertexTextureSampler_t morphSampler );
|
||||
|
||||
// Computes the shader index for vertex lit materials
|
||||
int ComputeVertexLitShaderIndex( bool bVertexLitGeneric, bool hasBump, bool hasEnvmap, bool hasVertexColor, bool bHasNormal ) const;
|
||||
|
||||
// Helper for setting up flashlight constants
|
||||
void SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms );
|
||||
|
||||
#if SUPPORT_DX8
|
||||
void DrawFlashlight_dx80( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
bool bBump, int bumpmapVar, int bumpmapFrame, int bumpTransform, int flashlightTextureVar,
|
||||
int flashlightTextureFrameVar, bool bLightmappedGeneric, bool bWorldVertexTransition,
|
||||
int nWorldVertexTransitionPassID, int baseTexture2Var, int baseTexture2FrameVar,
|
||||
bool bTeeth=false, int nTeethForwardVar=0, int nTeethIllumFactorVar=0 );
|
||||
#endif
|
||||
|
||||
struct DrawFlashlight_dx90_Vars_t
|
||||
{
|
||||
DrawFlashlight_dx90_Vars_t()
|
||||
{
|
||||
// set all ints to -1
|
||||
memset( this, 0xFF, sizeof(DrawFlashlight_dx90_Vars_t) );
|
||||
// set all bools to a default value.
|
||||
m_bBump = false;
|
||||
m_bLightmappedGeneric = false;
|
||||
m_bWorldVertexTransition = false;
|
||||
m_bTeeth = false;
|
||||
m_bSSBump = false;
|
||||
m_fSeamlessScale = 0.0;
|
||||
}
|
||||
bool m_bBump;
|
||||
bool m_bLightmappedGeneric;
|
||||
bool m_bWorldVertexTransition;
|
||||
bool m_bTeeth;
|
||||
int m_nBumpmapVar;
|
||||
int m_nBumpmapFrame;
|
||||
int m_nBumpTransform;
|
||||
int m_nFlashlightTextureVar;
|
||||
int m_nFlashlightTextureFrameVar;
|
||||
int m_nBaseTexture2Var;
|
||||
int m_nBaseTexture2FrameVar;
|
||||
int m_nBumpmap2Var;
|
||||
int m_nBumpmap2Frame;
|
||||
int m_nBump2Transform;
|
||||
int m_nDetailVar;
|
||||
int m_nDetailScale;
|
||||
int m_nDetailTextureCombineMode;
|
||||
int m_nDetailTextureBlendFactor;
|
||||
int m_nDetailTint;
|
||||
int m_nTeethForwardVar;
|
||||
int m_nTeethIllumFactorVar;
|
||||
int m_nAlphaTestReference;
|
||||
bool m_bSSBump;
|
||||
float m_fSeamlessScale; // 0.0 = not seamless
|
||||
};
|
||||
void DrawFlashlight_dx90( IMaterialVar** params,
|
||||
IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, DrawFlashlight_dx90_Vars_t &vars );
|
||||
#endif // GAME_SHADER_DLL
|
||||
|
||||
BlendType_t EvaluateBlendRequirements( int textureVar, bool isBaseTexture, int detailTextureVar = -1 );
|
||||
|
||||
void HashShadow2DJitter( const float fJitterSeed, float *fU, float* fV );
|
||||
|
||||
//Alpha tested materials can end up leaving garbage in the dest alpha buffer if they write depth.
|
||||
//This pass fills in the areas that passed the alpha test with depth in dest alpha
|
||||
//by writing only equal depth pixels and only if we should be writing depth to dest alpha
|
||||
void DrawEqualDepthToDestAlpha( void );
|
||||
|
||||
private:
|
||||
// Helper methods for VertexLitGenericPass
|
||||
// void UnlitGenericShadowState( int baseTextureVar, int detailVar, int envmapVar, int envmapMaskVar, bool doSkin );
|
||||
void UnlitGenericDynamicState( int baseTextureVar, int frameVar, int baseTextureTransformVar,
|
||||
int detailVar, int detailTransform, bool bDetailTransformIsScale, int envmapVar,
|
||||
int envMapFrameVar, int envmapMaskVar, int envmapMaskFrameVar,
|
||||
int envmapMaskScaleVar, int envmapTintVar );
|
||||
|
||||
// Converts a color + alpha into a vector4
|
||||
void ColorVarsToVector( int colorVar, int alphaVar, Vector4D &color );
|
||||
|
||||
};
|
||||
|
||||
FORCEINLINE void SetFlashLightColorFromState( FlashlightState_t const &state, IShaderDynamicAPI *pShaderAPI, int nPSRegister=28, bool bFlashlightNoLambert=false )
|
||||
{
|
||||
// Old code
|
||||
//float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x;
|
||||
//float flFlashlightScale = 1.0f / flToneMapScale;
|
||||
|
||||
// Fix to old code to keep flashlight from ever getting brighter than 1.0
|
||||
//float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x;
|
||||
//if ( flToneMapScale < 1.0f )
|
||||
// flToneMapScale = 1.0f;
|
||||
//float flFlashlightScale = 1.0f / flToneMapScale;
|
||||
|
||||
// Force flashlight to 25% bright always
|
||||
float flFlashlightScale = 0.25f;
|
||||
|
||||
if ( !g_pHardwareConfig->GetHDREnabled() )
|
||||
{
|
||||
// Non-HDR path requires 2.0 flashlight
|
||||
flFlashlightScale = 2.0f;
|
||||
}
|
||||
|
||||
// DX10 requires some hackery due to sRGB/blend ordering change from DX9
|
||||
if ( g_pHardwareConfig->UsesSRGBCorrectBlending() )
|
||||
{
|
||||
flFlashlightScale *= 2.5f; // Magic number that works well on the NVIDIA 8800
|
||||
}
|
||||
|
||||
// Generate pixel shader constant
|
||||
float const *pFlashlightColor = state.m_Color;
|
||||
float vPsConst[4] = { flFlashlightScale * pFlashlightColor[0], flFlashlightScale * pFlashlightColor[1], flFlashlightScale * pFlashlightColor[2], pFlashlightColor[3] };
|
||||
vPsConst[3] = bFlashlightNoLambert ? 2.0f : 0.0f; // This will be added to N.L before saturate to force a 1.0 N.L term
|
||||
|
||||
// Red flashlight for testing
|
||||
//vPsConst[0] = 0.5f; vPsConst[1] = 0.0f; vPsConst[2] = 0.0f;
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( nPSRegister, ( float * )vPsConst );
|
||||
}
|
||||
|
||||
FORCEINLINE float ShadowAttenFromState( FlashlightState_t const &state )
|
||||
{
|
||||
// DX10 requires some hackery due to sRGB/blend ordering change from DX9, which makes the shadows too light
|
||||
if ( g_pHardwareConfig->UsesSRGBCorrectBlending() )
|
||||
return state.m_flShadowAtten * 0.1f; // magic number
|
||||
|
||||
return state.m_flShadowAtten;
|
||||
}
|
||||
|
||||
FORCEINLINE float ShadowFilterFromState( FlashlightState_t const &state )
|
||||
{
|
||||
// We developed shadow maps at 1024, so we expect the penumbra size to have been tuned relative to that
|
||||
return state.m_flShadowFilterSize / 1024.0f;
|
||||
}
|
||||
|
||||
|
||||
// convenient material variable access functions for helpers to use.
|
||||
FORCEINLINE bool IsTextureSet( int nVar, IMaterialVar **params )
|
||||
{
|
||||
return ( nVar != -1 ) && ( params[nVar]->IsTexture() );
|
||||
}
|
||||
|
||||
FORCEINLINE bool IsBoolSet( int nVar, IMaterialVar **params )
|
||||
{
|
||||
return ( nVar != -1 ) && ( params[nVar]->GetIntValue() );
|
||||
}
|
||||
|
||||
FORCEINLINE int GetIntParam( int nVar, IMaterialVar **params, int nDefaultValue = 0 )
|
||||
{
|
||||
return ( nVar != -1 ) ? ( params[nVar]->GetIntValue() ) : nDefaultValue;
|
||||
}
|
||||
|
||||
FORCEINLINE float GetFloatParam( int nVar, IMaterialVar **params, float flDefaultValue = 0.0 )
|
||||
{
|
||||
return ( nVar != -1 ) ? ( params[nVar]->GetFloatValue() ) : flDefaultValue;
|
||||
}
|
||||
|
||||
FORCEINLINE void InitFloatParam( int nIndex, IMaterialVar **params, float flValue )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetFloatValue( flValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void InitIntParam( int nIndex, IMaterialVar **params, int nValue )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetIntValue( nValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ConVar;
|
||||
|
||||
#ifdef _DEBUG
|
||||
extern ConVar mat_envmaptintoverride;
|
||||
extern ConVar mat_envmaptintscale;
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BASEVSSHADER_H
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// This is what all vs/ps (dx8+) shaders inherit from.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef BASEVSSHADER_H
|
||||
#define BASEVSSHADER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderlib/cshader.h"
|
||||
#include "shaderlib/BaseShader.h"
|
||||
#include "convar.h"
|
||||
#include <renderparm.h>
|
||||
|
||||
#ifdef _X360
|
||||
#define SUPPORT_DX8 0
|
||||
#define SUPPORT_DX7 0
|
||||
#else
|
||||
#define SUPPORT_DX8 1
|
||||
#define SUPPORT_DX7 1
|
||||
#endif
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper macro for vertex shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
#define BEGIN_VS_SHADER_FLAGS(_name, _help, _flags) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, _flags )
|
||||
#define BEGIN_VS_SHADER(_name,_help) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, 0 )
|
||||
|
||||
|
||||
// useful parameter initialization macro
|
||||
#define INIT_FLOAT_PARM( parm, value ) \
|
||||
if ( !params[(parm)]->IsDefined() ) \
|
||||
{ \
|
||||
params[(parm)]->SetFloatValue( (value) ); \
|
||||
}
|
||||
|
||||
// useful pixel shader declaration macro for ps20/20b c++ code
|
||||
#define SET_STATIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \
|
||||
{ \
|
||||
DECLARE_STATIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
SET_STATIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
DECLARE_STATIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
SET_STATIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
}
|
||||
|
||||
#define SET_DYNAMIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \
|
||||
{ \
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
SET_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
SET_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base class for shaders, contains helper methods.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseVSShader : public CBaseShader
|
||||
{
|
||||
public:
|
||||
|
||||
// Loads bump lightmap coordinates into the pixel shader
|
||||
void LoadBumpLightmapCoordinateAxes_PixelShader( int pixelReg );
|
||||
|
||||
// Loads bump lightmap coordinates into the vertex shader
|
||||
void LoadBumpLightmapCoordinateAxes_VertexShader( int vertexReg );
|
||||
|
||||
// Pixel and vertex shader constants....
|
||||
void SetPixelShaderConstant( int pixelReg, int constantVar );
|
||||
|
||||
// Pixel and vertex shader constants....
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar );
|
||||
|
||||
// This version will put constantVar into x,y,z, and constantVar2 into the w
|
||||
void SetPixelShaderConstant( int pixelReg, int constantVar, int constantVar2 );
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar, int constantVar2 );
|
||||
|
||||
// Helpers for setting constants that need to be converted to linear space (from gamma space).
|
||||
void SetVertexShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
void SetPixelShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
|
||||
void SetVertexShaderConstant( int vertexReg, int constantVar );
|
||||
|
||||
// set rgb components of constant from a color parm and give an explicit w value
|
||||
void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue );
|
||||
|
||||
// GR - fix for const/lerp issues
|
||||
void SetPixelShaderConstantFudge( int pixelReg, int constantVar );
|
||||
|
||||
// Sets light direction for pixel shaders.
|
||||
void SetPixelShaderLightColors( int pixelReg );
|
||||
|
||||
// Sets vertex shader texture transforms
|
||||
void SetVertexShaderTextureTranslation( int vertexReg, int translationVar );
|
||||
void SetVertexShaderTextureScale( int vertexReg, int scaleVar );
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar );
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Set pixel shader texture transforms
|
||||
void SetPixelShaderTextureTranslation( int pixelReg, int translationVar );
|
||||
void SetPixelShaderTextureScale( int pixelReg, int scaleVar );
|
||||
void SetPixelShaderTextureTransform( int pixelReg, int transformVar );
|
||||
void SetPixelShaderTextureScaledTransform( int pixelReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Moves a matrix into vertex shader constants
|
||||
void SetVertexShaderMatrix3x4( int vertexReg, int matrixVar );
|
||||
void SetVertexShaderMatrix4x4( int vertexReg, int matrixVar );
|
||||
|
||||
// Loads the view matrix into vertex shader constants
|
||||
void LoadViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the projection matrix into vertex shader constants
|
||||
void LoadProjectionMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the model->view matrix into vertex shader constants
|
||||
void LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads a scale/offset version of the viewport transform into the specified constant.
|
||||
void LoadViewportTransformScaledIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Sets up ambient light cube...
|
||||
void SetAmbientCubeDynamicStateVertexShader( );
|
||||
float GetAmbientLightCubeLuminance( );
|
||||
|
||||
// Helpers for dealing with envmaptint
|
||||
void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar, int alphaVar, bool bConvertFromGammaToLinear = false );
|
||||
|
||||
// Helper methods for pixel shader overbrighting
|
||||
void EnablePixelShaderOverbright( int reg, bool bEnable, bool bDivideByTwo );
|
||||
|
||||
// Helper for dealing with modulation
|
||||
void SetModulationVertexShaderDynamicState();
|
||||
void SetModulationPixelShaderDynamicState( int modulationVar );
|
||||
void SetModulationPixelShaderDynamicState_LinearColorSpace( int modulationVar );
|
||||
void SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int modulationVar, float flScale );
|
||||
|
||||
// Sets a color + alpha into shader constants
|
||||
void SetColorVertexShaderConstant( int nVertexReg, int colorVar, int alphaVar );
|
||||
void SetColorPixelShaderConstant( int nPixelReg, int colorVar, int alphaVar );
|
||||
|
||||
|
||||
#ifndef GAME_SHADER_DLL
|
||||
//
|
||||
// Standard shader passes!
|
||||
//
|
||||
|
||||
void InitParamsUnlitGeneric_DX8(
|
||||
int baseTextureVar,
|
||||
int detailScaleVar,
|
||||
int envmapOptionalVar,
|
||||
int envmapVar,
|
||||
int envmapTintVar,
|
||||
int envmapMaskScaleVar,
|
||||
int nDetailBlendMode );
|
||||
|
||||
void InitUnlitGeneric_DX8(
|
||||
int baseTextureVar,
|
||||
int detailVar,
|
||||
int envmapVar,
|
||||
int envmapMaskVar );
|
||||
|
||||
// Dx8 Unlit Generic pass
|
||||
void VertexShaderUnlitGenericPass( int baseTextureVar, int frameVar,
|
||||
int baseTextureTransformVar,
|
||||
int detailVar, int detailTransform, bool bDetailTransformIsScale,
|
||||
int envmapVar, int envMapFrameVar, int envmapMaskVar,
|
||||
int envmapMaskFrameVar, int envmapMaskScaleVar, int envmapTintVar,
|
||||
int alphaTestReferenceVar,
|
||||
int nDetailBlendModeVar,
|
||||
int nOutlineVar,
|
||||
int nOutlineColorVar,
|
||||
int nOutlineStartVar,
|
||||
int nOutlineEndVar,
|
||||
int nSeparateDetailUVsVar
|
||||
);
|
||||
|
||||
// Helpers for drawing world bump mapped stuff.
|
||||
void DrawModelBumpedSpecularLighting( int bumpMapVar, int bumpMapFrameVar,
|
||||
int envMapVar, int envMapVarFrame,
|
||||
int envMapTintVar, int alphaVar,
|
||||
int envMapContrastVar, int envMapSaturationVar,
|
||||
int bumpTransformVar,
|
||||
bool bBlendSpecular, bool bNoWriteZ = false );
|
||||
void DrawWorldBumpedSpecularLighting( int bumpmapVar, int envmapVar,
|
||||
int bumpFrameVar, int envmapFrameVar,
|
||||
int envmapTintVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar,
|
||||
int bumpTransformVar, int fresnelReflectionVar,
|
||||
bool bBlend, bool bNoWriteZ = false );
|
||||
|
||||
const char *UnlitGeneric_ComputeVertexShaderName( bool bMask,
|
||||
bool bEnvmap,
|
||||
bool bBaseTexture,
|
||||
bool bBaseAlphaEnvmapMask,
|
||||
bool bDetail,
|
||||
bool bVertexColor,
|
||||
bool bEnvmapCameraSpace,
|
||||
bool bEnvmapSphere );
|
||||
|
||||
const char *UnlitGeneric_ComputePixelShaderName( bool bMask,
|
||||
bool bEnvmap,
|
||||
bool bBaseTexture,
|
||||
bool bBaseAlphaEnvmapMask,
|
||||
bool bDetail,
|
||||
bool bMultiplyDetail,
|
||||
bool bMaskBaseByDetailAlpha );
|
||||
|
||||
void DrawWorldBaseTexture( int baseTextureVar, int baseTextureTransformVar, int frameVar, int colorVar, int alphaVar );
|
||||
void DrawWorldBumpedDiffuseLighting( int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar, bool bMultiply, bool bSSBump );
|
||||
void DrawWorldBumpedSpecularLighting( int envmapMaskVar, int envmapMaskFrame,
|
||||
int bumpmapVar, int envmapVar,
|
||||
int bumpFrameVar, int envmapFrameVar,
|
||||
int envmapTintVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar,
|
||||
int bumpTransformVar, int fresnelReflectionVar,
|
||||
bool bBlend );
|
||||
void DrawBaseTextureBlend( int baseTextureVar, int baseTextureTransformVar,
|
||||
int baseTextureFrameVar,
|
||||
int baseTexture2Var, int baseTextureTransform2Var,
|
||||
int baseTextureFrame2Var, int colorVar, int alphaVar );
|
||||
void DrawWorldBumpedDiffuseLighting_Base_ps14( int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar, int baseTextureVar, int baseTextureTransformVar, int frameVar );
|
||||
void DrawWorldBumpedDiffuseLighting_Blend_ps14( int bumpmapVar, int bumpFrameVar, int bumpTransformVar,
|
||||
int baseTextureVar, int baseTextureTransformVar, int baseTextureFrameVar,
|
||||
int baseTexture2Var, int baseTextureTransform2Var, int baseTextureFrame2Var);
|
||||
void DrawWorldBumpedUsingVertexShader( int baseTextureVar, int baseTextureTransformVar,
|
||||
int bumpmapVar, int bumpFrameVar,
|
||||
int bumpTransformVar,
|
||||
int envmapMaskVar, int envmapMaskFrame,
|
||||
int envmapVar,
|
||||
int envmapFrameVar,
|
||||
int envmapTintVar, int colorVar, int alphaVar,
|
||||
int envmapContrastVar, int envmapSaturationVar, int frameVar, int fresnelReflectionVar,
|
||||
bool doBaseTexture2,
|
||||
int baseTexture2Var,
|
||||
int baseTextureTransform2Var,
|
||||
int baseTextureFrame2Var,
|
||||
bool bSSBump
|
||||
);
|
||||
|
||||
// Sets up hw morphing state for the vertex shader
|
||||
void SetHWMorphVertexShaderState( int nDimConst, int nSubrectConst, VertexTextureSampler_t morphSampler );
|
||||
|
||||
// Computes the shader index for vertex lit materials
|
||||
int ComputeVertexLitShaderIndex( bool bVertexLitGeneric, bool hasBump, bool hasEnvmap, bool hasVertexColor, bool bHasNormal ) const;
|
||||
|
||||
// Helper for setting up flashlight constants
|
||||
void SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms );
|
||||
|
||||
#if SUPPORT_DX8
|
||||
void DrawFlashlight_dx80( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
bool bBump, int bumpmapVar, int bumpmapFrame, int bumpTransform, int flashlightTextureVar,
|
||||
int flashlightTextureFrameVar, bool bLightmappedGeneric, bool bWorldVertexTransition,
|
||||
int nWorldVertexTransitionPassID, int baseTexture2Var, int baseTexture2FrameVar,
|
||||
bool bTeeth=false, int nTeethForwardVar=0, int nTeethIllumFactorVar=0 );
|
||||
#endif
|
||||
|
||||
struct DrawFlashlight_dx90_Vars_t
|
||||
{
|
||||
DrawFlashlight_dx90_Vars_t()
|
||||
{
|
||||
// set all ints to -1
|
||||
memset( this, 0xFF, sizeof(DrawFlashlight_dx90_Vars_t) );
|
||||
// set all bools to a default value.
|
||||
m_bBump = false;
|
||||
m_bLightmappedGeneric = false;
|
||||
m_bWorldVertexTransition = false;
|
||||
m_bTeeth = false;
|
||||
m_bSSBump = false;
|
||||
m_fSeamlessScale = 0.0;
|
||||
}
|
||||
bool m_bBump;
|
||||
bool m_bLightmappedGeneric;
|
||||
bool m_bWorldVertexTransition;
|
||||
bool m_bTeeth;
|
||||
int m_nBumpmapVar;
|
||||
int m_nBumpmapFrame;
|
||||
int m_nBumpTransform;
|
||||
int m_nFlashlightTextureVar;
|
||||
int m_nFlashlightTextureFrameVar;
|
||||
int m_nBaseTexture2Var;
|
||||
int m_nBaseTexture2FrameVar;
|
||||
int m_nBumpmap2Var;
|
||||
int m_nBumpmap2Frame;
|
||||
int m_nBump2Transform;
|
||||
int m_nDetailVar;
|
||||
int m_nDetailScale;
|
||||
int m_nDetailTextureCombineMode;
|
||||
int m_nDetailTextureBlendFactor;
|
||||
int m_nDetailTint;
|
||||
int m_nTeethForwardVar;
|
||||
int m_nTeethIllumFactorVar;
|
||||
int m_nAlphaTestReference;
|
||||
bool m_bSSBump;
|
||||
float m_fSeamlessScale; // 0.0 = not seamless
|
||||
};
|
||||
void DrawFlashlight_dx90( IMaterialVar** params,
|
||||
IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, DrawFlashlight_dx90_Vars_t &vars );
|
||||
#endif // GAME_SHADER_DLL
|
||||
|
||||
BlendType_t EvaluateBlendRequirements( int textureVar, bool isBaseTexture, int detailTextureVar = -1 );
|
||||
|
||||
void HashShadow2DJitter( const float fJitterSeed, float *fU, float* fV );
|
||||
|
||||
//Alpha tested materials can end up leaving garbage in the dest alpha buffer if they write depth.
|
||||
//This pass fills in the areas that passed the alpha test with depth in dest alpha
|
||||
//by writing only equal depth pixels and only if we should be writing depth to dest alpha
|
||||
void DrawEqualDepthToDestAlpha( void );
|
||||
|
||||
private:
|
||||
// Helper methods for VertexLitGenericPass
|
||||
// void UnlitGenericShadowState( int baseTextureVar, int detailVar, int envmapVar, int envmapMaskVar, bool doSkin );
|
||||
void UnlitGenericDynamicState( int baseTextureVar, int frameVar, int baseTextureTransformVar,
|
||||
int detailVar, int detailTransform, bool bDetailTransformIsScale, int envmapVar,
|
||||
int envMapFrameVar, int envmapMaskVar, int envmapMaskFrameVar,
|
||||
int envmapMaskScaleVar, int envmapTintVar );
|
||||
|
||||
// Converts a color + alpha into a vector4
|
||||
void ColorVarsToVector( int colorVar, int alphaVar, Vector4D &color );
|
||||
|
||||
};
|
||||
|
||||
FORCEINLINE void SetFlashLightColorFromState( FlashlightState_t const &state, IShaderDynamicAPI *pShaderAPI, int nPSRegister=28, bool bFlashlightNoLambert=false )
|
||||
{
|
||||
// Old code
|
||||
//float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x;
|
||||
//float flFlashlightScale = 1.0f / flToneMapScale;
|
||||
|
||||
// Fix to old code to keep flashlight from ever getting brighter than 1.0
|
||||
//float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x;
|
||||
//if ( flToneMapScale < 1.0f )
|
||||
// flToneMapScale = 1.0f;
|
||||
//float flFlashlightScale = 1.0f / flToneMapScale;
|
||||
|
||||
// Force flashlight to 25% bright always
|
||||
float flFlashlightScale = 0.25f;
|
||||
|
||||
if ( !g_pHardwareConfig->GetHDREnabled() )
|
||||
{
|
||||
// Non-HDR path requires 2.0 flashlight
|
||||
flFlashlightScale = 2.0f;
|
||||
}
|
||||
|
||||
// DX10 requires some hackery due to sRGB/blend ordering change from DX9
|
||||
if ( g_pHardwareConfig->UsesSRGBCorrectBlending() )
|
||||
{
|
||||
flFlashlightScale *= 2.5f; // Magic number that works well on the NVIDIA 8800
|
||||
}
|
||||
|
||||
// Generate pixel shader constant
|
||||
float const *pFlashlightColor = state.m_Color;
|
||||
float vPsConst[4] = { flFlashlightScale * pFlashlightColor[0], flFlashlightScale * pFlashlightColor[1], flFlashlightScale * pFlashlightColor[2], pFlashlightColor[3] };
|
||||
vPsConst[3] = bFlashlightNoLambert ? 2.0f : 0.0f; // This will be added to N.L before saturate to force a 1.0 N.L term
|
||||
|
||||
// Red flashlight for testing
|
||||
//vPsConst[0] = 0.5f; vPsConst[1] = 0.0f; vPsConst[2] = 0.0f;
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( nPSRegister, ( float * )vPsConst );
|
||||
}
|
||||
|
||||
FORCEINLINE float ShadowAttenFromState( FlashlightState_t const &state )
|
||||
{
|
||||
// DX10 requires some hackery due to sRGB/blend ordering change from DX9, which makes the shadows too light
|
||||
if ( g_pHardwareConfig->UsesSRGBCorrectBlending() )
|
||||
return state.m_flShadowAtten * 0.1f; // magic number
|
||||
|
||||
return state.m_flShadowAtten;
|
||||
}
|
||||
|
||||
FORCEINLINE float ShadowFilterFromState( FlashlightState_t const &state )
|
||||
{
|
||||
// We developed shadow maps at 1024, so we expect the penumbra size to have been tuned relative to that
|
||||
return state.m_flShadowFilterSize / 1024.0f;
|
||||
}
|
||||
|
||||
|
||||
// convenient material variable access functions for helpers to use.
|
||||
FORCEINLINE bool IsTextureSet( int nVar, IMaterialVar **params )
|
||||
{
|
||||
return ( nVar != -1 ) && ( params[nVar]->IsTexture() );
|
||||
}
|
||||
|
||||
FORCEINLINE bool IsBoolSet( int nVar, IMaterialVar **params )
|
||||
{
|
||||
return ( nVar != -1 ) && ( params[nVar]->GetIntValue() );
|
||||
}
|
||||
|
||||
FORCEINLINE int GetIntParam( int nVar, IMaterialVar **params, int nDefaultValue = 0 )
|
||||
{
|
||||
return ( nVar != -1 ) ? ( params[nVar]->GetIntValue() ) : nDefaultValue;
|
||||
}
|
||||
|
||||
FORCEINLINE float GetFloatParam( int nVar, IMaterialVar **params, float flDefaultValue = 0.0 )
|
||||
{
|
||||
return ( nVar != -1 ) ? ( params[nVar]->GetFloatValue() ) : flDefaultValue;
|
||||
}
|
||||
|
||||
FORCEINLINE void InitFloatParam( int nIndex, IMaterialVar **params, float flValue )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetFloatValue( flValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void InitIntParam( int nIndex, IMaterialVar **params, int nValue )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetIntValue( nValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ConVar;
|
||||
|
||||
#ifdef _DEBUG
|
||||
extern ConVar mat_envmaptintoverride;
|
||||
extern ConVar mat_envmaptintscale;
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BASEVSSHADER_H
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "SDK_screenspaceeffect_vs20.inc"
|
||||
#include "SDK_Bloom_ps20.inc"
|
||||
#include "SDK_Bloom_ps20b.inc"
|
||||
|
||||
BEGIN_VS_SHADER_FLAGS( SDK_Bloom, "Help for Bloom", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "" )
|
||||
SHADER_PARAM( BLURTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if( params[FBTEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( FBTEXTURE );
|
||||
}
|
||||
if( params[BLURTEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BLURTEXTURE );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
// Requires DX9 + above
|
||||
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
|
||||
{
|
||||
Assert( 0 );
|
||||
return "Wireframe";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
int fmt = VERTEX_POSITION;
|
||||
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
|
||||
|
||||
// Pre-cache shaders
|
||||
DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
}
|
||||
}
|
||||
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
|
||||
BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 );
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "SDK_screenspaceeffect_vs20.inc"
|
||||
#include "SDK_Bloom_ps20.inc"
|
||||
#include "SDK_Bloom_ps20b.inc"
|
||||
|
||||
BEGIN_VS_SHADER_FLAGS( SDK_Bloom, "Help for Bloom", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "" )
|
||||
SHADER_PARAM( BLURTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if( params[FBTEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( FBTEXTURE );
|
||||
}
|
||||
if( params[BLURTEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BLURTEXTURE );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
// Requires DX9 + above
|
||||
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
|
||||
{
|
||||
Assert( 0 );
|
||||
return "Wireframe";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
int fmt = VERTEX_POSITION;
|
||||
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
|
||||
|
||||
// Pre-cache shaders
|
||||
DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
}
|
||||
}
|
||||
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
|
||||
BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 );
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
||||
|
||||
@@ -1,407 +1,407 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// Utility class for building command buffers into memory
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef COMMANDBUILDER_H
|
||||
#define COMMANDBUILDER_H
|
||||
|
||||
#ifndef COMMANDBUFFER_H
|
||||
#include "shaderapi/commandbuffer.h"
|
||||
#endif
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
extern ConVar my_mat_fullbright;
|
||||
|
||||
template<int N> class CFixedCommandStorageBuffer
|
||||
{
|
||||
public:
|
||||
uint8 m_Data[N];
|
||||
|
||||
uint8 *m_pDataOut;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
size_t m_nNumBytesRemaining;
|
||||
#endif
|
||||
|
||||
FORCEINLINE CFixedCommandStorageBuffer( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
FORCEINLINE void EnsureCapacity( size_t sz )
|
||||
{
|
||||
Assert( m_nNumBytesRemaining >= sz );
|
||||
}
|
||||
|
||||
template<class T> FORCEINLINE void Put( T const &nValue )
|
||||
{
|
||||
EnsureCapacity( sizeof( T ) );
|
||||
*( reinterpret_cast<T *>( m_pDataOut ) ) = nValue;
|
||||
m_pDataOut += sizeof( nValue );
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining -= sizeof( nValue );
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void PutInt( int nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutFloat( float nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutPtr( void * pPtr )
|
||||
{
|
||||
Put( pPtr );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutMemory( const void *pMemory, size_t nBytes )
|
||||
{
|
||||
EnsureCapacity( nBytes );
|
||||
memcpy( m_pDataOut, pMemory, nBytes );
|
||||
m_pDataOut += nBytes;
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_pDataOut - m_Data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class S> class CCommandBufferBuilder
|
||||
{
|
||||
public:
|
||||
S m_Storage;
|
||||
|
||||
FORCEINLINE void End( void )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_END );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE IMaterialVar *Param( int nVar ) const
|
||||
{
|
||||
return CBaseShader::s_ppParams[nVar];
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstants( int nFirstConstant, int nConstants )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( nConstants );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData( float const *pSrcData )
|
||||
{
|
||||
m_Storage.PutFloat( pSrcData[0] );
|
||||
m_Storage.PutFloat( pSrcData[1] );
|
||||
m_Storage.PutFloat( pSrcData[2] );
|
||||
m_Storage.PutFloat( pSrcData[3] );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData4( float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
m_Storage.PutFloat( flVal0 );
|
||||
m_Storage.PutFloat( flVal1 );
|
||||
m_Storage.PutFloat( flVal2 );
|
||||
m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData, int nNumConstantsToSet )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, nNumConstantsToSet );
|
||||
m_Storage.PutMemory( pSrcData, 4 * sizeof( float ) * nNumConstantsToSet );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, int nVar )
|
||||
{
|
||||
SetPixelShaderConstant( nFirstConstant, Param( nVar )->GetVecValue() );
|
||||
}
|
||||
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar )
|
||||
{
|
||||
float val[4];
|
||||
Param(constantVar)->GetVecValue( val, 3 );
|
||||
val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] );
|
||||
val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] );
|
||||
val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] );
|
||||
val[3] = 1.0;
|
||||
SetPixelShaderConstant( pixelReg, val );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData4( flVal0, flVal1, flVal2, flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue )
|
||||
{
|
||||
if ( constantVar != -1 )
|
||||
{
|
||||
float val[3];
|
||||
Param(constantVar)->GetVecValue( val, 3);
|
||||
SetPixelShaderConstant4( pixelReg, val[0], val[1], val[2], fWValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData, int nConsts )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( nConsts );
|
||||
m_Storage.PutMemory( pSrcData, 4 * nConsts * sizeof( float ) );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( 1 );
|
||||
m_Storage.PutFloat( flVal0 );
|
||||
m_Storage.PutFloat( flVal1 );
|
||||
m_Storage.PutFloat( flVal2 );
|
||||
m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg, int transformVar, int scaleVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
Vector2D scale( 1, 1 );
|
||||
IMaterialVar* pScaleVar = Param( scaleVar );
|
||||
if (pScaleVar)
|
||||
{
|
||||
if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR)
|
||||
pScaleVar->GetVecValue( scale.Base(), 2 );
|
||||
else if (pScaleVar->IsDefined())
|
||||
scale[0] = scale[1] = pScaleVar->GetFloatValue();
|
||||
}
|
||||
|
||||
// Apply the scaling
|
||||
transformation[0][0] *= scale[0];
|
||||
transformation[0][1] *= scale[1];
|
||||
transformation[1][0] *= scale[0];
|
||||
transformation[1][1] *= scale[1];
|
||||
transformation[0][3] *= scale[0];
|
||||
transformation[1][3] *= scale[1];
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar )
|
||||
{
|
||||
if( g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 )
|
||||
{
|
||||
SetPixelShaderConstant( pixelReg, Param( tintVar)->GetVecValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicStateGammaToLinear( int pixelReg, int tintVar, float flAlphaValue = 1.0 )
|
||||
{
|
||||
if( ( tintVar != -1 ) && g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 )
|
||||
{
|
||||
float color[4];
|
||||
color[3] = flAlphaValue;
|
||||
Param( tintVar)->GetLinearVecValue( color, 3 );
|
||||
SetPixelShaderConstant( pixelReg, color );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, flAlphaValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void StoreEyePosInPixelShaderConstant( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_STORE_EYE_POS_IN_PSCONST );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void CommitPixelShaderLighting( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_COMMITPIXELSHADERLIGHTING );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderStateAmbientLightCube( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetAmbientCubeDynamicStateVertexShader( void )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderFogParams( int nReg )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETPIXELSHADERFOGPARAMS );
|
||||
m_Storage.PutInt( nReg );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindStandardTexture( Sampler_t nSampler, StandardTextureId_t nTextureId )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_BIND_STANDARD_TEXTURE );
|
||||
m_Storage.PutInt( nSampler );
|
||||
m_Storage.PutInt( nTextureId );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void BindTexture( Sampler_t nSampler, ShaderAPITextureHandle_t hTexture )
|
||||
{
|
||||
Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE );
|
||||
if ( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE );
|
||||
m_Storage.PutInt( nSampler );
|
||||
m_Storage.PutInt( hTexture );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void BindTexture( CBaseVSShader *pShader, Sampler_t nSampler, int nTextureVar, int nFrameVar )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar );
|
||||
BindTexture( nSampler, hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindMultiTexture( CBaseVSShader *pShader, Sampler_t nSampler1, Sampler_t nSampler2, int nTextureVar, int nFrameVar )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 0 );
|
||||
BindTexture( nSampler1, hTexture );
|
||||
hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 1 );
|
||||
BindTexture( nSampler2, hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderIndex( int nIndex )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_PSHINDEX );
|
||||
m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderIndex( int nIndex )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VSHINDEX );
|
||||
m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_DEPTH_FEATHERING_CONST );
|
||||
m_Storage.PutInt( iConstant );
|
||||
m_Storage.PutFloat( fDepthBlendScale );
|
||||
}
|
||||
|
||||
FORCEINLINE void Goto( uint8 *pCmdBuf )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_JUMP );
|
||||
m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
FORCEINLINE void Call( uint8 *pCmdBuf )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_JSR );
|
||||
m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_Storage.Reset();
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_Storage.Size();
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Storage.Base();
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // commandbuilder_h
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// Utility class for building command buffers into memory
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef COMMANDBUILDER_H
|
||||
#define COMMANDBUILDER_H
|
||||
|
||||
#ifndef COMMANDBUFFER_H
|
||||
#include "shaderapi/commandbuffer.h"
|
||||
#endif
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
extern ConVar my_mat_fullbright;
|
||||
|
||||
template<int N> class CFixedCommandStorageBuffer
|
||||
{
|
||||
public:
|
||||
uint8 m_Data[N];
|
||||
|
||||
uint8 *m_pDataOut;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
size_t m_nNumBytesRemaining;
|
||||
#endif
|
||||
|
||||
FORCEINLINE CFixedCommandStorageBuffer( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
FORCEINLINE void EnsureCapacity( size_t sz )
|
||||
{
|
||||
Assert( m_nNumBytesRemaining >= sz );
|
||||
}
|
||||
|
||||
template<class T> FORCEINLINE void Put( T const &nValue )
|
||||
{
|
||||
EnsureCapacity( sizeof( T ) );
|
||||
*( reinterpret_cast<T *>( m_pDataOut ) ) = nValue;
|
||||
m_pDataOut += sizeof( nValue );
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining -= sizeof( nValue );
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void PutInt( int nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutFloat( float nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutPtr( void * pPtr )
|
||||
{
|
||||
Put( pPtr );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutMemory( const void *pMemory, size_t nBytes )
|
||||
{
|
||||
EnsureCapacity( nBytes );
|
||||
memcpy( m_pDataOut, pMemory, nBytes );
|
||||
m_pDataOut += nBytes;
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_pDataOut - m_Data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class S> class CCommandBufferBuilder
|
||||
{
|
||||
public:
|
||||
S m_Storage;
|
||||
|
||||
FORCEINLINE void End( void )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_END );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE IMaterialVar *Param( int nVar ) const
|
||||
{
|
||||
return CBaseShader::s_ppParams[nVar];
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstants( int nFirstConstant, int nConstants )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( nConstants );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData( float const *pSrcData )
|
||||
{
|
||||
m_Storage.PutFloat( pSrcData[0] );
|
||||
m_Storage.PutFloat( pSrcData[1] );
|
||||
m_Storage.PutFloat( pSrcData[2] );
|
||||
m_Storage.PutFloat( pSrcData[3] );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData4( float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
m_Storage.PutFloat( flVal0 );
|
||||
m_Storage.PutFloat( flVal1 );
|
||||
m_Storage.PutFloat( flVal2 );
|
||||
m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData, int nNumConstantsToSet )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, nNumConstantsToSet );
|
||||
m_Storage.PutMemory( pSrcData, 4 * sizeof( float ) * nNumConstantsToSet );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, int nVar )
|
||||
{
|
||||
SetPixelShaderConstant( nFirstConstant, Param( nVar )->GetVecValue() );
|
||||
}
|
||||
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar )
|
||||
{
|
||||
float val[4];
|
||||
Param(constantVar)->GetVecValue( val, 3 );
|
||||
val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] );
|
||||
val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] );
|
||||
val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] );
|
||||
val[3] = 1.0;
|
||||
SetPixelShaderConstant( pixelReg, val );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData4( flVal0, flVal1, flVal2, flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue )
|
||||
{
|
||||
if ( constantVar != -1 )
|
||||
{
|
||||
float val[3];
|
||||
Param(constantVar)->GetVecValue( val, 3);
|
||||
SetPixelShaderConstant4( pixelReg, val[0], val[1], val[2], fWValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData, int nConsts )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( nConsts );
|
||||
m_Storage.PutMemory( pSrcData, 4 * nConsts * sizeof( float ) );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
m_Storage.PutInt( nFirstConstant );
|
||||
m_Storage.PutInt( 1 );
|
||||
m_Storage.PutFloat( flVal0 );
|
||||
m_Storage.PutFloat( flVal1 );
|
||||
m_Storage.PutFloat( flVal2 );
|
||||
m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg, int transformVar, int scaleVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
Vector2D scale( 1, 1 );
|
||||
IMaterialVar* pScaleVar = Param( scaleVar );
|
||||
if (pScaleVar)
|
||||
{
|
||||
if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR)
|
||||
pScaleVar->GetVecValue( scale.Base(), 2 );
|
||||
else if (pScaleVar->IsDefined())
|
||||
scale[0] = scale[1] = pScaleVar->GetFloatValue();
|
||||
}
|
||||
|
||||
// Apply the scaling
|
||||
transformation[0][0] *= scale[0];
|
||||
transformation[0][1] *= scale[1];
|
||||
transformation[1][0] *= scale[0];
|
||||
transformation[1][1] *= scale[1];
|
||||
transformation[0][3] *= scale[0];
|
||||
transformation[1][3] *= scale[1];
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar )
|
||||
{
|
||||
if( g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 )
|
||||
{
|
||||
SetPixelShaderConstant( pixelReg, Param( tintVar)->GetVecValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicStateGammaToLinear( int pixelReg, int tintVar, float flAlphaValue = 1.0 )
|
||||
{
|
||||
if( ( tintVar != -1 ) && g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 )
|
||||
{
|
||||
float color[4];
|
||||
color[3] = flAlphaValue;
|
||||
Param( tintVar)->GetLinearVecValue( color, 3 );
|
||||
SetPixelShaderConstant( pixelReg, color );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, flAlphaValue );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void StoreEyePosInPixelShaderConstant( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_STORE_EYE_POS_IN_PSCONST );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void CommitPixelShaderLighting( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_COMMITPIXELSHADERLIGHTING );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderStateAmbientLightCube( int nConst )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE );
|
||||
m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetAmbientCubeDynamicStateVertexShader( void )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderFogParams( int nReg )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SETPIXELSHADERFOGPARAMS );
|
||||
m_Storage.PutInt( nReg );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindStandardTexture( Sampler_t nSampler, StandardTextureId_t nTextureId )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_BIND_STANDARD_TEXTURE );
|
||||
m_Storage.PutInt( nSampler );
|
||||
m_Storage.PutInt( nTextureId );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void BindTexture( Sampler_t nSampler, ShaderAPITextureHandle_t hTexture )
|
||||
{
|
||||
Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE );
|
||||
if ( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE );
|
||||
m_Storage.PutInt( nSampler );
|
||||
m_Storage.PutInt( hTexture );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void BindTexture( CBaseVSShader *pShader, Sampler_t nSampler, int nTextureVar, int nFrameVar )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar );
|
||||
BindTexture( nSampler, hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindMultiTexture( CBaseVSShader *pShader, Sampler_t nSampler1, Sampler_t nSampler2, int nTextureVar, int nFrameVar )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 0 );
|
||||
BindTexture( nSampler1, hTexture );
|
||||
hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 1 );
|
||||
BindTexture( nSampler2, hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderIndex( int nIndex )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_PSHINDEX );
|
||||
m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderIndex( int nIndex )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_VSHINDEX );
|
||||
m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_SET_DEPTH_FEATHERING_CONST );
|
||||
m_Storage.PutInt( iConstant );
|
||||
m_Storage.PutFloat( fDepthBlendScale );
|
||||
}
|
||||
|
||||
FORCEINLINE void Goto( uint8 *pCmdBuf )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_JUMP );
|
||||
m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
FORCEINLINE void Call( uint8 *pCmdBuf )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_JSR );
|
||||
m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_Storage.Reset();
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_Storage.Size();
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Storage.Base();
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // commandbuilder_h
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,326 +1,326 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_FXC_H_
|
||||
#define COMMON_FXC_H_
|
||||
|
||||
#include "common_pragmas.h"
|
||||
#include "common_hlsl_cpp_consts.h"
|
||||
|
||||
#ifdef NV3X
|
||||
# define HALF half
|
||||
# define HALF2 half2
|
||||
# define HALF3 half3
|
||||
# define HALF4 half4
|
||||
# define HALF3x3 half3x3
|
||||
# define HALF3x4 half3x4
|
||||
# define HALF4x3 half4x3
|
||||
# define HALF_CONSTANT( _constant ) ((HALF)_constant)
|
||||
#else
|
||||
# define HALF float
|
||||
# define HALF2 float2
|
||||
# define HALF3 float3
|
||||
# define HALF4 float4
|
||||
# define HALF3x3 float3x3
|
||||
# define HALF3x4 float3x4
|
||||
# define HALF4x3 float4x3
|
||||
# define HALF_CONSTANT( _constant ) _constant
|
||||
#endif
|
||||
|
||||
// This is where all common code for both vertex and pixel shaders.
|
||||
#define OO_SQRT_3 0.57735025882720947f
|
||||
static const HALF3 bumpBasis[3] = {
|
||||
HALF3( 0.81649661064147949f, 0.0f, OO_SQRT_3 ),
|
||||
HALF3( -0.40824833512306213f, 0.70710676908493042f, OO_SQRT_3 ),
|
||||
HALF3( -0.40824821591377258f, -0.7071068286895752f, OO_SQRT_3 )
|
||||
};
|
||||
static const HALF3 bumpBasisTranspose[3] = {
|
||||
HALF3( 0.81649661064147949f, -0.40824833512306213f, -0.40824833512306213f ),
|
||||
HALF3( 0.0f, 0.70710676908493042f, -0.7071068286895752f ),
|
||||
HALF3( OO_SQRT_3, OO_SQRT_3, OO_SQRT_3 )
|
||||
};
|
||||
|
||||
#if defined( _X360 )
|
||||
#define REVERSE_DEPTH_ON_X360 //uncomment to use D3DFMT_D24FS8 with an inverted depth viewport for better performance. Keep this in sync with the same named #define in public/shaderapi/shareddefs.h
|
||||
//Note that the reversal happens in the viewport. So ONLY reading back from a depth texture should be affected. Projected math is unaffected.
|
||||
#endif
|
||||
|
||||
HALF3 CalcReflectionVectorNormalized( HALF3 normal, HALF3 eyeVector )
|
||||
{
|
||||
// FIXME: might be better of normalizing with a normalizing cube map and
|
||||
// get rid of the dot( normal, normal )
|
||||
// compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v
|
||||
return 2.0 * ( dot( normal, eyeVector ) / dot( normal, normal ) ) * normal - eyeVector;
|
||||
}
|
||||
|
||||
HALF3 CalcReflectionVectorUnnormalized( HALF3 normal, HALF3 eyeVector )
|
||||
{
|
||||
// FIXME: might be better of normalizing with a normalizing cube map and
|
||||
// get rid of the dot( normal, normal )
|
||||
// compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v
|
||||
// multiply all values through by N.N. uniformly scaling reflection vector won't affect result
|
||||
// since it is used in a cubemap lookup
|
||||
return (2.0*(dot( normal, eyeVector ))*normal) - (dot( normal, normal )*eyeVector);
|
||||
}
|
||||
|
||||
float3 HuePreservingColorClamp( float3 c )
|
||||
{
|
||||
// Get the max of all of the color components and a specified maximum amount
|
||||
float maximum = max( max( c.x, c.y ), max( c.z, 1.0f ) );
|
||||
|
||||
return (c / maximum);
|
||||
}
|
||||
|
||||
HALF3 HuePreservingColorClamp( HALF3 c, HALF maxVal )
|
||||
{
|
||||
// Get the max of all of the color components and a specified maximum amount
|
||||
float maximum = max( max( c.x, c.y ), max( c.z, maxVal ) );
|
||||
return (c * ( maxVal / maximum ) );
|
||||
}
|
||||
|
||||
#if (AA_CLAMP==1)
|
||||
HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord )
|
||||
{
|
||||
HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99;
|
||||
result += Lightmap3Coord;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord,
|
||||
out HALF2 bumpCoord1,
|
||||
out HALF2 bumpCoord2,
|
||||
out HALF2 bumpCoord3 )
|
||||
{
|
||||
HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99;
|
||||
result += Lightmap3Coord;
|
||||
bumpCoord1 = result + HALF2(Lightmap1and2Coord.z, 0);
|
||||
bumpCoord2 = result + 2*HALF2(Lightmap1and2Coord.z, 0);
|
||||
bumpCoord3 = result + 3*HALF2(Lightmap1and2Coord.z, 0);
|
||||
}
|
||||
#else
|
||||
HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord )
|
||||
{
|
||||
return Lightmap1and2Coord.xy;
|
||||
}
|
||||
|
||||
void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord,
|
||||
out HALF2 bumpCoord1,
|
||||
out HALF2 bumpCoord2,
|
||||
out HALF2 bumpCoord3 )
|
||||
{
|
||||
bumpCoord1 = Lightmap1and2Coord.xy;
|
||||
bumpCoord2 = Lightmap1and2Coord.wz; // reversed order!!!
|
||||
bumpCoord3 = Lightmap3Coord.xy;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Versions of matrix multiply functions which force HLSL compiler to explictly use DOTs,
|
||||
// not giving it the option of using MAD expansion. In a perfect world, the compiler would
|
||||
// always pick the best strategy, and these shouldn't be needed.. but.. well.. umm..
|
||||
//
|
||||
// lorenmcq
|
||||
|
||||
float3 mul3x3(float3 v, float3x3 m)
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2]));
|
||||
#else
|
||||
// xbox360 fxc.exe (new back end) borks with transposes, generates bad code
|
||||
return mul( v, m );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 mul4x3(float4 v, float4x3 m)
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2]));
|
||||
#else
|
||||
// xbox360 fxc.exe (new back end) borks with transposes, generates bad code
|
||||
return mul( v, m );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 DecompressHDR( float4 input )
|
||||
{
|
||||
return input.rgb * input.a * MAX_HDR_OVERBRIGHT;
|
||||
}
|
||||
|
||||
float4 CompressHDR( float3 input )
|
||||
{
|
||||
// FIXME: want to use min so that we clamp to white, but what happens if we
|
||||
// have an albedo component that's less than 1/MAX_HDR_OVERBRIGHT?
|
||||
// float fMax = max( max( color.r, color.g ), color.b );
|
||||
float4 output;
|
||||
float fMax = min( min( input.r, input.g ), input.b );
|
||||
if( fMax > 1.0f )
|
||||
{
|
||||
float oofMax = 1.0f / fMax;
|
||||
output.rgb = oofMax * input.rgb;
|
||||
output.a = min( fMax / MAX_HDR_OVERBRIGHT, 1.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
output.rgb = input.rgb;
|
||||
output.a = 0.0f;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
float3 LinearToGamma( const float3 f3linear )
|
||||
{
|
||||
return pow( f3linear, 1.0f / 2.2f );
|
||||
}
|
||||
|
||||
float4 LinearToGamma( const float4 f4linear )
|
||||
{
|
||||
return float4( pow( f4linear.xyz, 1.0f / 2.2f ), f4linear.w );
|
||||
}
|
||||
|
||||
float LinearToGamma( const float f1linear )
|
||||
{
|
||||
return pow( f1linear, 1.0f / 2.2f );
|
||||
}
|
||||
|
||||
float3 GammaToLinear( const float3 gamma )
|
||||
{
|
||||
return pow( gamma, 2.2f );
|
||||
}
|
||||
|
||||
float4 GammaToLinear( const float4 gamma )
|
||||
{
|
||||
return float4( pow( gamma.xyz, 2.2f ), gamma.w );
|
||||
}
|
||||
|
||||
float GammaToLinear( const float gamma )
|
||||
{
|
||||
return pow( gamma, 2.2f );
|
||||
}
|
||||
|
||||
// These two functions use the actual sRGB math
|
||||
float SrgbGammaToLinear( float flSrgbGammaValue )
|
||||
{
|
||||
float x = saturate( flSrgbGammaValue );
|
||||
return ( x <= 0.04045f ) ? ( x / 12.92f ) : ( pow( ( x + 0.055f ) / 1.055f, 2.4f ) );
|
||||
}
|
||||
|
||||
float SrgbLinearToGamma( float flLinearValue )
|
||||
{
|
||||
float x = saturate( flLinearValue );
|
||||
return ( x <= 0.0031308f ) ? ( x * 12.92f ) : ( 1.055f * pow( x, ( 1.0f / 2.4f ) ) ) - 0.055f;
|
||||
}
|
||||
|
||||
// These twofunctions use the XBox 360's exact piecewise linear algorithm
|
||||
float X360GammaToLinear( float fl360GammaValue )
|
||||
{
|
||||
float flLinearValue;
|
||||
|
||||
fl360GammaValue = saturate( fl360GammaValue );
|
||||
if ( fl360GammaValue < ( 96.0f / 255.0f ) )
|
||||
{
|
||||
if ( fl360GammaValue < ( 64.0f / 255.0f ) )
|
||||
{
|
||||
flLinearValue = fl360GammaValue * 255.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 2.0f ) - 64.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 512.0f ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fl360GammaValue < ( 192.0f / 255.0f ) )
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 4.0f ) - 256.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 256.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 8.0f ) - 1024.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 128.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
flLinearValue *= 1.0f / 1023.0f;
|
||||
|
||||
flLinearValue = saturate( flLinearValue );
|
||||
return flLinearValue;
|
||||
}
|
||||
|
||||
float X360LinearToGamma( float flLinearValue )
|
||||
{
|
||||
float fl360GammaValue;
|
||||
|
||||
flLinearValue = saturate( flLinearValue );
|
||||
if ( flLinearValue < ( 128.0f / 1023.0f ) )
|
||||
{
|
||||
if ( flLinearValue < ( 64.0f / 1023.0f ) )
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( 1023.0f * ( 1.0f / 255.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f / 2.0f ) * ( 1.0f / 255.0f ) ) + ( 32.0f / 255.0f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( flLinearValue < ( 512.0f / 1023.0f ) )
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f / 4.0f ) * ( 1.0f / 255.0f ) ) + ( 64.0f / 255.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f /8.0f ) * ( 1.0f / 255.0f ) ) + ( 128.0f /255.0f ); // 1.0 -> 1.0034313725490196078431372549016
|
||||
if ( fl360GammaValue > 1.0f )
|
||||
{
|
||||
fl360GammaValue = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fl360GammaValue = saturate( fl360GammaValue );
|
||||
return fl360GammaValue;
|
||||
}
|
||||
|
||||
float SrgbGammaTo360Gamma( float flSrgbGammaValue )
|
||||
{
|
||||
float flLinearValue = SrgbGammaToLinear( flSrgbGammaValue );
|
||||
float fl360GammaValue = X360LinearToGamma( flLinearValue );
|
||||
return fl360GammaValue;
|
||||
}
|
||||
|
||||
float3 Vec3WorldToTangent( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
float3 vTangentVector;
|
||||
vTangentVector.x = dot( iWorldVector.xyz, iWorldTangent.xyz );
|
||||
vTangentVector.y = dot( iWorldVector.xyz, iWorldBinormal.xyz );
|
||||
vTangentVector.z = dot( iWorldVector.xyz, iWorldNormal.xyz );
|
||||
return vTangentVector.xyz; // Return without normalizing
|
||||
}
|
||||
|
||||
float3 Vec3WorldToTangentNormalized( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
return normalize( Vec3WorldToTangent( iWorldVector, iWorldNormal, iWorldTangent, iWorldBinormal ) );
|
||||
}
|
||||
|
||||
float3 Vec3TangentToWorld( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
float3 vWorldVector;
|
||||
vWorldVector.xyz = iTangentVector.x * iWorldTangent.xyz;
|
||||
vWorldVector.xyz += iTangentVector.y * iWorldBinormal.xyz;
|
||||
vWorldVector.xyz += iTangentVector.z * iWorldNormal.xyz;
|
||||
return vWorldVector.xyz; // Return without normalizing
|
||||
}
|
||||
|
||||
float3 Vec3TangentToWorldNormalized( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
return normalize( Vec3TangentToWorld( iTangentVector, iWorldNormal, iWorldTangent, iWorldBinormal ) );
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_FXC_H_
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_FXC_H_
|
||||
#define COMMON_FXC_H_
|
||||
|
||||
#include "common_pragmas.h"
|
||||
#include "common_hlsl_cpp_consts.h"
|
||||
|
||||
#ifdef NV3X
|
||||
# define HALF half
|
||||
# define HALF2 half2
|
||||
# define HALF3 half3
|
||||
# define HALF4 half4
|
||||
# define HALF3x3 half3x3
|
||||
# define HALF3x4 half3x4
|
||||
# define HALF4x3 half4x3
|
||||
# define HALF_CONSTANT( _constant ) ((HALF)_constant)
|
||||
#else
|
||||
# define HALF float
|
||||
# define HALF2 float2
|
||||
# define HALF3 float3
|
||||
# define HALF4 float4
|
||||
# define HALF3x3 float3x3
|
||||
# define HALF3x4 float3x4
|
||||
# define HALF4x3 float4x3
|
||||
# define HALF_CONSTANT( _constant ) _constant
|
||||
#endif
|
||||
|
||||
// This is where all common code for both vertex and pixel shaders.
|
||||
#define OO_SQRT_3 0.57735025882720947f
|
||||
static const HALF3 bumpBasis[3] = {
|
||||
HALF3( 0.81649661064147949f, 0.0f, OO_SQRT_3 ),
|
||||
HALF3( -0.40824833512306213f, 0.70710676908493042f, OO_SQRT_3 ),
|
||||
HALF3( -0.40824821591377258f, -0.7071068286895752f, OO_SQRT_3 )
|
||||
};
|
||||
static const HALF3 bumpBasisTranspose[3] = {
|
||||
HALF3( 0.81649661064147949f, -0.40824833512306213f, -0.40824833512306213f ),
|
||||
HALF3( 0.0f, 0.70710676908493042f, -0.7071068286895752f ),
|
||||
HALF3( OO_SQRT_3, OO_SQRT_3, OO_SQRT_3 )
|
||||
};
|
||||
|
||||
#if defined( _X360 )
|
||||
#define REVERSE_DEPTH_ON_X360 //uncomment to use D3DFMT_D24FS8 with an inverted depth viewport for better performance. Keep this in sync with the same named #define in public/shaderapi/shareddefs.h
|
||||
//Note that the reversal happens in the viewport. So ONLY reading back from a depth texture should be affected. Projected math is unaffected.
|
||||
#endif
|
||||
|
||||
HALF3 CalcReflectionVectorNormalized( HALF3 normal, HALF3 eyeVector )
|
||||
{
|
||||
// FIXME: might be better of normalizing with a normalizing cube map and
|
||||
// get rid of the dot( normal, normal )
|
||||
// compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v
|
||||
return 2.0 * ( dot( normal, eyeVector ) / dot( normal, normal ) ) * normal - eyeVector;
|
||||
}
|
||||
|
||||
HALF3 CalcReflectionVectorUnnormalized( HALF3 normal, HALF3 eyeVector )
|
||||
{
|
||||
// FIXME: might be better of normalizing with a normalizing cube map and
|
||||
// get rid of the dot( normal, normal )
|
||||
// compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v
|
||||
// multiply all values through by N.N. uniformly scaling reflection vector won't affect result
|
||||
// since it is used in a cubemap lookup
|
||||
return (2.0*(dot( normal, eyeVector ))*normal) - (dot( normal, normal )*eyeVector);
|
||||
}
|
||||
|
||||
float3 HuePreservingColorClamp( float3 c )
|
||||
{
|
||||
// Get the max of all of the color components and a specified maximum amount
|
||||
float maximum = max( max( c.x, c.y ), max( c.z, 1.0f ) );
|
||||
|
||||
return (c / maximum);
|
||||
}
|
||||
|
||||
HALF3 HuePreservingColorClamp( HALF3 c, HALF maxVal )
|
||||
{
|
||||
// Get the max of all of the color components and a specified maximum amount
|
||||
float maximum = max( max( c.x, c.y ), max( c.z, maxVal ) );
|
||||
return (c * ( maxVal / maximum ) );
|
||||
}
|
||||
|
||||
#if (AA_CLAMP==1)
|
||||
HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord )
|
||||
{
|
||||
HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99;
|
||||
result += Lightmap3Coord;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord,
|
||||
out HALF2 bumpCoord1,
|
||||
out HALF2 bumpCoord2,
|
||||
out HALF2 bumpCoord3 )
|
||||
{
|
||||
HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99;
|
||||
result += Lightmap3Coord;
|
||||
bumpCoord1 = result + HALF2(Lightmap1and2Coord.z, 0);
|
||||
bumpCoord2 = result + 2*HALF2(Lightmap1and2Coord.z, 0);
|
||||
bumpCoord3 = result + 3*HALF2(Lightmap1and2Coord.z, 0);
|
||||
}
|
||||
#else
|
||||
HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord )
|
||||
{
|
||||
return Lightmap1and2Coord.xy;
|
||||
}
|
||||
|
||||
void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord,
|
||||
out HALF2 bumpCoord1,
|
||||
out HALF2 bumpCoord2,
|
||||
out HALF2 bumpCoord3 )
|
||||
{
|
||||
bumpCoord1 = Lightmap1and2Coord.xy;
|
||||
bumpCoord2 = Lightmap1and2Coord.wz; // reversed order!!!
|
||||
bumpCoord3 = Lightmap3Coord.xy;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Versions of matrix multiply functions which force HLSL compiler to explictly use DOTs,
|
||||
// not giving it the option of using MAD expansion. In a perfect world, the compiler would
|
||||
// always pick the best strategy, and these shouldn't be needed.. but.. well.. umm..
|
||||
//
|
||||
// lorenmcq
|
||||
|
||||
float3 mul3x3(float3 v, float3x3 m)
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2]));
|
||||
#else
|
||||
// xbox360 fxc.exe (new back end) borks with transposes, generates bad code
|
||||
return mul( v, m );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 mul4x3(float4 v, float4x3 m)
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2]));
|
||||
#else
|
||||
// xbox360 fxc.exe (new back end) borks with transposes, generates bad code
|
||||
return mul( v, m );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 DecompressHDR( float4 input )
|
||||
{
|
||||
return input.rgb * input.a * MAX_HDR_OVERBRIGHT;
|
||||
}
|
||||
|
||||
float4 CompressHDR( float3 input )
|
||||
{
|
||||
// FIXME: want to use min so that we clamp to white, but what happens if we
|
||||
// have an albedo component that's less than 1/MAX_HDR_OVERBRIGHT?
|
||||
// float fMax = max( max( color.r, color.g ), color.b );
|
||||
float4 output;
|
||||
float fMax = min( min( input.r, input.g ), input.b );
|
||||
if( fMax > 1.0f )
|
||||
{
|
||||
float oofMax = 1.0f / fMax;
|
||||
output.rgb = oofMax * input.rgb;
|
||||
output.a = min( fMax / MAX_HDR_OVERBRIGHT, 1.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
output.rgb = input.rgb;
|
||||
output.a = 0.0f;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
float3 LinearToGamma( const float3 f3linear )
|
||||
{
|
||||
return pow( f3linear, 1.0f / 2.2f );
|
||||
}
|
||||
|
||||
float4 LinearToGamma( const float4 f4linear )
|
||||
{
|
||||
return float4( pow( f4linear.xyz, 1.0f / 2.2f ), f4linear.w );
|
||||
}
|
||||
|
||||
float LinearToGamma( const float f1linear )
|
||||
{
|
||||
return pow( f1linear, 1.0f / 2.2f );
|
||||
}
|
||||
|
||||
float3 GammaToLinear( const float3 gamma )
|
||||
{
|
||||
return pow( gamma, 2.2f );
|
||||
}
|
||||
|
||||
float4 GammaToLinear( const float4 gamma )
|
||||
{
|
||||
return float4( pow( gamma.xyz, 2.2f ), gamma.w );
|
||||
}
|
||||
|
||||
float GammaToLinear( const float gamma )
|
||||
{
|
||||
return pow( gamma, 2.2f );
|
||||
}
|
||||
|
||||
// These two functions use the actual sRGB math
|
||||
float SrgbGammaToLinear( float flSrgbGammaValue )
|
||||
{
|
||||
float x = saturate( flSrgbGammaValue );
|
||||
return ( x <= 0.04045f ) ? ( x / 12.92f ) : ( pow( ( x + 0.055f ) / 1.055f, 2.4f ) );
|
||||
}
|
||||
|
||||
float SrgbLinearToGamma( float flLinearValue )
|
||||
{
|
||||
float x = saturate( flLinearValue );
|
||||
return ( x <= 0.0031308f ) ? ( x * 12.92f ) : ( 1.055f * pow( x, ( 1.0f / 2.4f ) ) ) - 0.055f;
|
||||
}
|
||||
|
||||
// These twofunctions use the XBox 360's exact piecewise linear algorithm
|
||||
float X360GammaToLinear( float fl360GammaValue )
|
||||
{
|
||||
float flLinearValue;
|
||||
|
||||
fl360GammaValue = saturate( fl360GammaValue );
|
||||
if ( fl360GammaValue < ( 96.0f / 255.0f ) )
|
||||
{
|
||||
if ( fl360GammaValue < ( 64.0f / 255.0f ) )
|
||||
{
|
||||
flLinearValue = fl360GammaValue * 255.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 2.0f ) - 64.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 512.0f ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fl360GammaValue < ( 192.0f / 255.0f ) )
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 4.0f ) - 256.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 256.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
flLinearValue = fl360GammaValue * ( 255.0f * 8.0f ) - 1024.0f;
|
||||
flLinearValue += floor( flLinearValue * ( 1.0f / 128.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
flLinearValue *= 1.0f / 1023.0f;
|
||||
|
||||
flLinearValue = saturate( flLinearValue );
|
||||
return flLinearValue;
|
||||
}
|
||||
|
||||
float X360LinearToGamma( float flLinearValue )
|
||||
{
|
||||
float fl360GammaValue;
|
||||
|
||||
flLinearValue = saturate( flLinearValue );
|
||||
if ( flLinearValue < ( 128.0f / 1023.0f ) )
|
||||
{
|
||||
if ( flLinearValue < ( 64.0f / 1023.0f ) )
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( 1023.0f * ( 1.0f / 255.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f / 2.0f ) * ( 1.0f / 255.0f ) ) + ( 32.0f / 255.0f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( flLinearValue < ( 512.0f / 1023.0f ) )
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f / 4.0f ) * ( 1.0f / 255.0f ) ) + ( 64.0f / 255.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
fl360GammaValue = flLinearValue * ( ( 1023.0f /8.0f ) * ( 1.0f / 255.0f ) ) + ( 128.0f /255.0f ); // 1.0 -> 1.0034313725490196078431372549016
|
||||
if ( fl360GammaValue > 1.0f )
|
||||
{
|
||||
fl360GammaValue = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fl360GammaValue = saturate( fl360GammaValue );
|
||||
return fl360GammaValue;
|
||||
}
|
||||
|
||||
float SrgbGammaTo360Gamma( float flSrgbGammaValue )
|
||||
{
|
||||
float flLinearValue = SrgbGammaToLinear( flSrgbGammaValue );
|
||||
float fl360GammaValue = X360LinearToGamma( flLinearValue );
|
||||
return fl360GammaValue;
|
||||
}
|
||||
|
||||
float3 Vec3WorldToTangent( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
float3 vTangentVector;
|
||||
vTangentVector.x = dot( iWorldVector.xyz, iWorldTangent.xyz );
|
||||
vTangentVector.y = dot( iWorldVector.xyz, iWorldBinormal.xyz );
|
||||
vTangentVector.z = dot( iWorldVector.xyz, iWorldNormal.xyz );
|
||||
return vTangentVector.xyz; // Return without normalizing
|
||||
}
|
||||
|
||||
float3 Vec3WorldToTangentNormalized( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
return normalize( Vec3WorldToTangent( iWorldVector, iWorldNormal, iWorldTangent, iWorldBinormal ) );
|
||||
}
|
||||
|
||||
float3 Vec3TangentToWorld( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
float3 vWorldVector;
|
||||
vWorldVector.xyz = iTangentVector.x * iWorldTangent.xyz;
|
||||
vWorldVector.xyz += iTangentVector.y * iWorldBinormal.xyz;
|
||||
vWorldVector.xyz += iTangentVector.z * iWorldNormal.xyz;
|
||||
return vWorldVector.xyz; // Return without normalizing
|
||||
}
|
||||
|
||||
float3 Vec3TangentToWorldNormalized( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal )
|
||||
{
|
||||
return normalize( Vec3TangentToWorld( iTangentVector, iWorldNormal, iWorldTangent, iWorldBinormal ) );
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_FXC_H_
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_FXC2_H_
|
||||
#define COMMON_FXC2_H_
|
||||
|
||||
// This file is here so you can add new utility functions without
|
||||
// changing common_fxc.h and causing a recompile of the entire universe.
|
||||
|
||||
float LinearToMonochrome ( float3 r )
|
||||
{
|
||||
return dot( r, float3( 0.299f, 0.587f, 0.114f ) );
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_FXC2_H_
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_FXC2_H_
|
||||
#define COMMON_FXC2_H_
|
||||
|
||||
// This file is here so you can add new utility functions without
|
||||
// changing common_fxc.h and causing a recompile of the entire universe.
|
||||
|
||||
float LinearToMonochrome ( float3 r )
|
||||
{
|
||||
return dot( r, float3( 0.299f, 0.587f, 0.114f ) );
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_FXC2_H_
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_HLSL_CONSTS_H_
|
||||
#define COMMON_HLSL_CONSTS_H_
|
||||
|
||||
#ifdef NV3X
|
||||
#define PSHADER_VECT_SCALE 20.0
|
||||
#define VSHADER_VECT_SCALE (1.0 / (PSHADER_VECT_SCALE) )
|
||||
#else
|
||||
#define PSHADER_VECT_SCALE 1.0
|
||||
#define VSHADER_VECT_SCALE 1.0
|
||||
#endif
|
||||
|
||||
// GR - HDR luminance maps to 0..n range
|
||||
// IMPORTANT: Keep the same value as in materialsystem_global.h
|
||||
// HDRFIXME: Make this a pixel shader constant?
|
||||
#define MAX_HDR_OVERBRIGHT 16.0f
|
||||
|
||||
#define LINEAR_FOG_COLOR 29
|
||||
#define TONE_MAPPING_SCALE_PSH_CONSTANT 30
|
||||
|
||||
#endif //#ifndef COMMON_HLSL_CONSTS_H_
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_HLSL_CONSTS_H_
|
||||
#define COMMON_HLSL_CONSTS_H_
|
||||
|
||||
#ifdef NV3X
|
||||
#define PSHADER_VECT_SCALE 20.0
|
||||
#define VSHADER_VECT_SCALE (1.0 / (PSHADER_VECT_SCALE) )
|
||||
#else
|
||||
#define PSHADER_VECT_SCALE 1.0
|
||||
#define VSHADER_VECT_SCALE 1.0
|
||||
#endif
|
||||
|
||||
// GR - HDR luminance maps to 0..n range
|
||||
// IMPORTANT: Keep the same value as in materialsystem_global.h
|
||||
// HDRFIXME: Make this a pixel shader constant?
|
||||
#define MAX_HDR_OVERBRIGHT 16.0f
|
||||
|
||||
#define LINEAR_FOG_COLOR 29
|
||||
#define TONE_MAPPING_SCALE_PSH_CONSTANT 30
|
||||
|
||||
#endif //#ifndef COMMON_HLSL_CONSTS_H_
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
|
||||
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
|
||||
{
|
||||
vResultBase = 0;
|
||||
vResultBase2 = 0;
|
||||
vResultBump = 0;
|
||||
|
||||
if ( !bBump )
|
||||
{
|
||||
vResultBump = float4(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
#if SEAMLESS
|
||||
|
||||
vWeights = max( vWeights - 0.3, 0 );
|
||||
|
||||
vWeights *= 1.0f / dot( vWeights, float3(1,1,1) );
|
||||
|
||||
[branch]
|
||||
if (vWeights.x > 0)
|
||||
{
|
||||
vResultBase += vWeights.x * tex2D( base, coords.zy );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.x * tex2D( bump, coords.zy );
|
||||
}
|
||||
}
|
||||
|
||||
[branch]
|
||||
if (vWeights.y > 0)
|
||||
{
|
||||
vResultBase += vWeights.y * tex2D( base, coords.xz );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.y * tex2D( bump, coords.xz );
|
||||
}
|
||||
}
|
||||
|
||||
[branch]
|
||||
if (vWeights.z > 0)
|
||||
{
|
||||
vResultBase += vWeights.z * tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.z * tex2D( bump, coords.xy );
|
||||
}
|
||||
}
|
||||
|
||||
#else // not seamless
|
||||
|
||||
vResultBase = tex2D( base, coords.xy );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 = tex2D( base2, coords.xy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump = tex2D( bump, coords.xy );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
#else // PC
|
||||
|
||||
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
|
||||
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
|
||||
{
|
||||
vResultBase = 0;
|
||||
vResultBase2 = 0;
|
||||
vResultBump = 0;
|
||||
|
||||
if ( !bBump )
|
||||
{
|
||||
vResultBump = float4(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
#if SEAMLESS
|
||||
|
||||
vResultBase += vWeights.x * tex2D( base, coords.zy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.x * tex2D( bump, coords.zy );
|
||||
}
|
||||
|
||||
vResultBase += vWeights.y * tex2D( base, coords.xz );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.y * tex2D( bump, coords.xz );
|
||||
}
|
||||
|
||||
vResultBase += vWeights.z * tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.z * tex2D( bump, coords.xy );
|
||||
}
|
||||
|
||||
#else // not seamless
|
||||
|
||||
vResultBase = tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 = tex2D( base2, coords.xy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump = tex2D( bump, coords.xy );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
float3 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
|
||||
{
|
||||
# if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
|
||||
{
|
||||
float3 sample = tex2D( LightmapSampler, vTexCoord );
|
||||
|
||||
return sample;
|
||||
}
|
||||
# else
|
||||
{
|
||||
# if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
|
||||
{
|
||||
float4 sample = tex2D( LightmapSampler, vTexCoord );
|
||||
|
||||
return sample.rgb * sample.a;
|
||||
}
|
||||
# else
|
||||
{
|
||||
float4 Weights;
|
||||
float4 samples_0; //no arrays allowed in inline assembly
|
||||
float4 samples_1;
|
||||
float4 samples_2;
|
||||
float4 samples_3;
|
||||
|
||||
asm {
|
||||
tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
|
||||
getWeights2D Weights, vTexCoord.xy, LightmapSampler
|
||||
};
|
||||
|
||||
Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
|
||||
|
||||
float3 result;
|
||||
result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
|
||||
result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
|
||||
result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
|
||||
result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
|
||||
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
|
||||
{
|
||||
vResultBase = 0;
|
||||
vResultBase2 = 0;
|
||||
vResultBump = 0;
|
||||
|
||||
if ( !bBump )
|
||||
{
|
||||
vResultBump = float4(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
#if SEAMLESS
|
||||
|
||||
vWeights = max( vWeights - 0.3, 0 );
|
||||
|
||||
vWeights *= 1.0f / dot( vWeights, float3(1,1,1) );
|
||||
|
||||
[branch]
|
||||
if (vWeights.x > 0)
|
||||
{
|
||||
vResultBase += vWeights.x * tex2D( base, coords.zy );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.x * tex2D( bump, coords.zy );
|
||||
}
|
||||
}
|
||||
|
||||
[branch]
|
||||
if (vWeights.y > 0)
|
||||
{
|
||||
vResultBase += vWeights.y * tex2D( base, coords.xz );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.y * tex2D( bump, coords.xz );
|
||||
}
|
||||
}
|
||||
|
||||
[branch]
|
||||
if (vWeights.z > 0)
|
||||
{
|
||||
vResultBase += vWeights.z * tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.z * tex2D( bump, coords.xy );
|
||||
}
|
||||
}
|
||||
|
||||
#else // not seamless
|
||||
|
||||
vResultBase = tex2D( base, coords.xy );
|
||||
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 = tex2D( base2, coords.xy );
|
||||
}
|
||||
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump = tex2D( bump, coords.xy );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
#else // PC
|
||||
|
||||
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
|
||||
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
|
||||
{
|
||||
vResultBase = 0;
|
||||
vResultBase2 = 0;
|
||||
vResultBump = 0;
|
||||
|
||||
if ( !bBump )
|
||||
{
|
||||
vResultBump = float4(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
#if SEAMLESS
|
||||
|
||||
vResultBase += vWeights.x * tex2D( base, coords.zy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.x * tex2D( bump, coords.zy );
|
||||
}
|
||||
|
||||
vResultBase += vWeights.y * tex2D( base, coords.xz );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.y * tex2D( bump, coords.xz );
|
||||
}
|
||||
|
||||
vResultBase += vWeights.z * tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump += vWeights.z * tex2D( bump, coords.xy );
|
||||
}
|
||||
|
||||
#else // not seamless
|
||||
|
||||
vResultBase = tex2D( base, coords.xy );
|
||||
if ( bBase2 )
|
||||
{
|
||||
vResultBase2 = tex2D( base2, coords.xy );
|
||||
}
|
||||
if ( bBump )
|
||||
{
|
||||
vResultBump = tex2D( bump, coords.xy );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
float3 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
|
||||
{
|
||||
# if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
|
||||
{
|
||||
float3 sample = tex2D( LightmapSampler, vTexCoord );
|
||||
|
||||
return sample;
|
||||
}
|
||||
# else
|
||||
{
|
||||
# if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
|
||||
{
|
||||
float4 sample = tex2D( LightmapSampler, vTexCoord );
|
||||
|
||||
return sample.rgb * sample.a;
|
||||
}
|
||||
# else
|
||||
{
|
||||
float4 Weights;
|
||||
float4 samples_0; //no arrays allowed in inline assembly
|
||||
float4 samples_1;
|
||||
float4 samples_2;
|
||||
float4 samples_3;
|
||||
|
||||
asm {
|
||||
tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
|
||||
|
||||
getWeights2D Weights, vTexCoord.xy, LightmapSampler
|
||||
};
|
||||
|
||||
Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
|
||||
|
||||
float3 result;
|
||||
result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
|
||||
result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
|
||||
result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
|
||||
result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Common shader compiler pragmas
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_PRAGMAS_H_
|
||||
#define COMMON_PRAGMAS_H_
|
||||
|
||||
//
|
||||
// Validated shader models:
|
||||
//
|
||||
// SHADER_MODEL_VS_1_1
|
||||
// SHADER_MODEL_VS_2_0
|
||||
// SHADER_MODEL_VS_3_0
|
||||
//
|
||||
// SHADER_MODEL_PS_1_1
|
||||
// SHADER_MODEL_PS_1_4
|
||||
// SHADER_MODEL_PS_2_0
|
||||
// SHADER_MODEL_PS_2_B
|
||||
// SHADER_MODEL_PS_3_0
|
||||
//
|
||||
//
|
||||
//
|
||||
// Platforms:
|
||||
//
|
||||
// PC
|
||||
// _X360
|
||||
//
|
||||
|
||||
// Special pragmas silencing common warnings
|
||||
#pragma warning ( disable : 3557 ) // warning X3557: Loop only executes for N iteration(s), forcing loop to unroll
|
||||
#pragma warning ( disable : 3595 ) // warning X3595: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused
|
||||
#pragma warning ( disable : 3596 ) // warning X3596: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused
|
||||
#pragma warning ( disable : 4702 ) // warning X4702: complement opportunity missed because input result WAS clamped from 0 to 1
|
||||
|
||||
#endif //#ifndef COMMON_PRAGMAS_H_
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Common shader compiler pragmas
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#ifndef COMMON_PRAGMAS_H_
|
||||
#define COMMON_PRAGMAS_H_
|
||||
|
||||
//
|
||||
// Validated shader models:
|
||||
//
|
||||
// SHADER_MODEL_VS_1_1
|
||||
// SHADER_MODEL_VS_2_0
|
||||
// SHADER_MODEL_VS_3_0
|
||||
//
|
||||
// SHADER_MODEL_PS_1_1
|
||||
// SHADER_MODEL_PS_1_4
|
||||
// SHADER_MODEL_PS_2_0
|
||||
// SHADER_MODEL_PS_2_B
|
||||
// SHADER_MODEL_PS_3_0
|
||||
//
|
||||
//
|
||||
//
|
||||
// Platforms:
|
||||
//
|
||||
// PC
|
||||
// _X360
|
||||
//
|
||||
|
||||
// Special pragmas silencing common warnings
|
||||
#pragma warning ( disable : 3557 ) // warning X3557: Loop only executes for N iteration(s), forcing loop to unroll
|
||||
#pragma warning ( disable : 3595 ) // warning X3595: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused
|
||||
#pragma warning ( disable : 3596 ) // warning X3596: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused
|
||||
#pragma warning ( disable : 4702 ) // warning X4702: complement opportunity missed because input result WAS clamped from 0 to 1
|
||||
|
||||
#endif //#ifndef COMMON_PRAGMAS_H_
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,423 +1,423 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
#ifndef COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
#define COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
// We store four light colors and positions in an
|
||||
// array of three of these structures like so:
|
||||
//
|
||||
// x y z w
|
||||
// +------+------+------+------+
|
||||
// | L0.rgb | |
|
||||
// +------+------+------+ |
|
||||
// | L0.pos | L3 |
|
||||
// +------+------+------+ rgb |
|
||||
// | L1.rgb | |
|
||||
// +------+------+------+------+
|
||||
// | L1.pos | |
|
||||
// +------+------+------+ |
|
||||
// | L2.rgb | L3 |
|
||||
// +------+------+------+ pos |
|
||||
// | L2.pos | |
|
||||
// +------+------+------+------+
|
||||
//
|
||||
struct PixelShaderLightInfo
|
||||
{
|
||||
float4 color;
|
||||
float4 pos;
|
||||
};
|
||||
|
||||
#define cOverbright 2.0f
|
||||
#define cOOOverbright 0.5f
|
||||
|
||||
#define LIGHTTYPE_NONE 0
|
||||
#define LIGHTTYPE_SPOT 1
|
||||
#define LIGHTTYPE_POINT 2
|
||||
#define LIGHTTYPE_DIRECTIONAL 3
|
||||
|
||||
// Better suited to Pixel shader models, 11 instructions in pixel shader
|
||||
// ... actually, now only 9: mul, cmp, cmp, mul, mad, mad, mad, mad, mad
|
||||
float3 PixelShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
float3 linearColor, nSquared = worldNormal * worldNormal;
|
||||
float3 isNegative = ( worldNormal >= 0.0 ) ? 0 : nSquared;
|
||||
float3 isPositive = ( worldNormal >= 0.0 ) ? nSquared : 0;
|
||||
linearColor = isPositive.x * cAmbientCube[0] + isNegative.x * cAmbientCube[1] +
|
||||
isPositive.y * cAmbientCube[2] + isNegative.y * cAmbientCube[3] +
|
||||
isPositive.z * cAmbientCube[4] + isNegative.z * cAmbientCube[5];
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
// Better suited to Vertex shader models
|
||||
// Six VS instructions due to use of constant indexing (slt, mova, mul, mul, mad, mad)
|
||||
float3 VertexShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
float3 nSquared = worldNormal * worldNormal;
|
||||
int3 isNegative = ( worldNormal < 0.0 );
|
||||
float3 linearColor;
|
||||
linearColor = nSquared.x * cAmbientCube[isNegative.x] +
|
||||
nSquared.y * cAmbientCube[isNegative.y+2] +
|
||||
nSquared.z * cAmbientCube[isNegative.z+4];
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
float3 AmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
// Vertex shader cases
|
||||
#ifdef SHADER_MODEL_VS_1_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_1_1
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_2_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_3_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#else
|
||||
// Pixel shader case
|
||||
return PixelShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Compute scalar diffuse term with various optional tweaks such as
|
||||
// Half Lambert and ambient occlusion
|
||||
//-----------------------------------------------------------------------------
|
||||
float3 DiffuseTerm(const bool bHalfLambert, const float3 worldNormal, const float3 lightDir,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float fResult;
|
||||
|
||||
float NDotL = dot( worldNormal, lightDir ); // Unsaturated dot (-1 to 1 range)
|
||||
|
||||
if ( bHalfLambert )
|
||||
{
|
||||
fResult = saturate(NDotL * 0.5 + 0.5); // Scale and bias to 0 to 1 range
|
||||
|
||||
if ( !bDoLightingWarp )
|
||||
{
|
||||
fResult *= fResult; // Square
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fResult = saturate( NDotL ); // Saturate pure Lambertian term
|
||||
}
|
||||
|
||||
if ( bDoAmbientOcclusion )
|
||||
{
|
||||
// Raise to higher powers for darker AO values
|
||||
// float fAOPower = lerp( 4.0f, 1.0f, fAmbientOcclusion );
|
||||
// result *= pow( NDotL * 0.5 + 0.5, fAOPower );
|
||||
fResult *= fAmbientOcclusion;
|
||||
}
|
||||
|
||||
float3 fOut = float3( fResult, fResult, fResult );
|
||||
if ( bDoLightingWarp )
|
||||
{
|
||||
fOut = 2.0f * tex1D( lightWarpSampler, fResult );
|
||||
}
|
||||
|
||||
return fOut;
|
||||
}
|
||||
|
||||
float3 PixelShaderDoGeneralDiffuseLight( const float fAtten, const float3 worldPos, const float3 worldNormal,
|
||||
in sampler NormalizeSampler,
|
||||
const float3 vPosition, const float3 vColor, const bool bHalfLambert,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
#if (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))
|
||||
float3 lightDir = normalize( vPosition - worldPos );
|
||||
#else
|
||||
float3 lightDir = NormalizeWithCubemap( NormalizeSampler, vPosition - worldPos );
|
||||
#endif
|
||||
return vColor * fAtten * DiffuseTerm( bHalfLambert, worldNormal, lightDir, bDoAmbientOcclusion, fAmbientOcclusion, bDoLightingWarp, lightWarpSampler );
|
||||
}
|
||||
|
||||
float3 PixelShaderGetLightVector( const float3 worldPos, PixelShaderLightInfo cLightInfo[3], int nLightIndex )
|
||||
{
|
||||
if ( nLightIndex == 3 )
|
||||
{
|
||||
// Unpack light 3 from w components...
|
||||
float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w );
|
||||
return normalize( vLight3Pos - worldPos );
|
||||
}
|
||||
else
|
||||
{
|
||||
return normalize( cLightInfo[nLightIndex].pos - worldPos );
|
||||
}
|
||||
}
|
||||
|
||||
float3 PixelShaderGetLightColor( PixelShaderLightInfo cLightInfo[3], int nLightIndex )
|
||||
{
|
||||
if ( nLightIndex == 3 )
|
||||
{
|
||||
// Unpack light 3 from w components...
|
||||
return float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w );
|
||||
}
|
||||
else
|
||||
{
|
||||
return cLightInfo[nLightIndex].color.rgb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SpecularAndRimTerms( const float3 vWorldNormal, const float3 vLightDir, const float fSpecularExponent,
|
||||
const float3 vEyeDir, const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, const float fFresnel,
|
||||
const float3 color, const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
rimLighting = float3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
//float3 vReflect = reflect( -vEyeDir, vWorldNormal ); // Reflect view through normal
|
||||
float3 vReflect = 2 * vWorldNormal * dot( vWorldNormal , vEyeDir ) - vEyeDir; // Reflect view through normal
|
||||
float LdotR = saturate(dot( vReflect, vLightDir )); // L.R (use half-angle instead?)
|
||||
specularLighting = pow( LdotR, fSpecularExponent ); // Raise to specular exponent
|
||||
|
||||
// Optionally warp as function of scalar specular and fresnel
|
||||
if ( bDoSpecularWarp )
|
||||
specularLighting *= tex2D( specularWarpSampler, float2(specularLighting.x, fFresnel) ); // Sample at { (L.R)^k, fresnel }
|
||||
|
||||
specularLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L
|
||||
specularLighting *= color; // Modulate with light color
|
||||
|
||||
if ( bDoAmbientOcclusion ) // Optionally modulate with ambient occlusion
|
||||
specularLighting *= fAmbientOcclusion;
|
||||
|
||||
if ( bDoRimLighting ) // Optionally do rim lighting
|
||||
{
|
||||
rimLighting = pow( LdotR, fRimExponent ); // Raise to rim exponent
|
||||
rimLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L
|
||||
rimLighting *= color; // Modulate with light color
|
||||
}
|
||||
}
|
||||
|
||||
// Traditional fresnel term approximation
|
||||
float Fresnel( const float3 vNormal, const float3 vEyeDir )
|
||||
{
|
||||
float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term
|
||||
return fresnel * fresnel; // Square for a more subtle look
|
||||
}
|
||||
|
||||
// Traditional fresnel term approximation which uses 4th power (square twice)
|
||||
float Fresnel4( const float3 vNormal, const float3 vEyeDir )
|
||||
{
|
||||
float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term
|
||||
fresnel = fresnel * fresnel; // Square
|
||||
return fresnel * fresnel; // Square again for a more subtle look
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Custom Fresnel with low, mid and high parameters defining a piecewise continuous function
|
||||
// with traditional fresnel (0 to 1 range) as input. The 0 to 0.5 range blends between
|
||||
// low and mid while the 0.5 to 1 range blends between mid and high
|
||||
//
|
||||
// |
|
||||
// | . M . . . H
|
||||
// | .
|
||||
// L
|
||||
// |
|
||||
// +----------------
|
||||
// 0 1
|
||||
//
|
||||
float Fresnel( const float3 vNormal, const float3 vEyeDir, float3 vRanges )
|
||||
{
|
||||
//float result, f = Fresnel( vNormal, vEyeDir ); // Traditional Fresnel
|
||||
//if ( f > 0.5f )
|
||||
// result = lerp( vRanges.y, vRanges.z, (2*f)-1 ); // Blend between mid and high values
|
||||
//else
|
||||
// result = lerp( vRanges.x, vRanges.y, 2*f ); // Blend between low and mid values
|
||||
|
||||
// note: vRanges is now encoded as ((mid-min)*2, mid, (max-mid)*2) to optimize math
|
||||
float f = saturate( 1 - dot( vNormal, vEyeDir ) );
|
||||
f = f*f - 0.5;
|
||||
return vRanges.y + (f >= 0.0 ? vRanges.z : vRanges.x) * f;
|
||||
}
|
||||
|
||||
void PixelShaderDoSpecularLight( const float3 vWorldPos, const float3 vWorldNormal, const float fSpecularExponent, const float3 vEyeDir,
|
||||
const float fAtten, const float3 vLightColor, const float3 vLightDir,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel,
|
||||
const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
// Compute Specular and rim terms
|
||||
SpecularAndRimTerms( vWorldNormal, vLightDir, fSpecularExponent,
|
||||
vEyeDir, bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel, vLightColor * fAtten,
|
||||
bDoRimLighting, fRimExponent, specularLighting, rimLighting );
|
||||
}
|
||||
|
||||
float3 PixelShaderDoLightingLinear( const float3 worldPos, const float3 worldNormal,
|
||||
const float3 staticLightingColor, const bool bStaticLight,
|
||||
const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6],
|
||||
in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bHalfLambert, const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float3 linearColor = 0.0f;
|
||||
|
||||
if ( bStaticLight )
|
||||
{
|
||||
// The static lighting comes in in gamma space and has also been premultiplied by $cOOOverbright
|
||||
// need to get it into
|
||||
// linear space so that we can do adds.
|
||||
linearColor += GammaToLinear( staticLightingColor * cOverbright );
|
||||
}
|
||||
|
||||
if ( bAmbientLight )
|
||||
{
|
||||
float3 ambient = AmbientLight( worldNormal, cAmbientCube );
|
||||
|
||||
if ( bDoAmbientOcclusion )
|
||||
ambient *= fAmbientOcclusion * fAmbientOcclusion; // Note squaring...
|
||||
|
||||
linearColor += ambient;
|
||||
}
|
||||
|
||||
if ( nNumLights > 0 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.x, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[0].pos, cLightInfo[0].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 1 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.y, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[1].pos, cLightInfo[1].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 2 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.z, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[2].pos, cLightInfo[2].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 3 )
|
||||
{
|
||||
// Unpack the 4th light's data from tight constant packing
|
||||
float3 vLight3Color = float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w );
|
||||
float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w );
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.w, worldPos, worldNormal, NormalizeSampler,
|
||||
vLight3Pos, vLight3Color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
void PixelShaderDoSpecularLighting( const float3 worldPos, const float3 worldNormal, const float fSpecularExponent, const float3 vEyeDir,
|
||||
const float4 lightAtten, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel,
|
||||
const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
specularLighting = rimLighting = float3( 0.0f, 0.0f, 0.0f );
|
||||
float3 localSpecularTerm, localRimTerm;
|
||||
|
||||
if( nNumLights > 0 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.x, PixelShaderGetLightColor( cLightInfo, 0 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 0 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
if( nNumLights > 1 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.y, PixelShaderGetLightColor( cLightInfo, 1 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 1 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
|
||||
if( nNumLights > 2 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.z, PixelShaderGetLightColor( cLightInfo, 2 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 2 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
if( nNumLights > 3 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.w, PixelShaderGetLightColor( cLightInfo, 3 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 3 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float3 PixelShaderDoRimLighting( const float3 worldNormal, const float3 vEyeDir, const float3 cAmbientCube[6], float fFresnel )
|
||||
{
|
||||
float3 vReflect = reflect( -vEyeDir, worldNormal ); // Reflect view through normal
|
||||
|
||||
return fFresnel * PixelShaderAmbientLight( vEyeDir, cAmbientCube );
|
||||
}
|
||||
|
||||
// Called directly by newer shaders or through the following wrapper for older shaders
|
||||
float3 PixelShaderDoLighting( const float3 worldPos, const float3 worldNormal,
|
||||
const float3 staticLightingColor, const bool bStaticLight,
|
||||
const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6],
|
||||
in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bHalfLambert,
|
||||
|
||||
// New optional/experimental parameters
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float3 linearColor = PixelShaderDoLightingLinear( worldPos, worldNormal, staticLightingColor,
|
||||
bStaticLight, bAmbientLight, lightAtten,
|
||||
cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
|
||||
// go ahead and clamp to the linear space equivalent of overbright 2 so that we match
|
||||
// everything else.
|
||||
// linearColor = HuePreservingColorClamp( linearColor, pow( 2.0f, 2.2 ) );
|
||||
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
#ifndef COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
#define COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
// We store four light colors and positions in an
|
||||
// array of three of these structures like so:
|
||||
//
|
||||
// x y z w
|
||||
// +------+------+------+------+
|
||||
// | L0.rgb | |
|
||||
// +------+------+------+ |
|
||||
// | L0.pos | L3 |
|
||||
// +------+------+------+ rgb |
|
||||
// | L1.rgb | |
|
||||
// +------+------+------+------+
|
||||
// | L1.pos | |
|
||||
// +------+------+------+ |
|
||||
// | L2.rgb | L3 |
|
||||
// +------+------+------+ pos |
|
||||
// | L2.pos | |
|
||||
// +------+------+------+------+
|
||||
//
|
||||
struct PixelShaderLightInfo
|
||||
{
|
||||
float4 color;
|
||||
float4 pos;
|
||||
};
|
||||
|
||||
#define cOverbright 2.0f
|
||||
#define cOOOverbright 0.5f
|
||||
|
||||
#define LIGHTTYPE_NONE 0
|
||||
#define LIGHTTYPE_SPOT 1
|
||||
#define LIGHTTYPE_POINT 2
|
||||
#define LIGHTTYPE_DIRECTIONAL 3
|
||||
|
||||
// Better suited to Pixel shader models, 11 instructions in pixel shader
|
||||
// ... actually, now only 9: mul, cmp, cmp, mul, mad, mad, mad, mad, mad
|
||||
float3 PixelShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
float3 linearColor, nSquared = worldNormal * worldNormal;
|
||||
float3 isNegative = ( worldNormal >= 0.0 ) ? 0 : nSquared;
|
||||
float3 isPositive = ( worldNormal >= 0.0 ) ? nSquared : 0;
|
||||
linearColor = isPositive.x * cAmbientCube[0] + isNegative.x * cAmbientCube[1] +
|
||||
isPositive.y * cAmbientCube[2] + isNegative.y * cAmbientCube[3] +
|
||||
isPositive.z * cAmbientCube[4] + isNegative.z * cAmbientCube[5];
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
// Better suited to Vertex shader models
|
||||
// Six VS instructions due to use of constant indexing (slt, mova, mul, mul, mad, mad)
|
||||
float3 VertexShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
float3 nSquared = worldNormal * worldNormal;
|
||||
int3 isNegative = ( worldNormal < 0.0 );
|
||||
float3 linearColor;
|
||||
linearColor = nSquared.x * cAmbientCube[isNegative.x] +
|
||||
nSquared.y * cAmbientCube[isNegative.y+2] +
|
||||
nSquared.z * cAmbientCube[isNegative.z+4];
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
float3 AmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] )
|
||||
{
|
||||
// Vertex shader cases
|
||||
#ifdef SHADER_MODEL_VS_1_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_1_1
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_2_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#elif SHADER_MODEL_VS_3_0
|
||||
return VertexShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#else
|
||||
// Pixel shader case
|
||||
return PixelShaderAmbientLight( worldNormal, cAmbientCube );
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Compute scalar diffuse term with various optional tweaks such as
|
||||
// Half Lambert and ambient occlusion
|
||||
//-----------------------------------------------------------------------------
|
||||
float3 DiffuseTerm(const bool bHalfLambert, const float3 worldNormal, const float3 lightDir,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float fResult;
|
||||
|
||||
float NDotL = dot( worldNormal, lightDir ); // Unsaturated dot (-1 to 1 range)
|
||||
|
||||
if ( bHalfLambert )
|
||||
{
|
||||
fResult = saturate(NDotL * 0.5 + 0.5); // Scale and bias to 0 to 1 range
|
||||
|
||||
if ( !bDoLightingWarp )
|
||||
{
|
||||
fResult *= fResult; // Square
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fResult = saturate( NDotL ); // Saturate pure Lambertian term
|
||||
}
|
||||
|
||||
if ( bDoAmbientOcclusion )
|
||||
{
|
||||
// Raise to higher powers for darker AO values
|
||||
// float fAOPower = lerp( 4.0f, 1.0f, fAmbientOcclusion );
|
||||
// result *= pow( NDotL * 0.5 + 0.5, fAOPower );
|
||||
fResult *= fAmbientOcclusion;
|
||||
}
|
||||
|
||||
float3 fOut = float3( fResult, fResult, fResult );
|
||||
if ( bDoLightingWarp )
|
||||
{
|
||||
fOut = 2.0f * tex1D( lightWarpSampler, fResult );
|
||||
}
|
||||
|
||||
return fOut;
|
||||
}
|
||||
|
||||
float3 PixelShaderDoGeneralDiffuseLight( const float fAtten, const float3 worldPos, const float3 worldNormal,
|
||||
in sampler NormalizeSampler,
|
||||
const float3 vPosition, const float3 vColor, const bool bHalfLambert,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
#if (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))
|
||||
float3 lightDir = normalize( vPosition - worldPos );
|
||||
#else
|
||||
float3 lightDir = NormalizeWithCubemap( NormalizeSampler, vPosition - worldPos );
|
||||
#endif
|
||||
return vColor * fAtten * DiffuseTerm( bHalfLambert, worldNormal, lightDir, bDoAmbientOcclusion, fAmbientOcclusion, bDoLightingWarp, lightWarpSampler );
|
||||
}
|
||||
|
||||
float3 PixelShaderGetLightVector( const float3 worldPos, PixelShaderLightInfo cLightInfo[3], int nLightIndex )
|
||||
{
|
||||
if ( nLightIndex == 3 )
|
||||
{
|
||||
// Unpack light 3 from w components...
|
||||
float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w );
|
||||
return normalize( vLight3Pos - worldPos );
|
||||
}
|
||||
else
|
||||
{
|
||||
return normalize( cLightInfo[nLightIndex].pos - worldPos );
|
||||
}
|
||||
}
|
||||
|
||||
float3 PixelShaderGetLightColor( PixelShaderLightInfo cLightInfo[3], int nLightIndex )
|
||||
{
|
||||
if ( nLightIndex == 3 )
|
||||
{
|
||||
// Unpack light 3 from w components...
|
||||
return float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w );
|
||||
}
|
||||
else
|
||||
{
|
||||
return cLightInfo[nLightIndex].color.rgb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SpecularAndRimTerms( const float3 vWorldNormal, const float3 vLightDir, const float fSpecularExponent,
|
||||
const float3 vEyeDir, const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, const float fFresnel,
|
||||
const float3 color, const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
rimLighting = float3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
//float3 vReflect = reflect( -vEyeDir, vWorldNormal ); // Reflect view through normal
|
||||
float3 vReflect = 2 * vWorldNormal * dot( vWorldNormal , vEyeDir ) - vEyeDir; // Reflect view through normal
|
||||
float LdotR = saturate(dot( vReflect, vLightDir )); // L.R (use half-angle instead?)
|
||||
specularLighting = pow( LdotR, fSpecularExponent ); // Raise to specular exponent
|
||||
|
||||
// Optionally warp as function of scalar specular and fresnel
|
||||
if ( bDoSpecularWarp )
|
||||
specularLighting *= tex2D( specularWarpSampler, float2(specularLighting.x, fFresnel) ); // Sample at { (L.R)^k, fresnel }
|
||||
|
||||
specularLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L
|
||||
specularLighting *= color; // Modulate with light color
|
||||
|
||||
if ( bDoAmbientOcclusion ) // Optionally modulate with ambient occlusion
|
||||
specularLighting *= fAmbientOcclusion;
|
||||
|
||||
if ( bDoRimLighting ) // Optionally do rim lighting
|
||||
{
|
||||
rimLighting = pow( LdotR, fRimExponent ); // Raise to rim exponent
|
||||
rimLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L
|
||||
rimLighting *= color; // Modulate with light color
|
||||
}
|
||||
}
|
||||
|
||||
// Traditional fresnel term approximation
|
||||
float Fresnel( const float3 vNormal, const float3 vEyeDir )
|
||||
{
|
||||
float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term
|
||||
return fresnel * fresnel; // Square for a more subtle look
|
||||
}
|
||||
|
||||
// Traditional fresnel term approximation which uses 4th power (square twice)
|
||||
float Fresnel4( const float3 vNormal, const float3 vEyeDir )
|
||||
{
|
||||
float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term
|
||||
fresnel = fresnel * fresnel; // Square
|
||||
return fresnel * fresnel; // Square again for a more subtle look
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Custom Fresnel with low, mid and high parameters defining a piecewise continuous function
|
||||
// with traditional fresnel (0 to 1 range) as input. The 0 to 0.5 range blends between
|
||||
// low and mid while the 0.5 to 1 range blends between mid and high
|
||||
//
|
||||
// |
|
||||
// | . M . . . H
|
||||
// | .
|
||||
// L
|
||||
// |
|
||||
// +----------------
|
||||
// 0 1
|
||||
//
|
||||
float Fresnel( const float3 vNormal, const float3 vEyeDir, float3 vRanges )
|
||||
{
|
||||
//float result, f = Fresnel( vNormal, vEyeDir ); // Traditional Fresnel
|
||||
//if ( f > 0.5f )
|
||||
// result = lerp( vRanges.y, vRanges.z, (2*f)-1 ); // Blend between mid and high values
|
||||
//else
|
||||
// result = lerp( vRanges.x, vRanges.y, 2*f ); // Blend between low and mid values
|
||||
|
||||
// note: vRanges is now encoded as ((mid-min)*2, mid, (max-mid)*2) to optimize math
|
||||
float f = saturate( 1 - dot( vNormal, vEyeDir ) );
|
||||
f = f*f - 0.5;
|
||||
return vRanges.y + (f >= 0.0 ? vRanges.z : vRanges.x) * f;
|
||||
}
|
||||
|
||||
void PixelShaderDoSpecularLight( const float3 vWorldPos, const float3 vWorldNormal, const float fSpecularExponent, const float3 vEyeDir,
|
||||
const float fAtten, const float3 vLightColor, const float3 vLightDir,
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel,
|
||||
const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
// Compute Specular and rim terms
|
||||
SpecularAndRimTerms( vWorldNormal, vLightDir, fSpecularExponent,
|
||||
vEyeDir, bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel, vLightColor * fAtten,
|
||||
bDoRimLighting, fRimExponent, specularLighting, rimLighting );
|
||||
}
|
||||
|
||||
float3 PixelShaderDoLightingLinear( const float3 worldPos, const float3 worldNormal,
|
||||
const float3 staticLightingColor, const bool bStaticLight,
|
||||
const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6],
|
||||
in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bHalfLambert, const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float3 linearColor = 0.0f;
|
||||
|
||||
if ( bStaticLight )
|
||||
{
|
||||
// The static lighting comes in in gamma space and has also been premultiplied by $cOOOverbright
|
||||
// need to get it into
|
||||
// linear space so that we can do adds.
|
||||
linearColor += GammaToLinear( staticLightingColor * cOverbright );
|
||||
}
|
||||
|
||||
if ( bAmbientLight )
|
||||
{
|
||||
float3 ambient = AmbientLight( worldNormal, cAmbientCube );
|
||||
|
||||
if ( bDoAmbientOcclusion )
|
||||
ambient *= fAmbientOcclusion * fAmbientOcclusion; // Note squaring...
|
||||
|
||||
linearColor += ambient;
|
||||
}
|
||||
|
||||
if ( nNumLights > 0 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.x, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[0].pos, cLightInfo[0].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 1 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.y, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[1].pos, cLightInfo[1].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 2 )
|
||||
{
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.z, worldPos, worldNormal, NormalizeSampler,
|
||||
cLightInfo[2].pos, cLightInfo[2].color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
if ( nNumLights > 3 )
|
||||
{
|
||||
// Unpack the 4th light's data from tight constant packing
|
||||
float3 vLight3Color = float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w );
|
||||
float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w );
|
||||
linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.w, worldPos, worldNormal, NormalizeSampler,
|
||||
vLight3Pos, vLight3Color, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
void PixelShaderDoSpecularLighting( const float3 worldPos, const float3 worldNormal, const float fSpecularExponent, const float3 vEyeDir,
|
||||
const float4 lightAtten, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel,
|
||||
const bool bDoRimLighting, const float fRimExponent,
|
||||
|
||||
// Outputs
|
||||
out float3 specularLighting, out float3 rimLighting )
|
||||
{
|
||||
specularLighting = rimLighting = float3( 0.0f, 0.0f, 0.0f );
|
||||
float3 localSpecularTerm, localRimTerm;
|
||||
|
||||
if( nNumLights > 0 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.x, PixelShaderGetLightColor( cLightInfo, 0 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 0 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
if( nNumLights > 1 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.y, PixelShaderGetLightColor( cLightInfo, 1 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 1 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
|
||||
if( nNumLights > 2 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.z, PixelShaderGetLightColor( cLightInfo, 2 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 2 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
if( nNumLights > 3 )
|
||||
{
|
||||
PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir,
|
||||
lightAtten.w, PixelShaderGetLightColor( cLightInfo, 3 ),
|
||||
PixelShaderGetLightVector( worldPos, cLightInfo, 3 ),
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoSpecularWarp, specularWarpSampler, fFresnel,
|
||||
bDoRimLighting, fRimExponent,
|
||||
localSpecularTerm, localRimTerm );
|
||||
|
||||
specularLighting += localSpecularTerm; // Accumulate specular and rim terms
|
||||
rimLighting += localRimTerm;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float3 PixelShaderDoRimLighting( const float3 worldNormal, const float3 vEyeDir, const float3 cAmbientCube[6], float fFresnel )
|
||||
{
|
||||
float3 vReflect = reflect( -vEyeDir, worldNormal ); // Reflect view through normal
|
||||
|
||||
return fFresnel * PixelShaderAmbientLight( vEyeDir, cAmbientCube );
|
||||
}
|
||||
|
||||
// Called directly by newer shaders or through the following wrapper for older shaders
|
||||
float3 PixelShaderDoLighting( const float3 worldPos, const float3 worldNormal,
|
||||
const float3 staticLightingColor, const bool bStaticLight,
|
||||
const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6],
|
||||
in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3],
|
||||
const bool bHalfLambert,
|
||||
|
||||
// New optional/experimental parameters
|
||||
const bool bDoAmbientOcclusion, const float fAmbientOcclusion,
|
||||
const bool bDoLightingWarp, in sampler lightWarpSampler )
|
||||
{
|
||||
float3 linearColor = PixelShaderDoLightingLinear( worldPos, worldNormal, staticLightingColor,
|
||||
bStaticLight, bAmbientLight, lightAtten,
|
||||
cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert,
|
||||
bDoAmbientOcclusion, fAmbientOcclusion,
|
||||
bDoLightingWarp, lightWarpSampler );
|
||||
|
||||
// go ahead and clamp to the linear space equivalent of overbright 2 so that we match
|
||||
// everything else.
|
||||
// linearColor = HuePreservingColorClamp( linearColor, pow( 2.0f, 2.2 ) );
|
||||
|
||||
return linearColor;
|
||||
}
|
||||
|
||||
#endif //#ifndef COMMON_VERTEXLITGENERIC_DX9_H_
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,45 +1,45 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Provide convenient mapping for shader constants
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#define C_CODE_HACK
|
||||
#include "shader_constant_register_map.h"
|
||||
#undef C_CODE_HACK
|
||||
|
||||
// For the C code, map the above file's defines back to integers...
|
||||
#define PSREG_CONSTANT_00 0
|
||||
#define PSREG_CONSTANT_01 1
|
||||
#define PSREG_CONSTANT_02 2
|
||||
#define PSREG_CONSTANT_03 3
|
||||
#define PSREG_CONSTANT_04 4
|
||||
#define PSREG_CONSTANT_05 5
|
||||
#define PSREG_CONSTANT_06 6
|
||||
#define PSREG_CONSTANT_07 7
|
||||
#define PSREG_CONSTANT_08 8
|
||||
#define PSREG_CONSTANT_09 9
|
||||
#define PSREG_CONSTANT_10 10
|
||||
#define PSREG_CONSTANT_11 11
|
||||
#define PSREG_CONSTANT_12 12
|
||||
#define PSREG_CONSTANT_13 13
|
||||
#define PSREG_CONSTANT_14 14
|
||||
#define PSREG_CONSTANT_15 15
|
||||
#define PSREG_CONSTANT_16 16
|
||||
#define PSREG_CONSTANT_17 17
|
||||
#define PSREG_CONSTANT_18 18
|
||||
#define PSREG_CONSTANT_19 19
|
||||
#define PSREG_CONSTANT_20 20
|
||||
#define PSREG_CONSTANT_21 21
|
||||
#define PSREG_CONSTANT_22 22
|
||||
#define PSREG_CONSTANT_23 23
|
||||
#define PSREG_CONSTANT_24 24
|
||||
#define PSREG_CONSTANT_25 25
|
||||
#define PSREG_CONSTANT_26 26
|
||||
#define PSREG_CONSTANT_27 27
|
||||
#define PSREG_CONSTANT_28 28
|
||||
#define PSREG_CONSTANT_29 29
|
||||
#define PSREG_CONSTANT_30 30
|
||||
#define PSREG_CONSTANT_31 31
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Provide convenient mapping for shader constants
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#define C_CODE_HACK
|
||||
#include "shader_constant_register_map.h"
|
||||
#undef C_CODE_HACK
|
||||
|
||||
// For the C code, map the above file's defines back to integers...
|
||||
#define PSREG_CONSTANT_00 0
|
||||
#define PSREG_CONSTANT_01 1
|
||||
#define PSREG_CONSTANT_02 2
|
||||
#define PSREG_CONSTANT_03 3
|
||||
#define PSREG_CONSTANT_04 4
|
||||
#define PSREG_CONSTANT_05 5
|
||||
#define PSREG_CONSTANT_06 6
|
||||
#define PSREG_CONSTANT_07 7
|
||||
#define PSREG_CONSTANT_08 8
|
||||
#define PSREG_CONSTANT_09 9
|
||||
#define PSREG_CONSTANT_10 10
|
||||
#define PSREG_CONSTANT_11 11
|
||||
#define PSREG_CONSTANT_12 12
|
||||
#define PSREG_CONSTANT_13 13
|
||||
#define PSREG_CONSTANT_14 14
|
||||
#define PSREG_CONSTANT_15 15
|
||||
#define PSREG_CONSTANT_16 16
|
||||
#define PSREG_CONSTANT_17 17
|
||||
#define PSREG_CONSTANT_18 18
|
||||
#define PSREG_CONSTANT_19 19
|
||||
#define PSREG_CONSTANT_20 20
|
||||
#define PSREG_CONSTANT_21 21
|
||||
#define PSREG_CONSTANT_22 22
|
||||
#define PSREG_CONSTANT_23 23
|
||||
#define PSREG_CONSTANT_24 24
|
||||
#define PSREG_CONSTANT_25 25
|
||||
#define PSREG_CONSTANT_26 26
|
||||
#define PSREG_CONSTANT_27 27
|
||||
#define PSREG_CONSTANT_28 28
|
||||
#define PSREG_CONSTANT_29 29
|
||||
#define PSREG_CONSTANT_30 30
|
||||
#define PSREG_CONSTANT_31 31
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
// This one isn't supported on dx8
|
||||
DEFINE_FALLBACK_SHADER( SDK_DepthWrite, Wireframe )
|
||||
|
||||
DEFINE_FALLBACK_SHADER( SDK_EyeRefract, Eyes_dx8 )
|
||||
DEFINE_FALLBACK_SHADER( SDK_VolumeClouds, UnlitGeneric_DX8 )
|
||||
|
||||
// FIXME: These aren't supported on dx8, but need to be.
|
||||
DEFINE_FALLBACK_SHADER( SDK_EyeGlint, EyeGlint )
|
||||
DEFINE_FALLBACK_SHADER( SDK_AfterShock, AfterShock )
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
// This one isn't supported on dx8
|
||||
DEFINE_FALLBACK_SHADER( SDK_DepthWrite, Wireframe )
|
||||
|
||||
DEFINE_FALLBACK_SHADER( SDK_EyeRefract, Eyes_dx8 )
|
||||
DEFINE_FALLBACK_SHADER( SDK_VolumeClouds, UnlitGeneric_DX8 )
|
||||
|
||||
// FIXME: These aren't supported on dx8, but need to be.
|
||||
DEFINE_FALLBACK_SHADER( SDK_EyeGlint, EyeGlint )
|
||||
DEFINE_FALLBACK_SHADER( SDK_AfterShock, AfterShock )
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
|
||||
//
|
||||
// Example shader that can be applied to models
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "convar.h"
|
||||
#include "example_model_dx9_helper.h"
|
||||
|
||||
#ifdef GAME_SHADER_DLL
|
||||
DEFINE_FALLBACK_SHADER( Mod_Example_Model, Mod_Example_Model_DX9 )
|
||||
BEGIN_VS_SHADER( Mod_Example_Model_DX9, "Help for Example Model Shader" )
|
||||
#else
|
||||
DEFINE_FALLBACK_SHADER( Example_Model, Example_Model_DX9 )
|
||||
BEGIN_VS_SHADER( Example_Model_DX9, "Help for Example Model Shader" )
|
||||
#endif
|
||||
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
void SetupVars( ExampleModel_DX9_Vars_t& info )
|
||||
{
|
||||
info.m_nBaseTexture = BASETEXTURE;
|
||||
info.m_nBaseTextureFrame = FRAME;
|
||||
info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
|
||||
info.m_nAlphaTestReference = ALPHATESTREFERENCE;
|
||||
info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
|
||||
info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
|
||||
}
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
InitParamsExampleModel_DX9( this, params, pMaterialName, info );
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
InitExampleModel_DX9( this, params, info );
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
DrawExampleModel_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression, pContextDataPtr );
|
||||
}
|
||||
|
||||
END_SHADER
|
||||
|
||||
//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
|
||||
//
|
||||
// Example shader that can be applied to models
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "convar.h"
|
||||
#include "example_model_dx9_helper.h"
|
||||
|
||||
#ifdef GAME_SHADER_DLL
|
||||
DEFINE_FALLBACK_SHADER( Mod_Example_Model, Mod_Example_Model_DX9 )
|
||||
BEGIN_VS_SHADER( Mod_Example_Model_DX9, "Help for Example Model Shader" )
|
||||
#else
|
||||
DEFINE_FALLBACK_SHADER( Example_Model, Example_Model_DX9 )
|
||||
BEGIN_VS_SHADER( Example_Model_DX9, "Help for Example Model Shader" )
|
||||
#endif
|
||||
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
void SetupVars( ExampleModel_DX9_Vars_t& info )
|
||||
{
|
||||
info.m_nBaseTexture = BASETEXTURE;
|
||||
info.m_nBaseTextureFrame = FRAME;
|
||||
info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
|
||||
info.m_nAlphaTestReference = ALPHATESTREFERENCE;
|
||||
info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
|
||||
info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
|
||||
}
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
InitParamsExampleModel_DX9( this, params, pMaterialName, info );
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
InitExampleModel_DX9( this, params, info );
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
ExampleModel_DX9_Vars_t info;
|
||||
SetupVars( info );
|
||||
DrawExampleModel_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression, pContextDataPtr );
|
||||
}
|
||||
|
||||
END_SHADER
|
||||
|
||||
|
||||
@@ -1,341 +1,341 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
#include "BaseVSShader.h"
|
||||
#include "example_model_dx9_helper.h"
|
||||
#include "convar.h"
|
||||
#include "cpp_shader_constant_register_map.h"
|
||||
#include "example_model_vs20.inc"
|
||||
#include "example_model_ps20b.inc"
|
||||
#include "commandbuilder.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT );
|
||||
static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT );
|
||||
static ConVar r_rimlight( "r_rimlight", "1", FCVAR_CHEAT );
|
||||
|
||||
// Textures may be bound to the following samplers:
|
||||
// SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha
|
||||
// SHADER_SAMPLER4 Flashlight Shadow Depth Map
|
||||
// SHADER_SAMPLER5 Normalization cube map
|
||||
// SHADER_SAMPLER6 Flashlight Cookie
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialize shader parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ExampleModel_DX9_Vars_t &info )
|
||||
{
|
||||
// FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
|
||||
Assert( info.m_nFlashlightTexture >= 0 );
|
||||
|
||||
if ( g_pHardwareConfig->SupportsBorderColor() )
|
||||
{
|
||||
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
|
||||
}
|
||||
else
|
||||
{
|
||||
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
|
||||
}
|
||||
|
||||
// This shader can be used with hw skinning
|
||||
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
|
||||
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialize shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, ExampleModel_DX9_Vars_t &info )
|
||||
{
|
||||
Assert( info.m_nFlashlightTexture >= 0 );
|
||||
pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
|
||||
|
||||
bool bIsBaseTextureTranslucent = false;
|
||||
if ( params[info.m_nBaseTexture]->IsDefined() )
|
||||
{
|
||||
pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
|
||||
|
||||
if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
|
||||
{
|
||||
bIsBaseTextureTranslucent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CExampleModel_DX9_Context : public CBasePerMaterialContextData
|
||||
{
|
||||
public:
|
||||
CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut;
|
||||
bool m_bFastPath;
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void DrawExampleModel_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
bool bHasFlashlight, ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression,
|
||||
CBasePerMaterialContextData **pContextDataPtr )
|
||||
{
|
||||
bool bHasBaseTexture = (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsTexture();
|
||||
bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
|
||||
|
||||
BlendType_t nBlendType= pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true );
|
||||
bool bFullyOpaque = ( nBlendType != BT_BLENDADD ) && ( nBlendType != BT_BLEND ) && !bIsAlphaTested && !bHasFlashlight;
|
||||
|
||||
CExampleModel_DX9_Context *pContextData = reinterpret_cast< CExampleModel_DX9_Context *> ( *pContextDataPtr );
|
||||
if ( !pContextData )
|
||||
{
|
||||
pContextData = new CExampleModel_DX9_Context;
|
||||
*pContextDataPtr = pContextData;
|
||||
}
|
||||
|
||||
if( pShader->IsSnapshotting() )
|
||||
{
|
||||
pShaderShadow->EnableAlphaTest( bIsAlphaTested );
|
||||
|
||||
if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f )
|
||||
{
|
||||
pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() );
|
||||
}
|
||||
|
||||
int nShadowFilterMode = 0;
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
if (params[info.m_nBaseTexture]->IsTexture())
|
||||
{
|
||||
pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
|
||||
}
|
||||
|
||||
if( bIsAlphaTested )
|
||||
{
|
||||
// disable alpha test and use the zfunc zequals since alpha isn't guaranteed to
|
||||
// be the same on both the regular pass and the flashlight pass.
|
||||
pShaderShadow->EnableAlphaTest( false );
|
||||
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL );
|
||||
}
|
||||
pShaderShadow->EnableBlending( true );
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
// Be sure not to write to dest alpha
|
||||
pShaderShadow->EnableAlphaWrites( false );
|
||||
|
||||
nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats
|
||||
}
|
||||
else // not flashlight pass
|
||||
{
|
||||
if (params[info.m_nBaseTexture]->IsTexture())
|
||||
{
|
||||
pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true );
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
|
||||
int userDataSize = 0;
|
||||
|
||||
// Always enable...will bind white if nothing specified...
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base (albedo) map
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map
|
||||
pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Noise map
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Flashlight cookie
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true );
|
||||
userDataSize = 4; // tangent S
|
||||
}
|
||||
|
||||
// Always enable, since flat normal will be bound
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Normal map
|
||||
userDataSize = 4; // tangent S
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Normalizing cube map
|
||||
pShaderShadow->EnableSRGBWrite( true );
|
||||
|
||||
// texcoord0 : base texcoord, texcoord2 : decal hw morph delta
|
||||
int pTexCoordDim[3] = { 2, 0, 3 };
|
||||
int nTexCoordCount = 1;
|
||||
|
||||
// This shader supports compressed vertices, so OR in that flag:
|
||||
flags |= VERTEX_FORMAT_COMPRESSED;
|
||||
|
||||
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( example_model_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( example_model_vs20 );
|
||||
|
||||
// Assume we're only going to get in here if we support 2b
|
||||
DECLARE_STATIC_PIXEL_SHADER( example_model_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CONVERT_TO_SRGB, 0 );
|
||||
SET_STATIC_PIXEL_SHADER( example_model_ps20b );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
pShader->FogToBlack();
|
||||
}
|
||||
else
|
||||
{
|
||||
pShader->DefaultFog();
|
||||
}
|
||||
|
||||
// HACK HACK HACK - enable alpha writes all the time so that we have them for underwater stuff
|
||||
pShaderShadow->EnableAlphaWrites( bFullyOpaque );
|
||||
}
|
||||
else // not snapshotting -- begin dynamic state
|
||||
{
|
||||
bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
|
||||
|
||||
if( bHasBaseTexture )
|
||||
{
|
||||
pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE );
|
||||
}
|
||||
|
||||
LightState_t lightState = { 0, false, false };
|
||||
bool bFlashlightShadows = false;
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
|
||||
pShader->BindTexture( SHADER_SAMPLER6, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
|
||||
VMatrix worldToTexture;
|
||||
ITexture *pFlashlightDepthTexture;
|
||||
FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
|
||||
bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL );
|
||||
|
||||
SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR );
|
||||
|
||||
if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows )
|
||||
{
|
||||
pShader->BindTexture( SHADER_SAMPLER4, pFlashlightDepthTexture, 0 );
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D );
|
||||
}
|
||||
}
|
||||
else // no flashlight
|
||||
{
|
||||
pShaderAPI->GetDX9LightState( &lightState );
|
||||
}
|
||||
|
||||
MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
|
||||
int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
|
||||
int numBones = pShaderAPI->GetCurrentNumBones();
|
||||
|
||||
bool bWriteDepthToAlpha = false;
|
||||
bool bWriteWaterFogToAlpha = false;
|
||||
if( bFullyOpaque )
|
||||
{
|
||||
bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha();
|
||||
bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z);
|
||||
AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." );
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( example_model_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0);
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
|
||||
SET_DYNAMIC_VERTEX_SHADER( example_model_vs20 );
|
||||
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( example_model_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
|
||||
SET_DYNAMIC_PIXEL_SHADER( example_model_ps20b );
|
||||
|
||||
pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform );
|
||||
pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 );
|
||||
pShader->SetAmbientCubeDynamicStateVertexShader();
|
||||
|
||||
if( !bHasFlashlight )
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE, !lightState.m_bAmbientLight ); // Force to black if not bAmbientLight
|
||||
pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY );
|
||||
|
||||
// handle mat_fullbright 2 (diffuse lighting only)
|
||||
if( bLightingOnly )
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY );
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
VMatrix worldToTexture;
|
||||
float atten[4], pos[4], tweaks[4];
|
||||
|
||||
const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
|
||||
SetFlashLightColorFromState( flashlightState, pShaderAPI, PSREG_FLASHLIGHT_COLOR );
|
||||
|
||||
pShader->BindTexture( SHADER_SAMPLER6, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame );
|
||||
|
||||
atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
|
||||
atten[1] = flashlightState.m_fLinearAtten;
|
||||
atten[2] = flashlightState.m_fQuadraticAtten;
|
||||
atten[3] = flashlightState.m_FarZ;
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
|
||||
|
||||
pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
|
||||
pos[1] = flashlightState.m_vecLightOrigin[1];
|
||||
pos[2] = flashlightState.m_vecLightOrigin[2];
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 );
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
|
||||
|
||||
// Tweaks associated with a given flashlight
|
||||
tweaks[0] = ShadowFilterFromState( flashlightState );
|
||||
tweaks[1] = ShadowAttenFromState( flashlightState );
|
||||
pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
|
||||
|
||||
// Dimensions of screen, used for screen-space noise map sampling
|
||||
float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
|
||||
int nWidth, nHeight;
|
||||
pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
|
||||
vScreenScale[0] = (float) nWidth / 32.0f;
|
||||
vScreenScale[1] = (float) nHeight / 32.0f;
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
|
||||
}
|
||||
}
|
||||
pShader->Draw();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr )
|
||||
|
||||
{
|
||||
bool bHasFlashlight = pShader->UsingFlashlight( params );
|
||||
if ( bHasFlashlight )
|
||||
{
|
||||
DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression, pContextDataPtr++ );
|
||||
if ( pShaderShadow )
|
||||
{
|
||||
pShader->SetInitialShadowState( );
|
||||
}
|
||||
}
|
||||
DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression, pContextDataPtr );
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
#include "BaseVSShader.h"
|
||||
#include "example_model_dx9_helper.h"
|
||||
#include "convar.h"
|
||||
#include "cpp_shader_constant_register_map.h"
|
||||
#include "example_model_vs20.inc"
|
||||
#include "example_model_ps20b.inc"
|
||||
#include "commandbuilder.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT );
|
||||
static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT );
|
||||
static ConVar r_rimlight( "r_rimlight", "1", FCVAR_CHEAT );
|
||||
|
||||
// Textures may be bound to the following samplers:
|
||||
// SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha
|
||||
// SHADER_SAMPLER4 Flashlight Shadow Depth Map
|
||||
// SHADER_SAMPLER5 Normalization cube map
|
||||
// SHADER_SAMPLER6 Flashlight Cookie
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialize shader parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ExampleModel_DX9_Vars_t &info )
|
||||
{
|
||||
// FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
|
||||
Assert( info.m_nFlashlightTexture >= 0 );
|
||||
|
||||
if ( g_pHardwareConfig->SupportsBorderColor() )
|
||||
{
|
||||
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
|
||||
}
|
||||
else
|
||||
{
|
||||
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
|
||||
}
|
||||
|
||||
// This shader can be used with hw skinning
|
||||
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
|
||||
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialize shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, ExampleModel_DX9_Vars_t &info )
|
||||
{
|
||||
Assert( info.m_nFlashlightTexture >= 0 );
|
||||
pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
|
||||
|
||||
bool bIsBaseTextureTranslucent = false;
|
||||
if ( params[info.m_nBaseTexture]->IsDefined() )
|
||||
{
|
||||
pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
|
||||
|
||||
if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
|
||||
{
|
||||
bIsBaseTextureTranslucent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CExampleModel_DX9_Context : public CBasePerMaterialContextData
|
||||
{
|
||||
public:
|
||||
CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut;
|
||||
bool m_bFastPath;
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void DrawExampleModel_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
bool bHasFlashlight, ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression,
|
||||
CBasePerMaterialContextData **pContextDataPtr )
|
||||
{
|
||||
bool bHasBaseTexture = (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsTexture();
|
||||
bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
|
||||
|
||||
BlendType_t nBlendType= pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true );
|
||||
bool bFullyOpaque = ( nBlendType != BT_BLENDADD ) && ( nBlendType != BT_BLEND ) && !bIsAlphaTested && !bHasFlashlight;
|
||||
|
||||
CExampleModel_DX9_Context *pContextData = reinterpret_cast< CExampleModel_DX9_Context *> ( *pContextDataPtr );
|
||||
if ( !pContextData )
|
||||
{
|
||||
pContextData = new CExampleModel_DX9_Context;
|
||||
*pContextDataPtr = pContextData;
|
||||
}
|
||||
|
||||
if( pShader->IsSnapshotting() )
|
||||
{
|
||||
pShaderShadow->EnableAlphaTest( bIsAlphaTested );
|
||||
|
||||
if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f )
|
||||
{
|
||||
pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() );
|
||||
}
|
||||
|
||||
int nShadowFilterMode = 0;
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
if (params[info.m_nBaseTexture]->IsTexture())
|
||||
{
|
||||
pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
|
||||
}
|
||||
|
||||
if( bIsAlphaTested )
|
||||
{
|
||||
// disable alpha test and use the zfunc zequals since alpha isn't guaranteed to
|
||||
// be the same on both the regular pass and the flashlight pass.
|
||||
pShaderShadow->EnableAlphaTest( false );
|
||||
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL );
|
||||
}
|
||||
pShaderShadow->EnableBlending( true );
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
// Be sure not to write to dest alpha
|
||||
pShaderShadow->EnableAlphaWrites( false );
|
||||
|
||||
nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats
|
||||
}
|
||||
else // not flashlight pass
|
||||
{
|
||||
if (params[info.m_nBaseTexture]->IsTexture())
|
||||
{
|
||||
pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true );
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
|
||||
int userDataSize = 0;
|
||||
|
||||
// Always enable...will bind white if nothing specified...
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base (albedo) map
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map
|
||||
pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Noise map
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Flashlight cookie
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true );
|
||||
userDataSize = 4; // tangent S
|
||||
}
|
||||
|
||||
// Always enable, since flat normal will be bound
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Normal map
|
||||
userDataSize = 4; // tangent S
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Normalizing cube map
|
||||
pShaderShadow->EnableSRGBWrite( true );
|
||||
|
||||
// texcoord0 : base texcoord, texcoord2 : decal hw morph delta
|
||||
int pTexCoordDim[3] = { 2, 0, 3 };
|
||||
int nTexCoordCount = 1;
|
||||
|
||||
// This shader supports compressed vertices, so OR in that flag:
|
||||
flags |= VERTEX_FORMAT_COMPRESSED;
|
||||
|
||||
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( example_model_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( example_model_vs20 );
|
||||
|
||||
// Assume we're only going to get in here if we support 2b
|
||||
DECLARE_STATIC_PIXEL_SHADER( example_model_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CONVERT_TO_SRGB, 0 );
|
||||
SET_STATIC_PIXEL_SHADER( example_model_ps20b );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
pShader->FogToBlack();
|
||||
}
|
||||
else
|
||||
{
|
||||
pShader->DefaultFog();
|
||||
}
|
||||
|
||||
// HACK HACK HACK - enable alpha writes all the time so that we have them for underwater stuff
|
||||
pShaderShadow->EnableAlphaWrites( bFullyOpaque );
|
||||
}
|
||||
else // not snapshotting -- begin dynamic state
|
||||
{
|
||||
bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
|
||||
|
||||
if( bHasBaseTexture )
|
||||
{
|
||||
pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE );
|
||||
}
|
||||
|
||||
LightState_t lightState = { 0, false, false };
|
||||
bool bFlashlightShadows = false;
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
|
||||
pShader->BindTexture( SHADER_SAMPLER6, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
|
||||
VMatrix worldToTexture;
|
||||
ITexture *pFlashlightDepthTexture;
|
||||
FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
|
||||
bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL );
|
||||
|
||||
SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR );
|
||||
|
||||
if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows )
|
||||
{
|
||||
pShader->BindTexture( SHADER_SAMPLER4, pFlashlightDepthTexture, 0 );
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D );
|
||||
}
|
||||
}
|
||||
else // no flashlight
|
||||
{
|
||||
pShaderAPI->GetDX9LightState( &lightState );
|
||||
}
|
||||
|
||||
MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
|
||||
int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
|
||||
int numBones = pShaderAPI->GetCurrentNumBones();
|
||||
|
||||
bool bWriteDepthToAlpha = false;
|
||||
bool bWriteWaterFogToAlpha = false;
|
||||
if( bFullyOpaque )
|
||||
{
|
||||
bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha();
|
||||
bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z);
|
||||
AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." );
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( example_model_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0);
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
|
||||
SET_DYNAMIC_VERTEX_SHADER( example_model_vs20 );
|
||||
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( example_model_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
|
||||
SET_DYNAMIC_PIXEL_SHADER( example_model_ps20b );
|
||||
|
||||
pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform );
|
||||
pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 );
|
||||
pShader->SetAmbientCubeDynamicStateVertexShader();
|
||||
|
||||
if( !bHasFlashlight )
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE, !lightState.m_bAmbientLight ); // Force to black if not bAmbientLight
|
||||
pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY );
|
||||
|
||||
// handle mat_fullbright 2 (diffuse lighting only)
|
||||
if( bLightingOnly )
|
||||
{
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY );
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
|
||||
|
||||
if( bHasFlashlight )
|
||||
{
|
||||
VMatrix worldToTexture;
|
||||
float atten[4], pos[4], tweaks[4];
|
||||
|
||||
const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
|
||||
SetFlashLightColorFromState( flashlightState, pShaderAPI, PSREG_FLASHLIGHT_COLOR );
|
||||
|
||||
pShader->BindTexture( SHADER_SAMPLER6, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame );
|
||||
|
||||
atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
|
||||
atten[1] = flashlightState.m_fLinearAtten;
|
||||
atten[2] = flashlightState.m_fQuadraticAtten;
|
||||
atten[3] = flashlightState.m_FarZ;
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
|
||||
|
||||
pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
|
||||
pos[1] = flashlightState.m_vecLightOrigin[1];
|
||||
pos[2] = flashlightState.m_vecLightOrigin[2];
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 );
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
|
||||
|
||||
// Tweaks associated with a given flashlight
|
||||
tweaks[0] = ShadowFilterFromState( flashlightState );
|
||||
tweaks[1] = ShadowAttenFromState( flashlightState );
|
||||
pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
|
||||
|
||||
// Dimensions of screen, used for screen-space noise map sampling
|
||||
float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
|
||||
int nWidth, nHeight;
|
||||
pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
|
||||
vScreenScale[0] = (float) nWidth / 32.0f;
|
||||
vScreenScale[1] = (float) nHeight / 32.0f;
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
|
||||
}
|
||||
}
|
||||
pShader->Draw();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
|
||||
ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr )
|
||||
|
||||
{
|
||||
bool bHasFlashlight = pShader->UsingFlashlight( params );
|
||||
if ( bHasFlashlight )
|
||||
{
|
||||
DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression, pContextDataPtr++ );
|
||||
if ( pShaderShadow )
|
||||
{
|
||||
pShader->SetInitialShadowState( );
|
||||
}
|
||||
}
|
||||
DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression, pContextDataPtr );
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
|
||||
//
|
||||
// Example shader that can be applied to models
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
#ifndef EXAMPLE_MODEL_DX9_HELPER_H
|
||||
#define EXAMPLE_MODEL_DX9_HELPER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseVSShader;
|
||||
class IMaterialVar;
|
||||
class IShaderDynamicAPI;
|
||||
class IShaderShadow;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init params/ init/ draw methods
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ExampleModel_DX9_Vars_t
|
||||
{
|
||||
ExampleModel_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); }
|
||||
|
||||
int m_nBaseTexture;
|
||||
int m_nBaseTextureFrame;
|
||||
int m_nBaseTextureTransform;
|
||||
int m_nAlphaTestReference;
|
||||
int m_nFlashlightTexture;
|
||||
int m_nFlashlightTextureFrame;
|
||||
};
|
||||
|
||||
void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params,
|
||||
const char *pMaterialName, ExampleModel_DX9_Vars_t &info );
|
||||
|
||||
void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params,
|
||||
ExampleModel_DX9_Vars_t &info );
|
||||
|
||||
void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
|
||||
IShaderShadow* pShaderShadow,
|
||||
ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression,
|
||||
CBasePerMaterialContextData **pContextDataPtr );
|
||||
|
||||
#endif // EXAMPLE_MODEL_DX9_HELPER_H
|
||||
//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
|
||||
//
|
||||
// Example shader that can be applied to models
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
#ifndef EXAMPLE_MODEL_DX9_HELPER_H
|
||||
#define EXAMPLE_MODEL_DX9_HELPER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseVSShader;
|
||||
class IMaterialVar;
|
||||
class IShaderDynamicAPI;
|
||||
class IShaderShadow;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init params/ init/ draw methods
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ExampleModel_DX9_Vars_t
|
||||
{
|
||||
ExampleModel_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); }
|
||||
|
||||
int m_nBaseTexture;
|
||||
int m_nBaseTextureFrame;
|
||||
int m_nBaseTextureTransform;
|
||||
int m_nAlphaTestReference;
|
||||
int m_nFlashlightTexture;
|
||||
int m_nFlashlightTextureFrame;
|
||||
};
|
||||
|
||||
void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params,
|
||||
const char *pMaterialName, ExampleModel_DX9_Vars_t &info );
|
||||
|
||||
void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params,
|
||||
ExampleModel_DX9_Vars_t &info );
|
||||
|
||||
void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
|
||||
IShaderShadow* pShaderShadow,
|
||||
ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression,
|
||||
CBasePerMaterialContextData **pContextDataPtr );
|
||||
|
||||
#endif // EXAMPLE_MODEL_DX9_HELPER_H
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// game_shader_dx9.vpc
|
||||
//
|
||||
// Project Script for mods to use an an example of how to override shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\$GAMENAME\bin"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory "Debug_dx9_$GAMENAME" [$WIN32]
|
||||
$IntermediateDirectory "Debug_dx9_$GAMENAME" [$WIN32]
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Release"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory "Release_dx9_$GAMENAME" [$WIN32]
|
||||
$IntermediateDirectory "Release_dx9_$GAMENAME" [$WIN32]
|
||||
}
|
||||
}
|
||||
|
||||
// Common Configuration
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;" [$WIN32||$POSIX]
|
||||
// $AdditionalIncludeDirectories "$BASE;..\..\dx9sdk\include" [$WIN32]
|
||||
$AdditionalIncludeDirectories "$BASE;fxctmp9_360;vshtmp9_360" [$X360]
|
||||
$PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS;GAME_SHADER_DLL"
|
||||
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [($WIN32||$X360) && !$GL]
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE version.lib winmm.lib" [$WIN32]
|
||||
$SystemLibraries "iconv" [$OSXALL]
|
||||
}
|
||||
}
|
||||
|
||||
$Project
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "BaseVSShader.cpp"
|
||||
|
||||
$File "example_model_dx9.cpp"
|
||||
$File "example_model_dx9_helper.cpp"
|
||||
|
||||
$File "Bloom.cpp"
|
||||
$File "screenspace_general.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "BaseVSShader.h"
|
||||
$File "common_fxc.h"
|
||||
$File "common_hlsl_cpp_consts.h"
|
||||
$File "common_ps_fxc.h"
|
||||
$File "common_vertexlitgeneric_dx9.h"
|
||||
$File "common_vs_fxc.h"
|
||||
$File "shader_constant_register_map.h"
|
||||
|
||||
$File "example_model_dx9_helper.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries" [$WIN32]
|
||||
{
|
||||
// $File "$SRCDIR\dx9sdk\lib\d3dx9.lib"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib mathlib
|
||||
$Lib shaderlib
|
||||
}
|
||||
|
||||
$File "buildsdkshaders.bat"
|
||||
$File "buildshaders.bat"
|
||||
|
||||
$Shaders "stdshader_dx9_20b.txt"
|
||||
$Shaders "stdshader_dx9_30.txt"
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// game_shader_dx9.vpc
|
||||
//
|
||||
// Project Script for mods to use an an example of how to override shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\$GAMENAME\bin"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory "Debug_dx9_$GAMENAME" [$WIN32]
|
||||
$IntermediateDirectory "Debug_dx9_$GAMENAME" [$WIN32]
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Release"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory "Release_dx9_$GAMENAME" [$WIN32]
|
||||
$IntermediateDirectory "Release_dx9_$GAMENAME" [$WIN32]
|
||||
}
|
||||
}
|
||||
|
||||
// Common Configuration
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;" [$WIN32||$POSIX]
|
||||
// $AdditionalIncludeDirectories "$BASE;..\..\dx9sdk\include" [$WIN32]
|
||||
$AdditionalIncludeDirectories "$BASE;fxctmp9_360;vshtmp9_360" [$X360]
|
||||
$PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS;GAME_SHADER_DLL"
|
||||
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [($WIN32||$X360) && !$GL]
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE version.lib winmm.lib" [$WIN32]
|
||||
$SystemLibraries "iconv" [$OSXALL]
|
||||
}
|
||||
}
|
||||
|
||||
$Project
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "BaseVSShader.cpp"
|
||||
|
||||
$File "example_model_dx9.cpp"
|
||||
$File "example_model_dx9_helper.cpp"
|
||||
|
||||
$File "Bloom.cpp"
|
||||
$File "screenspace_general.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "BaseVSShader.h"
|
||||
$File "common_fxc.h"
|
||||
$File "common_hlsl_cpp_consts.h"
|
||||
$File "common_ps_fxc.h"
|
||||
$File "common_vertexlitgeneric_dx9.h"
|
||||
$File "common_vs_fxc.h"
|
||||
$File "shader_constant_register_map.h"
|
||||
|
||||
$File "example_model_dx9_helper.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries" [$WIN32]
|
||||
{
|
||||
// $File "$SRCDIR\dx9sdk\lib\d3dx9.lib"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib mathlib
|
||||
$Lib shaderlib
|
||||
}
|
||||
|
||||
$File "buildsdkshaders.bat"
|
||||
$File "buildshaders.bat"
|
||||
|
||||
$Shaders "stdshader_dx9_20b.txt"
|
||||
$Shaders "stdshader_dx9_30.txt"
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// game_shader_dx9.vpc
|
||||
//
|
||||
// Project Script for mods to use an an example of how to override shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro GAMENAME "mod_hl2mp"
|
||||
$Include "$SRCDIR\materialsystem\stdshaders\game_shader_dx9_base.vpc"
|
||||
|
||||
$Project "Shaders (HL2MP)"
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
// game_shader_dx9.vpc
|
||||
//
|
||||
// Project Script for mods to use an an example of how to override shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro GAMENAME "mod_hl2mp"
|
||||
$Include "$SRCDIR\materialsystem\stdshaders\game_shader_dx9_base.vpc"
|
||||
|
||||
$Project "Shaders (HL2MP)"
|
||||
{
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
for($ix=-2;$ix<=2;$ix++)
|
||||
{
|
||||
for($iy=-2;$iy<=2;$iy++)
|
||||
{
|
||||
print "vRefractColor += tex2D( RefractSampler, vRefractTexCoord + $ix * ddx1 + $iy * ddy1 );\n";
|
||||
$sumweights+=1;
|
||||
}
|
||||
}
|
||||
print "float sumweights = $sumweights;\n";
|
||||
for($ix=-2;$ix<=2;$ix++)
|
||||
{
|
||||
for($iy=-2;$iy<=2;$iy++)
|
||||
{
|
||||
print "vRefractColor += tex2D( RefractSampler, vRefractTexCoord + $ix * ddx1 + $iy * ddy1 );\n";
|
||||
$sumweights+=1;
|
||||
}
|
||||
}
|
||||
print "float sumweights = $sumweights;\n";
|
||||
|
||||
@@ -1,232 +1,232 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "SDK_screenspaceeffect_vs20.inc"
|
||||
|
||||
DEFINE_FALLBACK_SHADER( SDK_screenspace_general, SDK_screenspace_general_dx9 )
|
||||
BEGIN_VS_SHADER_FLAGS( SDK_screenspace_general_dx9, "Help for screenspace_general", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" )
|
||||
SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","")
|
||||
SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","")
|
||||
SHADER_PARAM( X360APPCHOOSER, SHADER_PARAM_TYPE_INTEGER, "0", "Needed for movies in 360 launcher" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if ( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
if ( params[TEXTURE1]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE1 );
|
||||
}
|
||||
if ( params[TEXTURE2]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE2 );
|
||||
}
|
||||
if ( params[TEXTURE3]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE3 );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
|
||||
{
|
||||
return "screenspace_general_dx8";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
if (params[BASETEXTURE]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
ITexture *txtr=params[BASETEXTURE]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE1]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
ITexture *txtr=params[TEXTURE1]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE2]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
|
||||
ITexture *txtr=params[TEXTURE2]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE3]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
|
||||
ITexture *txtr=params[TEXTURE3]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() );
|
||||
}
|
||||
int fmt = VERTEX_POSITION;
|
||||
|
||||
if ( IS_PARAM_DEFINED( X360APPCHOOSER ) && ( params[X360APPCHOOSER]->GetIntValue() ) )
|
||||
{
|
||||
fmt |= VERTEX_COLOR;
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
}
|
||||
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
|
||||
|
||||
// maybe convert from linear to gamma on write.
|
||||
bool srgb_write=true;
|
||||
if (params[LINEARWRITE]->GetFloatValue())
|
||||
srgb_write=false;
|
||||
pShaderShadow->EnableSRGBWrite( srgb_write );
|
||||
|
||||
// Pre-cache shaders
|
||||
DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( X360APPCHOOSER, IS_PARAM_DEFINED( X360APPCHOOSER ) ? params[X360APPCHOOSER]->GetIntValue() : 0 );
|
||||
vsh_forgot_to_set_static_X360APPCHOOSER = 0; // This is a dirty workaround to the shortcut [= 0] in the fxc
|
||||
SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if (params[DISABLE_COLOR_WRITES]->GetIntValue())
|
||||
{
|
||||
pShaderShadow->EnableColorWrites(false);
|
||||
}
|
||||
// if (params[ALPHATESTED]->GetFloatValue())
|
||||
{
|
||||
pShaderShadow->EnableAlphaTest(true);
|
||||
pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0);
|
||||
}
|
||||
if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
|
||||
}
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
const char *szPixelShader = params[PIXSHADER]->GetStringValue();
|
||||
size_t iLength = Q_strlen( szPixelShader );
|
||||
|
||||
if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
|
||||
{
|
||||
//replace it with the ps20b shader
|
||||
char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
|
||||
memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
|
||||
szNewName[iLength] = 'b';
|
||||
szNewName[iLength + 1] = '\0';
|
||||
pShaderShadow->SetPixelShader( szNewName, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
if (params[BASETEXTURE]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
|
||||
}
|
||||
if (params[TEXTURE1]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
|
||||
}
|
||||
if (params[TEXTURE2]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
|
||||
}
|
||||
if (params[TEXTURE3]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
|
||||
}
|
||||
float c0[]={
|
||||
params[C0_X]->GetFloatValue(),
|
||||
params[C0_Y]->GetFloatValue(),
|
||||
params[C0_Z]->GetFloatValue(),
|
||||
params[C0_W]->GetFloatValue(),
|
||||
params[C1_X]->GetFloatValue(),
|
||||
params[C1_Y]->GetFloatValue(),
|
||||
params[C1_Z]->GetFloatValue(),
|
||||
params[C1_W]->GetFloatValue(),
|
||||
params[C2_X]->GetFloatValue(),
|
||||
params[C2_Y]->GetFloatValue(),
|
||||
params[C2_Z]->GetFloatValue(),
|
||||
params[C2_W]->GetFloatValue(),
|
||||
params[C3_X]->GetFloatValue(),
|
||||
params[C3_Y]->GetFloatValue(),
|
||||
params[C3_Z]->GetFloatValue(),
|
||||
params[C3_W]->GetFloatValue()
|
||||
};
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 );
|
||||
|
||||
float eyePos[4];
|
||||
pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
|
||||
pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 );
|
||||
|
||||
pShaderAPI->SetVertexShaderIndex( 0 );
|
||||
pShaderAPI->SetPixelShaderIndex( 0 );
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "SDK_screenspaceeffect_vs20.inc"
|
||||
|
||||
DEFINE_FALLBACK_SHADER( SDK_screenspace_general, SDK_screenspace_general_dx9 )
|
||||
BEGIN_VS_SHADER_FLAGS( SDK_screenspace_general_dx9, "Help for screenspace_general", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" )
|
||||
SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","")
|
||||
SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","")
|
||||
SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
|
||||
SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" )
|
||||
SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","")
|
||||
SHADER_PARAM( X360APPCHOOSER, SHADER_PARAM_TYPE_INTEGER, "0", "Needed for movies in 360 launcher" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if ( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
if ( params[TEXTURE1]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE1 );
|
||||
}
|
||||
if ( params[TEXTURE2]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE2 );
|
||||
}
|
||||
if ( params[TEXTURE3]->IsDefined() )
|
||||
{
|
||||
LoadTexture( TEXTURE3 );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
|
||||
{
|
||||
return "screenspace_general_dx8";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
|
||||
if (params[BASETEXTURE]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
ITexture *txtr=params[BASETEXTURE]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE1]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
ITexture *txtr=params[TEXTURE1]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE2]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
|
||||
ITexture *txtr=params[TEXTURE2]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() );
|
||||
}
|
||||
if (params[TEXTURE3]->IsDefined())
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
|
||||
ITexture *txtr=params[TEXTURE3]->GetTextureValue();
|
||||
ImageFormat fmt=txtr->GetImageFormat();
|
||||
if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false);
|
||||
else
|
||||
pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() );
|
||||
}
|
||||
int fmt = VERTEX_POSITION;
|
||||
|
||||
if ( IS_PARAM_DEFINED( X360APPCHOOSER ) && ( params[X360APPCHOOSER]->GetIntValue() ) )
|
||||
{
|
||||
fmt |= VERTEX_COLOR;
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
}
|
||||
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
|
||||
|
||||
// maybe convert from linear to gamma on write.
|
||||
bool srgb_write=true;
|
||||
if (params[LINEARWRITE]->GetFloatValue())
|
||||
srgb_write=false;
|
||||
pShaderShadow->EnableSRGBWrite( srgb_write );
|
||||
|
||||
// Pre-cache shaders
|
||||
DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( X360APPCHOOSER, IS_PARAM_DEFINED( X360APPCHOOSER ) ? params[X360APPCHOOSER]->GetIntValue() : 0 );
|
||||
vsh_forgot_to_set_static_X360APPCHOOSER = 0; // This is a dirty workaround to the shortcut [= 0] in the fxc
|
||||
SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
|
||||
if (params[DISABLE_COLOR_WRITES]->GetIntValue())
|
||||
{
|
||||
pShaderShadow->EnableColorWrites(false);
|
||||
}
|
||||
// if (params[ALPHATESTED]->GetFloatValue())
|
||||
{
|
||||
pShaderShadow->EnableAlphaTest(true);
|
||||
pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0);
|
||||
}
|
||||
if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
|
||||
}
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
const char *szPixelShader = params[PIXSHADER]->GetStringValue();
|
||||
size_t iLength = Q_strlen( szPixelShader );
|
||||
|
||||
if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
|
||||
{
|
||||
//replace it with the ps20b shader
|
||||
char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
|
||||
memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
|
||||
szNewName[iLength] = 'b';
|
||||
szNewName[iLength + 1] = '\0';
|
||||
pShaderShadow->SetPixelShader( szNewName, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
if (params[BASETEXTURE]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
|
||||
}
|
||||
if (params[TEXTURE1]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
|
||||
}
|
||||
if (params[TEXTURE2]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
|
||||
}
|
||||
if (params[TEXTURE3]->IsDefined())
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
|
||||
}
|
||||
float c0[]={
|
||||
params[C0_X]->GetFloatValue(),
|
||||
params[C0_Y]->GetFloatValue(),
|
||||
params[C0_Z]->GetFloatValue(),
|
||||
params[C0_W]->GetFloatValue(),
|
||||
params[C1_X]->GetFloatValue(),
|
||||
params[C1_Y]->GetFloatValue(),
|
||||
params[C1_Z]->GetFloatValue(),
|
||||
params[C1_W]->GetFloatValue(),
|
||||
params[C2_X]->GetFloatValue(),
|
||||
params[C2_Y]->GetFloatValue(),
|
||||
params[C2_Z]->GetFloatValue(),
|
||||
params[C2_W]->GetFloatValue(),
|
||||
params[C3_X]->GetFloatValue(),
|
||||
params[C3_Y]->GetFloatValue(),
|
||||
params[C3_Z]->GetFloatValue(),
|
||||
params[C3_W]->GetFloatValue()
|
||||
};
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 );
|
||||
|
||||
float eyePos[4];
|
||||
pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
|
||||
pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 );
|
||||
|
||||
pShaderAPI->SetVertexShaderIndex( 0 );
|
||||
pShaderAPI->SetPixelShaderIndex( 0 );
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Provide convenient mapping for shader constants
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef C_CODE_HACK
|
||||
#include "common_vertexlitgeneric_dx9.h"
|
||||
#endif
|
||||
|
||||
#define PSREG_SELFILLUMTINT PSREG_CONSTANT_00
|
||||
#define PSREG_DIFFUSE_MODULATION PSREG_CONSTANT_01
|
||||
#define PSREG_ENVMAP_TINT__SHADOW_TWEAKS PSREG_CONSTANT_02
|
||||
#define PSREG_SELFILLUM_SCALE_BIAS_EXP PSREG_CONSTANT_03
|
||||
#define PSREG_AMBIENT_CUBE PSREG_CONSTANT_04
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_05
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_06
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_07
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_08
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_09
|
||||
#define PSREG_ENVMAP_FRESNEL__SELFILLUMMASK PSREG_CONSTANT_10
|
||||
#define PSREG_EYEPOS_SPEC_EXPONENT PSREG_CONSTANT_11
|
||||
#define PSREG_FOG_PARAMS PSREG_CONSTANT_12
|
||||
#define PSREG_FLASHLIGHT_ATTENUATION PSREG_CONSTANT_13
|
||||
#define PSREG_FLASHLIGHT_POSITION_RIM_BOOST PSREG_CONSTANT_14
|
||||
#define PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_15
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_16
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_17
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_18
|
||||
#define PSREG_FRESNEL_SPEC_PARAMS PSREG_CONSTANT_19
|
||||
#define PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_20
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_21
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_22
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_23
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_24
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_25
|
||||
#define PSREG_SPEC_RIM_PARAMS PSREG_CONSTANT_26
|
||||
// #define **free** PSREG_CONSTANT_27 //actually using this often blows constant limits, since literals have to get stuffed somewhere...
|
||||
#define PSREG_FLASHLIGHT_COLOR PSREG_CONSTANT_28
|
||||
#define PSREG_LINEAR_FOG_COLOR PSREG_CONSTANT_29
|
||||
#define PSREG_LIGHT_SCALE PSREG_CONSTANT_30
|
||||
#define PSREG_FLASHLIGHT_SCREEN_SCALE PSREG_CONSTANT_31
|
||||
// --- End of ps_2_0 and ps_2_b constants ---
|
||||
|
||||
|
||||
#ifndef C_CODE_HACK
|
||||
//for fxc code, map the constants to register names.
|
||||
#define PSREG_CONSTANT_00 c0
|
||||
#define PSREG_CONSTANT_01 c1
|
||||
#define PSREG_CONSTANT_02 c2
|
||||
#define PSREG_CONSTANT_03 c3
|
||||
#define PSREG_CONSTANT_04 c4
|
||||
#define PSREG_CONSTANT_05 c5
|
||||
#define PSREG_CONSTANT_06 c6
|
||||
#define PSREG_CONSTANT_07 c7
|
||||
#define PSREG_CONSTANT_08 c8
|
||||
#define PSREG_CONSTANT_09 c9
|
||||
#define PSREG_CONSTANT_10 c10
|
||||
#define PSREG_CONSTANT_11 c11
|
||||
#define PSREG_CONSTANT_12 c12
|
||||
#define PSREG_CONSTANT_13 c13
|
||||
#define PSREG_CONSTANT_14 c14
|
||||
#define PSREG_CONSTANT_15 c15
|
||||
#define PSREG_CONSTANT_16 c16
|
||||
#define PSREG_CONSTANT_17 c17
|
||||
#define PSREG_CONSTANT_18 c18
|
||||
#define PSREG_CONSTANT_19 c19
|
||||
#define PSREG_CONSTANT_20 c20
|
||||
#define PSREG_CONSTANT_21 c21
|
||||
#define PSREG_CONSTANT_22 c22
|
||||
#define PSREG_CONSTANT_23 c23
|
||||
#define PSREG_CONSTANT_24 c24
|
||||
#define PSREG_CONSTANT_25 c25
|
||||
#define PSREG_CONSTANT_26 c26
|
||||
#define PSREG_CONSTANT_27 c27
|
||||
#define PSREG_CONSTANT_28 c28
|
||||
#define PSREG_CONSTANT_29 c29
|
||||
#define PSREG_CONSTANT_30 c30
|
||||
#define PSREG_CONSTANT_31 c31
|
||||
#endif
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Provide convenient mapping for shader constants
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef C_CODE_HACK
|
||||
#include "common_vertexlitgeneric_dx9.h"
|
||||
#endif
|
||||
|
||||
#define PSREG_SELFILLUMTINT PSREG_CONSTANT_00
|
||||
#define PSREG_DIFFUSE_MODULATION PSREG_CONSTANT_01
|
||||
#define PSREG_ENVMAP_TINT__SHADOW_TWEAKS PSREG_CONSTANT_02
|
||||
#define PSREG_SELFILLUM_SCALE_BIAS_EXP PSREG_CONSTANT_03
|
||||
#define PSREG_AMBIENT_CUBE PSREG_CONSTANT_04
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_05
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_06
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_07
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_08
|
||||
// PSREG_AMBIENT_CUBE PSREG_CONSTANT_09
|
||||
#define PSREG_ENVMAP_FRESNEL__SELFILLUMMASK PSREG_CONSTANT_10
|
||||
#define PSREG_EYEPOS_SPEC_EXPONENT PSREG_CONSTANT_11
|
||||
#define PSREG_FOG_PARAMS PSREG_CONSTANT_12
|
||||
#define PSREG_FLASHLIGHT_ATTENUATION PSREG_CONSTANT_13
|
||||
#define PSREG_FLASHLIGHT_POSITION_RIM_BOOST PSREG_CONSTANT_14
|
||||
#define PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_15
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_16
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_17
|
||||
// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_18
|
||||
#define PSREG_FRESNEL_SPEC_PARAMS PSREG_CONSTANT_19
|
||||
#define PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_20
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_21
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_22
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_23
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_24
|
||||
// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_25
|
||||
#define PSREG_SPEC_RIM_PARAMS PSREG_CONSTANT_26
|
||||
// #define **free** PSREG_CONSTANT_27 //actually using this often blows constant limits, since literals have to get stuffed somewhere...
|
||||
#define PSREG_FLASHLIGHT_COLOR PSREG_CONSTANT_28
|
||||
#define PSREG_LINEAR_FOG_COLOR PSREG_CONSTANT_29
|
||||
#define PSREG_LIGHT_SCALE PSREG_CONSTANT_30
|
||||
#define PSREG_FLASHLIGHT_SCREEN_SCALE PSREG_CONSTANT_31
|
||||
// --- End of ps_2_0 and ps_2_b constants ---
|
||||
|
||||
|
||||
#ifndef C_CODE_HACK
|
||||
//for fxc code, map the constants to register names.
|
||||
#define PSREG_CONSTANT_00 c0
|
||||
#define PSREG_CONSTANT_01 c1
|
||||
#define PSREG_CONSTANT_02 c2
|
||||
#define PSREG_CONSTANT_03 c3
|
||||
#define PSREG_CONSTANT_04 c4
|
||||
#define PSREG_CONSTANT_05 c5
|
||||
#define PSREG_CONSTANT_06 c6
|
||||
#define PSREG_CONSTANT_07 c7
|
||||
#define PSREG_CONSTANT_08 c8
|
||||
#define PSREG_CONSTANT_09 c9
|
||||
#define PSREG_CONSTANT_10 c10
|
||||
#define PSREG_CONSTANT_11 c11
|
||||
#define PSREG_CONSTANT_12 c12
|
||||
#define PSREG_CONSTANT_13 c13
|
||||
#define PSREG_CONSTANT_14 c14
|
||||
#define PSREG_CONSTANT_15 c15
|
||||
#define PSREG_CONSTANT_16 c16
|
||||
#define PSREG_CONSTANT_17 c17
|
||||
#define PSREG_CONSTANT_18 c18
|
||||
#define PSREG_CONSTANT_19 c19
|
||||
#define PSREG_CONSTANT_20 c20
|
||||
#define PSREG_CONSTANT_21 c21
|
||||
#define PSREG_CONSTANT_22 c22
|
||||
#define PSREG_CONSTANT_23 c23
|
||||
#define PSREG_CONSTANT_24 c24
|
||||
#define PSREG_CONSTANT_25 c25
|
||||
#define PSREG_CONSTANT_26 c26
|
||||
#define PSREG_CONSTANT_27 c27
|
||||
#define PSREG_CONSTANT_28 c28
|
||||
#define PSREG_CONSTANT_29 c29
|
||||
#define PSREG_CONSTANT_30 c30
|
||||
#define PSREG_CONSTANT_31 c31
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user