ported stdshader_* (dx6, dx7, dx8, dx9)

This commit is contained in:
EnderZip
2021-10-01 13:28:22 +07:00
parent 669f368e34
commit 99fbd1c279
1533 changed files with 162379 additions and 46973 deletions

View File

@@ -0,0 +1,294 @@
#!perl
use strict;
BEGIN {use File::Basename; push @INC, dirname($0); }
require "valve_perl_helpers.pl";
sub PrintCleanPerforceOutput
{
my $line;
while( $line = shift )
{
if( $line =~ m/currently opened/i )
{
next;
}
if( $line =~ m/already opened for edit/i )
{
next;
}
if( $line =~ m/also opened/i )
{
next;
}
if( $line =~ m/add of existing file/i )
{
next;
}
print $line;
}
}
# HACK!!!! Need to pass something in to do this rather than hard coding.
sub NormalizePerforceFilename
{
my $line = shift;
# remove newlines.
$line =~ s/\n//;
# downcase.
$line =~ tr/[A-Z]/[a-z]/;
# backslash to forwardslash
$line =~ s,\\,/,g;
# for inc files HACK!
$line =~ s/^.*(fxctmp9.*)/$1/i;
$line =~ s/^.*(vshtmp9.*)/$1/i;
# for vcs files. HACK!
$line =~ s,^.*game/platform/shaders/,,i;
return $line;
}
# COMMAND-LINE ARGUMENTS
my $x360 = 0;
my $ps3 = 0;
my $filename = shift;
if( $filename =~ m/-x360/i )
{
$x360 = 1;
$filename = shift;
}
elsif( $filename =~ m/-ps3/i )
{
$ps3 = 1;
$filename = shift;
}
my $changelistname = shift;
my $perforcebasepath = shift;
my $diffpath = join " ", @ARGV;
#print STDERR "\$filename: $filename\n";
#print STDERR "\$changelistname: $changelistname\n";
#print STDERR "\$perforcebasepath: $perforcebasepath\n";
#print STDERR "\$diffpath: $diffpath\n";
# Read the input file list before changing to the perforce directory.
open FILELIST, "<$filename";
my @inclist = <FILELIST>;
close FILELIST;
# change from the perforce directory so that our client will be correct from here out.
#print STDERR "chdir $perforcebasepath\n";
chdir $perforcebasepath || die "can't cd to $perforcebasepath";
#print "inclist before @inclist\n";
# get rid of newlines and fix slashes
@inclist =
map
{
$_ =~ s,_tmp,,g; # remove _tmp so that we check out in the proper directory
$_ =~ s,\\,/,g; # backslash to forwardslash
$_ =~ s/\n//g; # remove newlines
$_ =~ tr/[A-Z]/[a-z]/; # downcase
# $_ =~ s,.*platform/shaders/,,i;
# $_ =~ s,$perforcebasepath/,,i;
$_ =~ s,../../../game/platform/shaders/,,i; # hack. . .really want something here that works generically.
$_
} @inclist;
#print "inclist after @inclist\n";
my $prevline;
my @outlist;
foreach $_ ( sort( @inclist ) )
{
next if( defined( $prevline ) && $_ eq $prevline );
$prevline = $_;
push @outlist, $_;
}
@inclist = @outlist;
#print "\@inclist: @inclist\n";
# Get list of files on the client
# -sl Every unopened file, along with the status of
# 'same, 'diff', or 'missing' as compared to its
# revision in the depot.
my @unopenedlist = &RunCommand( "p4 diff -sl $diffpath" );
#print "\@unopenedlist: @unopenedlist\n";
my %sameunopened;
my %diffunopened;
my %missingunopened;
my $line;
foreach $line ( @unopenedlist )
{
my $same = 0;
my $diff = 0;
my $missing = 0;
if( $line =~ s/^same //i )
{
$same = 1;
}
elsif( $line =~ s/^diff //i )
{
$diff = 1;
}
elsif( $line =~ s/^missing //i )
{
$missing = 1;
}
else
{
die "checkoutincfiles.pl don't understand p4 diff -sl results: $line\n";
}
# clean up the filename
# print "before: $line\n" if $line =~ m/aftershock_vs20/i;
$line = NormalizePerforceFilename( $line );
# print "after: \"$line\"\n" if $line =~ m/aftershock_vs20/i;
# if( $line =~ m/aftershock/i )
# {
# print "unopenedlist: $line same: $same diff: $diff missing: $missing\n";
# }
# Save off the results for each line so that we can query them later.
if( $same )
{
$sameunopened{$line} = 1;
}
elsif( $diff )
{
$diffunopened{$line} = 1;
}
elsif( $missing )
{
$missingunopened{$line} = 1;
}
else
{
die;
}
}
# -sr Opened files that are the same as the revision in the
# depot.
my @openedbutsame = &RunCommand( "p4 diff -sr $diffpath" );
my %sameopened;
foreach $line ( @openedbutsame )
{
if( $line =~ m/not opened on this client/i )
{
next;
}
# clean up the filename
# print "before: $line\n" if $line =~ m/aftershock_vs20/i;
$line = NormalizePerforceFilename( $line );
# print "after: $line\n" if $line =~ m/aftershock_vs20/i;
# if( $line =~ m/aftershock/i )
# {
# print STDERR "sameopened: $line\n";
# }
$sameopened{$line} = 1;
}
my @sameunopened;
my @revert;
my @edit;
my @add;
foreach $line ( @inclist )
{
if( defined( $sameunopened{$line} ) )
{
push @sameunopened, $line;
}
elsif( defined( $sameopened{$line} ) )
{
push @revert, $line;
}
elsif( defined( $diffunopened{$line} ) )
{
push @edit, $line;
}
elsif( defined( $missingunopened{$line} ) )
{
printf STDERR "p4autocheckout.pl: $line missing\n";
}
else
{
push @add, $line;
}
}
#print "\@sameunopened = @sameunopened\n";
#print "\@revert = @revert\n";
#print "\@edit = @edit\n";
#print "\@add = @add\n";
# Get the changelist number for the named changelist if we are actually going to edit or add anything.
# We don't need it for deleting.
my $changelistarg = "";
# Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
my $changelistnumber = `valve_p4_create_changelist.cmd . \"$changelistname\"`;
# Get rid of the newline
$changelistnumber =~ s/\n//g;
#print STDERR "changelistnumber: $changelistnumber\n";
if( $changelistnumber != 0 )
{
$changelistarg = "-c $changelistnumber"
}
#my %sameunopened;
#my %diffunopened;
#my %missingunopened;
#my %sameopened;
if( scalar @edit )
{
while( scalar @edit )
{
# Grab 10 files at a time so that we don't blow cmd.exe line limits.
my @files = splice @edit, 0, 10;
my $cmd = "p4 edit $changelistarg @files";
# print STDERR $cmd . "\n";
my @results = &RunCommand( $cmd );
# print STDERR @results;
&PrintCleanPerforceOutput( @results );
}
}
if( scalar @revert )
{
while( scalar @revert )
{
# Grab 10 files at a time so that we don't blow cmd.exe line limits.
my @files = splice @revert, 0, 10;
my $cmd = "p4 revert @files";
# print STDERR $cmd . "\n";
my @results = &RunCommand( $cmd );
&PrintCleanPerforceOutput( @results );
}
}
if( scalar @add )
{
while( scalar @add )
{
# Grab 10 files at a time so that we don't blow cmd.exe line limits.
my @files = splice @add, 0, 10;
my $cmd = "p4 add $changelistarg @files";
# print STDERR $cmd . "\n";
my @results = &RunCommand( $cmd );
# print STDERR "@results\n";
&PrintCleanPerforceOutput( @results );
}
}

View File

@@ -0,0 +1,129 @@
use strict;
BEGIN {use File::Basename; push @INC, dirname($0); }
require "valve_perl_helpers.pl";
my $dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0;
# ----------------------------------------------
# COMMAND-LINE ARGS
# ----------------------------------------------
my $g_x360 = 0;
my $g_ps3 = 0;
my $g_tmpfolder = "";
my $g_vcsext = ".vcs";
my $g_SrcDir = ".";
my $inputbase;
my $g_SourceDir;
while( 1 )
{
$inputbase = shift;
if( $inputbase =~ m/-source/ )
{
$g_SourceDir = shift;
}
elsif( $inputbase =~ m/-x360/ )
{
$g_x360 = 1;
$g_tmpfolder = "_360";
$g_vcsext = ".360.vcs";
}
elsif( $inputbase =~ m/-ps3/ )
{
$g_ps3 = 1;
$g_tmpfolder = "_ps3";
$g_vcsext = ".ps3.vcs";
}
else
{
last;
}
}
# ----------------------------------------------
# Load the list of shaders that we care about.
# ----------------------------------------------
my @srcfiles = &LoadShaderListFile( $inputbase );
my %incHash;
my %vcsHash;
my $shader;
foreach $shader ( @srcfiles )
{
my $shadertype = &LoadShaderListFile_GetShaderType( $shader );
my $shaderbase = &LoadShaderListFile_GetShaderBase( $shader );
my $shadersrc = &LoadShaderListFile_GetShaderSrc( $shader );
if( $shadertype eq "fxc" || $shadertype eq "vsh" )
{
# We only generate inc files for fxc and vsh files.
my $incFileName = "$shadertype" . "tmp9" . $g_tmpfolder . "/" . $shaderbase . "\.inc";
$incFileName =~ tr/A-Z/a-z/;
$incHash{$incFileName} = 1;
}
my $vcsFileName = "$shadertype/$shaderbase" . $g_vcsext;
$vcsFileName =~ tr/A-Z/a-z/;
$vcsHash{$vcsFileName} = 1;
}
# ----------------------------------------------
# Get the list of inc files to consider for reverting
# ----------------------------------------------
sub RevertIntegratedFiles
{
my $path = shift;
my $fileHashRef = shift;
my $cmd = "p4 fstat $path";
my @fstat = &RunCommand( $cmd );
my $depotFile;
my $action;
my @openedforintegrate;
my $line;
foreach $line ( @fstat )
{
if( $line =~ m,depotFile (.*)\n, )
{
$depotFile = &NormalizePerforceFilename( $1 );
}
elsif( $line =~ m,action (.*)\n, )
{
$action = $1;
}
elsif( $line =~ m,^\s*$, )
{
if( defined $action && defined $fileHashRef->{$depotFile} && $action =~ m/integrate/i )
{
push @openedforintegrate, $depotFile;
}
undef $depotFile;
undef $action;
}
}
if( scalar( @openedforintegrate ) )
{
my $cmd = "p4 revert @openedforintegrate";
# print "$cmd\n";
my @revertOutput = &RunCommand( $cmd );
&PrintCleanPerforceOutput( @revertOutput );
}
}
my $path = "vshtmp9" . $g_tmpfolder . "/... fxctmp9" . $g_tmpfolder . "/...";
&RevertIntegratedFiles( $path, \%incHash );
if( !$dynamic_compile )
{
&MakeDirHier( "../../../game/platform/shaders" );
# Might be in a different client for the vcs files, so chdir to the correct place.
chdir "../../../game/platform/shaders" || die;
my $path = "...";
&RevertIntegratedFiles( $path, \%vcsHash );
}

View File

@@ -0,0 +1,114 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "BaseVSShader.h"
#include "common_hlsl_cpp_consts.h"
#include "screenspaceeffect_vs20.inc"
#include "accumbuff4sample_ps20.inc"
#include "accumbuff4sample_ps20b.inc"
#include "convar.h"
BEGIN_VS_SHADER_FLAGS( accumbuff4sample, "Help for AccumBuff4Sample", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
// Four textures to sample
SHADER_PARAM( TEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" )
SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
// Corresponding weights for the four input textures
SHADER_PARAM( WEIGHTS, SHADER_PARAM_TYPE_VEC4, "", "Weight for Samples" )
END_SHADER_PARAMS
SHADER_INIT
{
LoadTexture( TEXTURE0 );
LoadTexture( TEXTURE1 );
LoadTexture( TEXTURE2 );
LoadTexture( TEXTURE3 );
}
SHADER_FALLBACK
{
// Requires DX9 + above
if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
{
Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableDepthTest( false );
pShaderShadow->EnableAlphaWrites( false );
pShaderShadow->EnableBlending( false );
pShaderShadow->EnableCulling( false );
// pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
int fmt = VERTEX_POSITION;
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
// Render targets are pegged as sRGB on OSX togl, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b );
SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 );
SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, TEXTURE0, -1 );
BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
SetPixelShaderConstant( 0, WEIGHTS );
DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b );
SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 );
SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,32 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler TexSampler0 : register( s0 );
sampler TexSampler1 : register( s1 );
sampler TexSampler2 : register( s2 );
sampler TexSampler3 : register( s3 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
const float4 weights : register( c0 );
float4 main( PS_INPUT i ) : COLOR
{
// Just sample the four input textures
float4 sample0 = tex2D( TexSampler0, i.texCoord );
float4 sample1 = tex2D( TexSampler1, i.texCoord );
float4 sample2 = tex2D( TexSampler2, i.texCoord );
float4 sample3 = tex2D( TexSampler3, i.texCoord );
// Compute weighted average and return
return FinalOutput( weights.x * sample0 +
weights.y * sample1 +
weights.z * sample2 +
weights.w * sample3, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,440 +1,440 @@
//========= 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 SetVertexShaderMatrix2x4( int vertexReg, int matrixVar );
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 SetVertexShaderMatrix2x4( int vertexReg, int matrixVar );
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

View File

@@ -1,90 +1,90 @@
//===== Copyright <20> 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 Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "screenspaceeffect_vs20.inc"
#include "Bloom_ps20.inc"
#include "Bloom_ps20b.inc"
BEGIN_VS_SHADER_FLAGS( 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( screenspaceeffect_vs20 );
SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( bloom_ps20b );
SET_STATIC_PIXEL_SHADER( bloom_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( bloom_ps20 );
SET_STATIC_PIXEL_SHADER( bloom_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 );
DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( bloom_ps20b );
SET_DYNAMIC_PIXEL_SHADER( bloom_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( bloom_ps20 );
SET_DYNAMIC_PIXEL_SHADER( bloom_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,21 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler FBSampler : register( s0 );
sampler BlurSampler : register( s1 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
float4 main( PS_INPUT i ) : COLOR
{
float4 fbSample = tex2D( FBSampler, i.texCoord );
float4 blurSample = tex2D( BlurSampler, i.texCoord );
return FinalOutput( float4( fbSample + blurSample.rgb * blurSample.a * MAX_HDR_OVERBRIGHT, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -1,122 +1,122 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "BlurFilter_vs20.inc"
#include "BlurFilter_ps20.inc"
#include "BlurFilter_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( BlurFilterX, "Help for BlurFilterX", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_INIT
{
if( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "BlurFilterX_DX80";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Render targets are pegged as sRGB on POSIX, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
// Pre-cache shaders
blurfilter_vs20_Static_Index vshIndex;
pShaderShadow->SetVertexShader( "BlurFilter_vs20", vshIndex.GetIndex() );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
#ifndef _X360
SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite );
#endif
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
SET_STATIC_PIXEL_SHADER( blurfilter_ps20 );
}
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
float v[4];
// The temp buffer is 1/4 back buffer size
ITexture *src_texture = params[BASETEXTURE]->GetTextureValue();
int width = src_texture->GetActualWidth();
float dX = 1.0f / width;
// Tap offsets
v[0] = 1.3366f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
v[0] = 3.4295f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
v[0] = 5.4264f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
v[0] = 7.4359f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
v[0] = 9.4436f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 1, v, 1 );
v[0] = 11.4401f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 2, v, 1 );
v[0] = v[1] = v[2] = v[3] = 1.0;
pShaderAPI->SetPixelShaderConstant( 3, v, 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
}
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "BlurFilter_vs20.inc"
#include "BlurFilter_ps20.inc"
#include "BlurFilter_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( BlurFilterX, "Help for BlurFilterX", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_INIT
{
if( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "BlurFilterX_DX80";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Render targets are pegged as sRGB on POSIX, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
// Pre-cache shaders
blurfilter_vs20_Static_Index vshIndex;
pShaderShadow->SetVertexShader( "BlurFilter_vs20", vshIndex.GetIndex() );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
#ifndef _X360
SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite );
#endif
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
SET_STATIC_PIXEL_SHADER( blurfilter_ps20 );
}
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
float v[4];
// The temp buffer is 1/4 back buffer size
ITexture *src_texture = params[BASETEXTURE]->GetTextureValue();
int width = src_texture->GetActualWidth();
float dX = 1.0f / width;
// Tap offsets
v[0] = 1.3366f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
v[0] = 3.4295f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
v[0] = 5.4264f * dX;
v[1] = 0.0f;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
v[0] = 7.4359f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
v[0] = 9.4436f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 1, v, 1 );
v[0] = 11.4401f * dX;
v[1] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 2, v, 1 );
v[0] = v[1] = v[2] = v[3] = 1.0;
pShaderAPI->SetPixelShaderConstant( 3, v, 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -1,86 +1,86 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BlurFilterX, BlurFilterX_DX80 )
BEGIN_VS_SHADER_FLAGS( BlurFilterX_DX80, "Help for BlurFilterX_DX80", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_INIT
{
if( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
{
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Pre-cache shaders
pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 );
pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 );
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 );
// The temp buffer is 1/4 back buffer size
ITexture *src_texture=params[BASETEXTURE]->GetTextureValue();
int width = src_texture->GetActualWidth();
float dX = 2.0f / width;
// 4 Tap offsets, expected from pixel center
float v[4][4];
v[0][0] = -1.5f * dX;
v[0][1] = 0;
v[1][0] = -0.5f * dX;
v[1][1] = 0;
v[2][0] = 0.5f * dX;
v[2][1] = 0;
v[3][0] = 1.5f * dX;
v[3][1] = 0;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
v[0][0] = v[0][1] = v[0][2] = v[0][3] = 1.0f;
pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
pShaderAPI->SetPixelShaderIndex( 0 );
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BlurFilterX, BlurFilterX_DX80 )
BEGIN_VS_SHADER_FLAGS( BlurFilterX_DX80, "Help for BlurFilterX_DX80", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_INIT
{
if( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
{
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Pre-cache shaders
pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 );
pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 );
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 );
// The temp buffer is 1/4 back buffer size
ITexture *src_texture=params[BASETEXTURE]->GetTextureValue();
int width = src_texture->GetActualWidth();
float dX = 2.0f / width;
// 4 Tap offsets, expected from pixel center
float v[4][4];
v[0][0] = -1.5f * dX;
v[0][1] = 0;
v[1][0] = -0.5f * dX;
v[1][1] = 0;
v[2][0] = 0.5f * dX;
v[2][1] = 0;
v[3][0] = 1.5f * dX;
v[3][1] = 0;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
v[0][0] = v[0][1] = v[0][2] = v[0][3] = 1.0f;
pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
pShaderAPI->SetPixelShaderIndex( 0 );
}
Draw();
}
END_SHADER

View File

@@ -1,136 +1,136 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "BlurFilter_vs20.inc"
#include "BlurFilter_ps20.inc"
#include "BlurFilter_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( BlurFilterY, "Help for BlurFilterY", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
if ( !( params[BLOOMAMOUNT]->IsDefined() ) )
{
params[BLOOMAMOUNT]->SetFloatValue( 1.0 );
}
}
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "BlurFilterY_DX80";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Render targets are pegged as sRGB on POSIX, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
// Pre-cache shaders
DECLARE_STATIC_VERTEX_SHADER( blurfilter_vs20 );
SET_STATIC_VERTEX_SHADER( blurfilter_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
#ifndef _X360
SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite );
#endif
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
SET_STATIC_PIXEL_SHADER( blurfilter_ps20 );
}
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
// The temp buffer is 1/4 back buffer size
ITexture *src_texture = params[BASETEXTURE]->GetTextureValue();
int height = src_texture->GetActualWidth();
float dY = 1.0f / height;
// dY *= 0.4;
float v[4];
// Tap offsets
v[0] = 0.0f;
v[1] = 1.3366f * dY;
v[2] = 0;
v[3] = 0;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
v[0] = 0.0f;
v[1] = 3.4295f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
v[0] = 0.0f;
v[1] = 5.4264f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
v[0] = 0.0f;
v[1] = 7.4359f * dY;
pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
v[0] = 0.0f;
v[1] = 9.4436f * dY;
pShaderAPI->SetPixelShaderConstant( 1, v, 1 );
v[0] = 0.0f;
v[1] = 11.4401f * dY;
pShaderAPI->SetPixelShaderConstant( 2, v, 1 );
v[0]=v[1]=v[2]=params[BLOOMAMOUNT]->GetFloatValue();
pShaderAPI->SetPixelShaderConstant( 3, v, 1 );
DECLARE_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
SET_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
}
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "BlurFilter_vs20.inc"
#include "BlurFilter_ps20.inc"
#include "BlurFilter_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( BlurFilterY, "Help for BlurFilterY", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
if ( !( params[BLOOMAMOUNT]->IsDefined() ) )
{
params[BLOOMAMOUNT]->SetFloatValue( 1.0 );
}
}
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "BlurFilterY_DX80";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Render targets are pegged as sRGB on POSIX, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
// Pre-cache shaders
DECLARE_STATIC_VERTEX_SHADER( blurfilter_vs20 );
SET_STATIC_VERTEX_SHADER( blurfilter_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
#ifndef _X360
SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite );
#endif
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
SET_STATIC_PIXEL_SHADER( blurfilter_ps20 );
}
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
// The temp buffer is 1/4 back buffer size
ITexture *src_texture = params[BASETEXTURE]->GetTextureValue();
int height = src_texture->GetActualWidth();
float dY = 1.0f / height;
// dY *= 0.4;
float v[4];
// Tap offsets
v[0] = 0.0f;
v[1] = 1.3366f * dY;
v[2] = 0;
v[3] = 0;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
v[0] = 0.0f;
v[1] = 3.4295f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
v[0] = 0.0f;
v[1] = 5.4264f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
v[0] = 0.0f;
v[1] = 7.4359f * dY;
pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
v[0] = 0.0f;
v[1] = 9.4436f * dY;
pShaderAPI->SetPixelShaderConstant( 1, v, 1 );
v[0] = 0.0f;
v[1] = 11.4401f * dY;
pShaderAPI->SetPixelShaderConstant( 2, v, 1 );
v[0]=v[1]=v[2]=params[BLOOMAMOUNT]->GetFloatValue();
pShaderAPI->SetPixelShaderConstant( 3, v, 1 );
DECLARE_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
SET_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -1,91 +1,91 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BlurFilterY, BlurFilterY_DX80 )
BEGIN_VS_SHADER_FLAGS( BlurFilterY_DX80, "Help for BlurFilterY_DX80", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
END_SHADER_PARAMS
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
if ( !( params[BLOOMAMOUNT]->IsDefined() ) )
params[BLOOMAMOUNT]->SetFloatValue(1.0);
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
{
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Pre-cache shaders
pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 );
pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 );
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 );
int width, height;
pShaderAPI->GetBackBufferDimensions( width, height );
// The temp buffer is 1/4 back buffer size
float dY = 2.0f / height;
// 4 Tap offsets, expected from pixel center
float v[4][4];
v[0][0] = 0;
v[0][1] = -1.5f * dY;
v[1][0] = 0;
v[1][1] = -0.5f * dY;
v[2][0] = 0;
v[2][1] = 0.5f * dY;
v[3][0] = 0;
v[3][1] = 1.5f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
v[0][0] = v[0][1] = v[0][2] = params[BLOOMAMOUNT]->GetFloatValue();
pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
pShaderAPI->SetPixelShaderIndex( 0 );
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BlurFilterY, BlurFilterY_DX80 )
BEGIN_VS_SHADER_FLAGS( BlurFilterY_DX80, "Help for BlurFilterY_DX80", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
END_SHADER_PARAMS
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
if ( !( params[BLOOMAMOUNT]->IsDefined() ) )
params[BLOOMAMOUNT]->SetFloatValue(1.0);
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
{
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
// Pre-cache shaders
pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 );
pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 );
if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 );
BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 );
int width, height;
pShaderAPI->GetBackBufferDimensions( width, height );
// The temp buffer is 1/4 back buffer size
float dY = 2.0f / height;
// 4 Tap offsets, expected from pixel center
float v[4][4];
v[0][0] = 0;
v[0][1] = -1.5f * dY;
v[1][0] = 0;
v[1][1] = -0.5f * dY;
v[2][0] = 0;
v[2][1] = 0.5f * dY;
v[3][0] = 0;
v[3][1] = 1.5f * dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
v[0][0] = v[0][1] = v[0][2] = params[BLOOMAMOUNT]->GetFloatValue();
pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
pShaderAPI->SetPixelShaderIndex( 0 );
}
Draw();
}
END_SHADER

View File

@@ -1,18 +1,18 @@
ps.1.1
// 1221 filter constants
def c0, 0.1667f, 0.1667f, 0.1667f, 0.3333f
tex t0
tex t1
tex t2
tex t3
mul r0.rgb, t0, c0
mad r0.rgb, t1, c0.a, r0
mad r0.rgb, t2, c0.a, r0
mad r0.rgb, t3, c0, r0
mul r0.rgb, r0, c1 +
mov r0.a, t0.a
ps.1.1
// 1221 filter constants
def c0, 0.1667f, 0.1667f, 0.1667f, 0.3333f
tex t0
tex t1
tex t2
tex t3
mul r0.rgb, t0, c0
mad r0.rgb, t1, c0.a, r0
mad r0.rgb, t2, c0.a, r0
mad r0.rgb, t3, c0, r0
mul r0.rgb, r0, c1 +
mov r0.a, t0.a

View File

@@ -1,91 +1,91 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "APPROX_SRGB_ADAPTER" "0..1" [ps20b] [PC]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler TexSampler : register( s0 );
struct PS_INPUT
{
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
float2 coordTap1Neg : TEXCOORD4;
float2 coordTap2Neg : TEXCOORD5;
float2 coordTap3Neg : TEXCOORD6;
};
float2 psTapOffs[3] : register( c0 );
float3 scale_factor : register( c3 );
float4 SampleTexture( sampler texSampler, float2 uv )
{
float4 cSample = tex2D( texSampler, uv );
#if ( APPROX_SRGB_ADAPTER )
{
cSample.rgb = max( cSample.rgb, float3( 0.00001f, 0.00001f, 0.00001f ) ); // rsqrt doesn't like inputs of zero
float3 ooSQRT; //
ooSQRT.r = rsqrt( cSample.r ); //
ooSQRT.g = rsqrt( cSample.g ); // Approximate linear-to-sRGB conversion
ooSQRT.b = rsqrt( cSample.b ); //
cSample.rgb *= ooSQRT.rgb; //
}
#endif
return cSample;
}
float4 main( PS_INPUT i ) : COLOR
{
float4 s0, s1, s2, s3, s4, s5, s6, color;
// Sample taps with coordinates from VS
s0 = SampleTexture( TexSampler, i.coordTap0 );
s1 = SampleTexture( TexSampler, i.coordTap1 );
s2 = SampleTexture( TexSampler, i.coordTap2 );
s3 = SampleTexture( TexSampler, i.coordTap3 );
s4 = SampleTexture( TexSampler, i.coordTap1Neg );
s5 = SampleTexture( TexSampler, i.coordTap2Neg );
s6 = SampleTexture( TexSampler, i.coordTap3Neg );
color = s0 * 0.2013f;
color += ( s1 + s4 ) * 0.2185f;
color += ( s2 + s5 ) * 0.0821f;
color += ( s3 + s6 ) * 0.0461f;
// Compute tex coords for other taps
float2 coordTap4 = i.coordTap0 + psTapOffs[0];
float2 coordTap5 = i.coordTap0 + psTapOffs[1];
float2 coordTap6 = i.coordTap0 + psTapOffs[2];
float2 coordTap4Neg = i.coordTap0 - psTapOffs[0];
float2 coordTap5Neg = i.coordTap0 - psTapOffs[1];
float2 coordTap6Neg = i.coordTap0 - psTapOffs[2];
// Sample the taps
s1 = SampleTexture( TexSampler, coordTap4 );
s2 = SampleTexture( TexSampler, coordTap5 );
s3 = SampleTexture( TexSampler, coordTap6 );
s4 = SampleTexture( TexSampler, coordTap4Neg );
s5 = SampleTexture( TexSampler, coordTap5Neg );
s6 = SampleTexture( TexSampler, coordTap6Neg );
color += ( s1 + s4 ) * 0.0262f;
color += ( s2 + s5 ) * 0.0162f;
color += ( s3 + s6 ) * 0.0102f;
color.xyz*=scale_factor.xyz;
#if ( APPROX_SRGB_ADAPTER )
{
color.xyz *= color.xyz; // Approximate sRGB-to-linear conversion
}
#endif
return color;
//return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "APPROX_SRGB_ADAPTER" "0..1" [ps20b] [PC]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler TexSampler : register( s0 );
struct PS_INPUT
{
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
float2 coordTap1Neg : TEXCOORD4;
float2 coordTap2Neg : TEXCOORD5;
float2 coordTap3Neg : TEXCOORD6;
};
float2 psTapOffs[3] : register( c0 );
float3 scale_factor : register( c3 );
float4 SampleTexture( sampler texSampler, float2 uv )
{
float4 cSample = tex2D( texSampler, uv );
#if ( APPROX_SRGB_ADAPTER )
{
cSample.rgb = max( cSample.rgb, float3( 0.00001f, 0.00001f, 0.00001f ) ); // rsqrt doesn't like inputs of zero
float3 ooSQRT; //
ooSQRT.r = rsqrt( cSample.r ); //
ooSQRT.g = rsqrt( cSample.g ); // Approximate linear-to-sRGB conversion
ooSQRT.b = rsqrt( cSample.b ); //
cSample.rgb *= ooSQRT.rgb; //
}
#endif
return cSample;
}
float4 main( PS_INPUT i ) : COLOR
{
float4 s0, s1, s2, s3, s4, s5, s6, color;
// Sample taps with coordinates from VS
s0 = SampleTexture( TexSampler, i.coordTap0 );
s1 = SampleTexture( TexSampler, i.coordTap1 );
s2 = SampleTexture( TexSampler, i.coordTap2 );
s3 = SampleTexture( TexSampler, i.coordTap3 );
s4 = SampleTexture( TexSampler, i.coordTap1Neg );
s5 = SampleTexture( TexSampler, i.coordTap2Neg );
s6 = SampleTexture( TexSampler, i.coordTap3Neg );
color = s0 * 0.2013f;
color += ( s1 + s4 ) * 0.2185f;
color += ( s2 + s5 ) * 0.0821f;
color += ( s3 + s6 ) * 0.0461f;
// Compute tex coords for other taps
float2 coordTap4 = i.coordTap0 + psTapOffs[0];
float2 coordTap5 = i.coordTap0 + psTapOffs[1];
float2 coordTap6 = i.coordTap0 + psTapOffs[2];
float2 coordTap4Neg = i.coordTap0 - psTapOffs[0];
float2 coordTap5Neg = i.coordTap0 - psTapOffs[1];
float2 coordTap6Neg = i.coordTap0 - psTapOffs[2];
// Sample the taps
s1 = SampleTexture( TexSampler, coordTap4 );
s2 = SampleTexture( TexSampler, coordTap5 );
s3 = SampleTexture( TexSampler, coordTap6 );
s4 = SampleTexture( TexSampler, coordTap4Neg );
s5 = SampleTexture( TexSampler, coordTap5Neg );
s6 = SampleTexture( TexSampler, coordTap6Neg );
color += ( s1 + s4 ) * 0.0262f;
color += ( s2 + s5 ) * 0.0162f;
color += ( s3 + s6 ) * 0.0102f;
color.xyz*=scale_factor.xyz;
#if ( APPROX_SRGB_ADAPTER )
{
color.xyz *= color.xyz; // Approximate sRGB-to-linear conversion
}
#endif
return color;
//return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -1,34 +1,34 @@
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3];
return o;
}
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3];
return o;
}

View File

@@ -1,39 +1,39 @@
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
float2 coordTap1Neg : TEXCOORD4;
float2 coordTap2Neg : TEXCOORD5;
float2 coordTap3Neg : TEXCOORD6;
};
float2 vsTapOffs[3] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord;
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap1Neg = v.vBaseTexCoord - vsTapOffs[0];
o.coordTap2Neg = v.vBaseTexCoord - vsTapOffs[1];
o.coordTap3Neg = v.vBaseTexCoord - vsTapOffs[2];
return o;
}
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
float2 coordTap1Neg : TEXCOORD4;
float2 coordTap2Neg : TEXCOORD5;
float2 coordTap3Neg : TEXCOORD6;
};
float2 vsTapOffs[3] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord;
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap1Neg = v.vBaseTexCoord - vsTapOffs[0];
o.coordTap2Neg = v.vBaseTexCoord - vsTapOffs[1];
o.coordTap3Neg = v.vBaseTexCoord - vsTapOffs[2];
return o;
}

View File

@@ -0,0 +1,51 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Clears color/depth, but obeys stencil while doing so
//
// $Header: $
// $NoKeywords: $
//=============================================================================//
#include "shaderlib/cshader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX6 )
BEGIN_SHADER_FLAGS( BufferClearObeyStencil_DX6, "Help for BufferClearObeyStencil_DX6", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" )
SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
}
SHADER_INIT
{
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS );
bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0;
pShaderShadow->EnableDepthWrites( bEnableDepthWrites );
bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0;
pShaderShadow->EnableColorWrites( bEnableColorWrites );
pShaderShadow->EnableAlphaWrites( bEnableColorWrites );
pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR );
DisableFog();
}
DYNAMIC_STATE
{
}
Draw( );
}
END_SHADER

View File

@@ -0,0 +1,67 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Clears color/depth, but obeys stencil while doing so
//
//=============================================================================//
#include "BaseVSShader.h"
#include "BufferClearObeyStencil_vs11.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX8 )
BEGIN_VS_SHADER_FLAGS( BufferClearObeyStencil_DX8, "", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" )
SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
{
return "BufferClearObeyStencil_DX6";
}
return 0;
}
SHADER_INIT
{
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS );
bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0;
pShaderShadow->EnableDepthWrites( bEnableDepthWrites );
bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0;
pShaderShadow->EnableColorWrites( bEnableColorWrites );
pShaderShadow->EnableAlphaWrites( bEnableColorWrites );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION|VERTEX_COLOR, 1, 0, 0 );
bufferclearobeystencil_vs11_Static_Index vshIndex;
pShaderShadow->SetVertexShader( "BufferClearObeyStencil_vs11", vshIndex.GetIndex() );
pShaderShadow->SetPixelShader( "BufferClearObeyStencil_ps11", 0 );
}
DYNAMIC_STATE
{
pShaderAPI->SetVertexShaderIndex( 0 );
pShaderAPI->SetPixelShaderIndex( 0 );
}
Draw( );
}
END_SHADER

View File

@@ -0,0 +1,112 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Clears color/depth, but obeys stencil while doing so
//
//=============================================================================//
#include "BaseVSShader.h"
#include "bufferclearobeystencil_vs20.inc"
#include "bufferclearobeystencil_ps20.inc"
#include "bufferclearobeystencil_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX9 )
BEGIN_VS_SHADER_FLAGS( BufferClearObeyStencil_DX9, "", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" )
SHADER_PARAM( CLEARALPHA, SHADER_PARAM_TYPE_INTEGER, "-1", "activates clearing of alpha. -1 == copy CLEARCOLOR setting" )
SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "BufferClearObeyStencil_DX8";
}
return 0;
}
SHADER_INIT
{
if ( !params[CLEARALPHA]->IsDefined() )
params[CLEARALPHA]->SetIntValue( -1 );
}
SHADER_DRAW
{
bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0;
bool bEnableAlphaWrites = (params[CLEARALPHA]->GetIntValue() >= 0) ? (params[CLEARALPHA]->GetIntValue() != 0) : bEnableColorWrites;
bool bUsesColor = bEnableColorWrites || bEnableAlphaWrites;
SHADOW_STATE
{
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS );
bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0;
pShaderShadow->EnableDepthWrites( bEnableDepthWrites );
pShaderShadow->EnableColorWrites( bEnableColorWrites );
pShaderShadow->EnableAlphaWrites( bEnableAlphaWrites );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 1, NULL, 0 );
DECLARE_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
SET_STATIC_VERTEX_SHADER_COMBO( USESCOLOR, bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() );
SET_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
//avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
{
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
}
}
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ZERO );
pShaderShadow->EnableAlphaTest( true );
pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_ALWAYS, 0 );
}
DYNAMIC_STATE
{
DECLARE_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
SET_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
//avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
{
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
}
}
}
Draw( );
}
END_SHADER

View File

@@ -0,0 +1,3 @@
ps.1.1
mov r0, v0

View File

@@ -0,0 +1,8 @@
vs.1.1
#include "macros.vsh"
mov oPos.xyz, $vPos.xyz
mov oPos.w, $cOne
mov oD0, $vColor

View File

@@ -0,0 +1,32 @@
ps.1.1
;------------------------------------------------------------------------------
; Environment mapping on a bumped surface
; t0 - Normalmap
; t3 - Cube environment map (*must* be a cube map!)
;
; c0 - color to multiply the results by
; Input texture coords required here are a little wonky.
; tc0.uv <- U,V into the normal map
; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform
; from tangent space->env map space
; tc1.q, tc2.q, tc3.q <- eye vector in env map space
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Perform matrix multiply to get a local normal bump. Then
; reflect the eye vector through the normal and sample from
; a cubic environment map.
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
; result goes in output color (multiply by constant color c0)
mul r0, t3, c0
; The output alpha comes from the normal map.
mov r0.w, t0.a ; don't need this if we aren't alpha blending!

View File

@@ -0,0 +1,83 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; Shader specific constant:
; $SHADER_SPECIFIC_CONST_4, $SHADER_SPECIFIC_CONST_5 = normal map transform
;------------------------------------------------------------------------------
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
; Transform position from object to world
dp4 $worldPos.x, $vPos, $cModel0
dp4 $worldPos.y, $vPos, $cModel1
dp4 $worldPos.z, $vPos, $cModel2
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
; Transform tangent space basis vectors to env map space (world space)
; This will produce a set of vectors mapping from tangent space to env space
; We'll use this to transform normals from the normal map from tangent space
; to environment map space.
; NOTE: use dp3 here since the basis vectors are vectors, not points
dp3 oT1.x, $vTangentS, $cModel0
dp3 oT2.x, $vTangentS, $cModel1
dp3 oT3.x, $vTangentS, $cModel2
dp3 oT1.y, $vTangentT, $cModel0
dp3 oT2.y, $vTangentT, $cModel1
dp3 oT3.y, $vTangentT, $cModel2
dp3 oT1.z, $vNormal, $cModel0
dp3 oT2.z, $vNormal, $cModel1
dp3 oT3.z, $vNormal, $cModel2
&AllocateRegister( \$worldToEye );
; Compute the vector from vertex to camera
sub $worldToEye.xyz, $cEyePos, $worldPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$worldPos );
; Move it into the w component of the texture coords, as the wacky
; pixel shader wants it there.
mov oT1.w, $worldToEye.x
mov oT2.w, $worldToEye.y
mov oT3.w, $worldToEye.z
&FreeRegister( \$worldToEye );
;------------------------------------------------------------------------------
; Texture coordinates (normal map)
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
&FreeRegister( \$projPos );

View File

@@ -0,0 +1,57 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
alloc $projPos
; Transform position from object to projection space
; put in r1 now since we need it for fog.
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$bumpOffset );
mov $bumpOffset.xy, $vTexCoord2
mov oT0, $vTexCoord0 ; bumpmap texcoords
add oT1.xy, $bumpOffset, $vTexCoord1 ; first lightmap texcoord
mad oT2.xy, $bumpOffset, $cTwo, $vTexCoord1 ; second lightmap texcoord
; make a 3
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $bumpOffset, $three, $vTexCoord1 ; third lightmap texcoord
free $three
&FreeRegister( \$bumpOffset );
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
free $projPos

View File

@@ -0,0 +1,43 @@
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
; c3 = a
; c4 = b
; c5 = c in a quadratic approx to pow( 1/2.2 )
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; Compute the dot product of axis 1 and the normal
dp3_sat r1, t0_bx2, c0
; Modulate the lightmap color by N dot Axis 1
mul r0, t1, r1
; Do the same for the other two axes
dp3_sat r1, t0_bx2, c1
mad r0, r1, t2, r0
dp3_sat r1, t0_bx2, c2
mad r0, r1, t3, r0
; Do quadratic approximation to pow( x, 1 / 2.2 )
;mad r1, c3, r0, c4 ; r1 = a*x + b
;mad_x4_sat r0, r1, r0, c5 ; r0 = r1*x + c = a*x*x + b*x + c

View File

@@ -0,0 +1,43 @@
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
; c3 = a
; c4 = b
; c5 = c in a quadratic approx to pow( 1/2.2 )
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; Compute the dot product of axis 1 and the normal
dp3_sat r1, t0_bx2, c0
; Modulate the lightmap color by N dot Axis 1
mul r0, t1, r1
; Do the same for the other two axes
dp3_sat r1, t0_bx2, c1
mad r0, r1, t2, r0
dp3_sat r1, t0_bx2, c2
mad r0, r1, t3, r0
; Do quadratic approximation to pow( x, 1 / 2.2 )
;mad r1, c3, r0, c4 ; r1 = a*x + b
;mad_x2_sat r0, r1, r0, c5 ; r0 = r1*x + c = a*x*x + b*x + c

View File

@@ -1,27 +1,27 @@
ps.1.1
;------------------------------------------------------------------------------
; See the vertex shader for info
;
; This shader takes:
; t0 = normal map
; t1 = base texture
; v0 = directional light color
; t2 = directional light direction (biased into 0-1)
; c0 = percent of dirlight to add as ambient
;
; Output:
; (t0 dot t1) * v0
;------------------------------------------------------------------------------
tex t0 ; Get the 3-vector from the normal map
tex t1 ; Interpret tcoord t1 as color data.
texcoord t2
dp3 r1, t0_bx2, t2_bx2 ; r1 = normalMap dot dirLightDir
add r0, r1, c0 ; + 0.5
mul r1, v0, r0 ; scale the dot product by the dirlight's actual color
mul r0.rgb, r1, t1 + ; scale by the texture color
mul r0.a, t1.a, v0.a
ps.1.1
;------------------------------------------------------------------------------
; See the vertex shader for info
;
; This shader takes:
; t0 = normal map
; t1 = base texture
; v0 = directional light color
; t2 = directional light direction (biased into 0-1)
; c0 = percent of dirlight to add as ambient
;
; Output:
; (t0 dot t1) * v0
;------------------------------------------------------------------------------
tex t0 ; Get the 3-vector from the normal map
tex t1 ; Interpret tcoord t1 as color data.
texcoord t2
dp3 r1, t0_bx2, t2_bx2 ; r1 = normalMap dot dirLightDir
add r0, r1, c0 ; + 0.5
mul r1, v0, r0 ; scale the dot product by the dirlight's actual color
mul r0.rgb, r1, t1 + ; scale by the texture color
mul r0.a, t1.a, v0.a

View File

@@ -1,117 +1,117 @@
vs.1.1
#include "macros.vsh"
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; The cable equation is:
; [L dot N] * C * T
;
; where:
; C = directional light color
; T = baseTexture
; N = particle normal (stored in the normal map)
; L = directional light direction
;
; $SHADER_SPECIFIC_CONST_0 = Directional light direction
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Transform position from object to projection space
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Setup the tangent space
;------------------------------------------------------------------------------
&AllocateRegister( \$tmp1 );
&AllocateRegister( \$tmp2 );
&AllocateRegister( \$tmp3 );
&AllocateRegister( \$r );
; Get S crossed with T (call it R)
mov $tmp1, $vTangentS
mov $tmp2, $vTangentT
mul $tmp3, $vTangentS.yzxw, $tmp2.zxyw
mad $r, -$vTangentS.zxyw, $tmp2.yzxw, $tmp3
&FreeRegister( \$tmp2 );
&FreeRegister( \$tmp3 );
&AllocateRegister( \$s );
; Normalize S (into $s)
dp3 $s.w, $vTangentS, $vTangentS
rsq $s.w, $s.w
mul $s.xyz, $vTangentS, $s.w
; Normalize R (into $r)
dp3 $r.w, $r, $r
rsq $r.w, $r.w
mul $r.xyz, $r, $r.w
&AllocateRegister( \$t );
; Regenerate T (into $t)
mul $t, $r.yzxw, $tmp1.zxyw
mad $t, -$r.zxyw, $tmp1.yzxw, $t
&FreeRegister( \$tmp1 );
;------------------------------------------------------------------------------
; Transform the light direction (into oD1)
;------------------------------------------------------------------------------
&AllocateRegister( \$lightDirection );
dp3 $lightDirection.x, $s, $SHADER_SPECIFIC_CONST_0
dp3 $lightDirection.y, $t, $SHADER_SPECIFIC_CONST_0
dp3 $lightDirection.z, $r, $SHADER_SPECIFIC_CONST_0
&FreeRegister( \$r );
&FreeRegister( \$s );
&FreeRegister( \$t );
; Scale into 0-1 range (we're assuming light direction was normalized prior to here)
add oT2, $lightDirection, $cHalf ; + 0.5
&FreeRegister( \$lightDirection );
;------------------------------------------------------------------------------
; Copy texcoords for the normal map and base texture
;------------------------------------------------------------------------------
mov oT0, $vTexCoord0
mov oT1, $vTexCoord1
; Pass the dirlight color through
mov oD0.xyzw, $vColor
vs.1.1
#include "macros.vsh"
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; The cable equation is:
; [L dot N] * C * T
;
; where:
; C = directional light color
; T = baseTexture
; N = particle normal (stored in the normal map)
; L = directional light direction
;
; $SHADER_SPECIFIC_CONST_0 = Directional light direction
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Transform position from object to projection space
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Setup the tangent space
;------------------------------------------------------------------------------
&AllocateRegister( \$tmp1 );
&AllocateRegister( \$tmp2 );
&AllocateRegister( \$tmp3 );
&AllocateRegister( \$r );
; Get S crossed with T (call it R)
mov $tmp1, $vTangentS
mov $tmp2, $vTangentT
mul $tmp3, $vTangentS.yzxw, $tmp2.zxyw
mad $r, -$vTangentS.zxyw, $tmp2.yzxw, $tmp3
&FreeRegister( \$tmp2 );
&FreeRegister( \$tmp3 );
&AllocateRegister( \$s );
; Normalize S (into $s)
dp3 $s.w, $vTangentS, $vTangentS
rsq $s.w, $s.w
mul $s.xyz, $vTangentS, $s.w
; Normalize R (into $r)
dp3 $r.w, $r, $r
rsq $r.w, $r.w
mul $r.xyz, $r, $r.w
&AllocateRegister( \$t );
; Regenerate T (into $t)
mul $t, $r.yzxw, $tmp1.zxyw
mad $t, -$r.zxyw, $tmp1.yzxw, $t
&FreeRegister( \$tmp1 );
;------------------------------------------------------------------------------
; Transform the light direction (into oD1)
;------------------------------------------------------------------------------
&AllocateRegister( \$lightDirection );
dp3 $lightDirection.x, $s, $SHADER_SPECIFIC_CONST_0
dp3 $lightDirection.y, $t, $SHADER_SPECIFIC_CONST_0
dp3 $lightDirection.z, $r, $SHADER_SPECIFIC_CONST_0
&FreeRegister( \$r );
&FreeRegister( \$s );
&FreeRegister( \$t );
; Scale into 0-1 range (we're assuming light direction was normalized prior to here)
add oT2, $lightDirection, $cHalf ; + 0.5
&FreeRegister( \$lightDirection );
;------------------------------------------------------------------------------
; Copy texcoords for the normal map and base texture
;------------------------------------------------------------------------------
mov oT0, $vTexCoord0
mov oT1, $vTexCoord1
; Pass the dirlight color through
mov oD0.xyzw, $vColor

View File

@@ -1,23 +1,23 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
struct PS_INPUT
{
float4 projPos : POSITION;
float3 zValue : TEXCOORD0;
};
const float3 g_ZFilter : register( c1 );
const float3 g_ModulationColor : register( c2 );
float4 main( PS_INPUT i ) : COLOR
{
float z = dot( i.zValue, g_ZFilter );
z = saturate( z );
float4 color = float4( z, z, z, 1.0f );
color.rgb *= g_ModulationColor;
return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
struct PS_INPUT
{
float4 projPos : POSITION;
float3 zValue : TEXCOORD0;
};
const float3 g_ZFilter : register( c1 );
const float3 g_ModulationColor : register( c2 );
float4 main( PS_INPUT i ) : COLOR
{
float z = dot( i.zValue, g_ZFilter );
z = saturate( z );
float4 color = float4( z, z, z, 1.0f );
color.rgb *= g_ModulationColor;
return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -1,38 +1,38 @@
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
const float2 cDepthFactor : register( SHADER_SPECIFIC_CONST_0 );
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vBoneWeights : BLENDWEIGHT;
float4 vBoneIndices : BLENDINDICES;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 zValue : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
float3 worldPos;
SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos );
float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = projPos;
o.zValue.x = (o.projPos.z - cDepthFactor.y) / cDepthFactor.x;
o.zValue.y = (o.projPos.w - cDepthFactor.y) / cDepthFactor.x;
return o;
}
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
const float2 cDepthFactor : register( SHADER_SPECIFIC_CONST_0 );
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vBoneWeights : BLENDWEIGHT;
float4 vBoneIndices : BLENDINDICES;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 zValue : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
float3 worldPos;
SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos );
float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = projPos;
o.zValue.x = (o.projPos.z - cDepthFactor.y) / cDepthFactor.x;
o.zValue.y = (o.projPos.w - cDepthFactor.y) / cDepthFactor.x;
return o;
}

View File

@@ -1,94 +1,94 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "debugdrawenvmapmask_vs20.inc"
#include "debugdrawenvmapmask_ps20.inc"
#include "debugdrawenvmapmask_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( DebugDrawEnvmapMask, "Help for DebugDrawEnvmapMask", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
}
SHADER_INIT
{
}
SHADER_FALLBACK
{
if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
// Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Set stream format (note that this shader supports compression)
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
int nTexCoordCount = 1;
int userDataSize = 0;
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
DECLARE_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
SET_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
}
}
DYNAMIC_STATE
{
int numBones = s_pShaderAPI->GetCurrentNumBones();
DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
bool bShowAlpha = params[SHOWALPHA]->GetIntValue() ? true : false;
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha );
SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha );
SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
}
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "debugdrawenvmapmask_vs20.inc"
#include "debugdrawenvmapmask_ps20.inc"
#include "debugdrawenvmapmask_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER_FLAGS( DebugDrawEnvmapMask, "Help for DebugDrawEnvmapMask", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
}
SHADER_INIT
{
}
SHADER_FALLBACK
{
if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
// Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Set stream format (note that this shader supports compression)
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
int nTexCoordCount = 1;
int userDataSize = 0;
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
DECLARE_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
SET_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
}
}
DYNAMIC_STATE
{
int numBones = s_pShaderAPI->GetCurrentNumBones();
DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 );
bool bShowAlpha = params[SHOWALPHA]->GetIntValue() ? true : false;
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha );
SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha );
SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 );
}
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
}
Draw();
}
END_SHADER

View File

@@ -1,26 +1,26 @@
// DYNAMIC: "SHOWALPHA" "0..1"
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler BaseTextureSampler : register( s0 );
struct PS_INPUT
{
float4 projPos : POSITION;
float2 baseTexCoord : TEXCOORD0;
};
float4 main( PS_INPUT i ) : COLOR
{
float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord );
#if SHOWALPHA
float4 result = float4( baseColor.a, baseColor.a, baseColor.a, 1.0f );
#else
float4 result = float4( baseColor.rgb, 1.0f );
#endif
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
// DYNAMIC: "SHOWALPHA" "0..1"
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler BaseTextureSampler : register( s0 );
struct PS_INPUT
{
float4 projPos : POSITION;
float2 baseTexCoord : TEXCOORD0;
};
float4 main( PS_INPUT i ) : COLOR
{
float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord );
#if SHOWALPHA
float4 result = float4( baseColor.a, baseColor.a, baseColor.a, 1.0f );
#else
float4 result = float4( baseColor.rgb, 1.0f );
#endif
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -1,39 +1,39 @@
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vBoneWeights : BLENDWEIGHT;
float4 vBoneIndices : BLENDINDICES;
float4 vTexCoord0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 baseTexCoord : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
float3 worldPos;
SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos );
float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = projPos;
o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
return o;
}
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vBoneWeights : BLENDWEIGHT;
float4 vBoneIndices : BLENDINDICES;
float4 vTexCoord0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 baseTexCoord : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
float3 worldPos;
SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos );
float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = projPos;
o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
return o;
}

View File

@@ -1,104 +1,104 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "BaseVSShader.h"
#include "shaderlib/cshader.h"
#include "debugtextureview_vs20.inc"
#include "debugtextureview_ps20.inc"
#include "debugtextureview_ps20b.inc"
DEFINE_FALLBACK_SHADER( DebugTextureView, DebugTextureView_dx9 )
BEGIN_VS_SHADER( DebugTextureView_dx9, "Help for DebugTextureView" )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_BOOL, "0", "" )
END_SHADER_PARAMS
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "UnlitGeneric";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaTest( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Set stream format (note that this shader supports compression)
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
int nTexCoordCount = 1;
int userDataSize = 0;
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
DECLARE_STATIC_VERTEX_SHADER( debugtextureview_vs20 );
SET_STATIC_VERTEX_SHADER( debugtextureview_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20b );
SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 );
SET_STATIC_PIXEL_SHADER( debugtextureview_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20 );
SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 );
SET_STATIC_PIXEL_SHADER( debugtextureview_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
//pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
ITexture *pTexture = params[BASETEXTURE]->GetTextureValue();
float cPsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616 ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGB323232F ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA32323232F ) )
{
if ( pTexture->IsCubeMap() )
cPsConst0[0] = 1.0f;
else
cPsConst0[1] = 1.0f;
}
pShaderAPI->SetPixelShaderConstant( 0, cPsConst0 );
DECLARE_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() );
SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() );
SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 );
}
}
Draw();
}
END_SHADER
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "BaseVSShader.h"
#include "shaderlib/cshader.h"
#include "debugtextureview_vs20.inc"
#include "debugtextureview_ps20.inc"
#include "debugtextureview_ps20b.inc"
DEFINE_FALLBACK_SHADER( DebugTextureView, DebugTextureView_dx9 )
BEGIN_VS_SHADER( DebugTextureView_dx9, "Help for DebugTextureView" )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_BOOL, "0", "" )
END_SHADER_PARAMS
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "UnlitGeneric";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaTest( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Set stream format (note that this shader supports compression)
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
int nTexCoordCount = 1;
int userDataSize = 0;
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
DECLARE_STATIC_VERTEX_SHADER( debugtextureview_vs20 );
SET_STATIC_VERTEX_SHADER( debugtextureview_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20b );
SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 );
SET_STATIC_PIXEL_SHADER( debugtextureview_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20 );
SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 );
SET_STATIC_PIXEL_SHADER( debugtextureview_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
//pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
ITexture *pTexture = params[BASETEXTURE]->GetTextureValue();
float cPsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616 ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGB323232F ) ||
( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA32323232F ) )
{
if ( pTexture->IsCubeMap() )
cPsConst0[0] = 1.0f;
else
cPsConst0[1] = 1.0f;
}
pShaderAPI->SetPixelShaderConstant( 0, cPsConst0 );
DECLARE_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() );
SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() );
SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -1,81 +1,81 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "SHOWALPHA" "0..1"
// DYNAMIC: "ISCUBEMAP" "0..1"
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler g_tSampler : register( s0 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
const float3 g_vConst0 : register( c0 );
#define g_flIsHdrCube g_vConst0.x
#define g_flIsHdr2D g_vConst0.y
float4 main( PS_INPUT i ) : COLOR
{
float4 sample = tex2D( g_tSampler, i.texCoord );
float4 result = { 0.0f, 0.0f, 0.0f, 1.0f };
result.rgb = sample.rgb;
#if SHOWALPHA
result.rgb = sample.a;
#endif
if ( g_flIsHdr2D )
result.rgb *= MAX_HDR_OVERBRIGHT;
#if ISCUBEMAP
bool bNoDataForThisPixel = false;
float3 vec = float3( 0, 0, 0 );
float x = i.texCoord.x;
float y = i.texCoord.y;
float x2 = frac( ( i.texCoord.x ) * 3.0f ) * 2.0f - 1.0f;
float y2 = frac( ( i.texCoord.y ) * 4.0f ) * 2.0f - 1.0f;
if ( ( x >= 0.3333f ) && ( x <= 0.6666f ) ) //Center row
{
if ( y >= 0.75f )
vec = float3( x2, 1.0, y2 );
else if ( y >= 0.5f )
vec = float3( x2, y2, -1.0 );
else if ( y >= 0.25f )
vec = float3( x2, -1.0, -y2 );
else if ( y >= 0.0f )
vec = float3( x2, -y2, 1.0 );
}
else if ( ( y >= 0.25f ) && ( y <= 0.5f ) )
{
if ( x <= 0.3333f )
vec = float3( -1.0f, -x2, -y2 );
else if (x >= 0.6666f)
vec = float3( 1.0f, x2, -y2 );
else
bNoDataForThisPixel = true;
}
else
{
bNoDataForThisPixel = true;
}
float4 cBase = texCUBE( g_tSampler, vec );
#if SHOWALPHA
cBase.rgb = cBase.a;
#endif
if ( g_flIsHdrCube )
cBase.rgb *= ENV_MAP_SCALE;
if ( bNoDataForThisPixel == true )
cBase.rgb = float3( 0.9f, 0.4f, 0.15f );
result.rgb = cBase.rgb;
result.a = 1.0f; // - bNoDataForThisPixel;
#endif
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "SHOWALPHA" "0..1"
// DYNAMIC: "ISCUBEMAP" "0..1"
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler g_tSampler : register( s0 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
const float3 g_vConst0 : register( c0 );
#define g_flIsHdrCube g_vConst0.x
#define g_flIsHdr2D g_vConst0.y
float4 main( PS_INPUT i ) : COLOR
{
float4 sample = tex2D( g_tSampler, i.texCoord );
float4 result = { 0.0f, 0.0f, 0.0f, 1.0f };
result.rgb = sample.rgb;
#if SHOWALPHA
result.rgb = sample.a;
#endif
if ( g_flIsHdr2D )
result.rgb *= MAX_HDR_OVERBRIGHT;
#if ISCUBEMAP
bool bNoDataForThisPixel = false;
float3 vec = float3( 0, 0, 0 );
float x = i.texCoord.x;
float y = i.texCoord.y;
float x2 = frac( ( i.texCoord.x ) * 3.0f ) * 2.0f - 1.0f;
float y2 = frac( ( i.texCoord.y ) * 4.0f ) * 2.0f - 1.0f;
if ( ( x >= 0.3333f ) && ( x <= 0.6666f ) ) //Center row
{
if ( y >= 0.75f )
vec = float3( x2, 1.0, y2 );
else if ( y >= 0.5f )
vec = float3( x2, y2, -1.0 );
else if ( y >= 0.25f )
vec = float3( x2, -1.0, -y2 );
else if ( y >= 0.0f )
vec = float3( x2, -y2, 1.0 );
}
else if ( ( y >= 0.25f ) && ( y <= 0.5f ) )
{
if ( x <= 0.3333f )
vec = float3( -1.0f, -x2, -y2 );
else if (x >= 0.6666f)
vec = float3( 1.0f, x2, -y2 );
else
bNoDataForThisPixel = true;
}
else
{
bNoDataForThisPixel = true;
}
float4 cBase = texCUBE( g_tSampler, vec );
#if SHOWALPHA
cBase.rgb = cBase.a;
#endif
if ( g_flIsHdrCube )
cBase.rgb *= ENV_MAP_SCALE;
if ( bNoDataForThisPixel == true )
cBase.rgb = float3( 0.9f, 0.4f, 0.15f );
result.rgb = cBase.rgb;
result.a = 1.0f; // - bNoDataForThisPixel;
#endif
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -1,23 +1,23 @@
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
#include "common_vs_fxc.h"
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vTexCoord0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 vProjPos : POSITION;
float2 vUv0 : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT i )
{
VS_OUTPUT o;
o.vProjPos.xyzw = mul( i.vPos.xyzw, cModelViewProj );
o.vUv0.xy = i.vTexCoord0.xy;
return o;
}
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
#include "common_vs_fxc.h"
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vTexCoord0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 vProjPos : POSITION;
float2 vUv0 : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT i )
{
VS_OUTPUT o;
o.vProjPos.xyzw = mul( i.vPos.xyzw, cModelViewProj );
o.vUv0.xy = i.vTexCoord0.xy;
return o;
}

View File

@@ -0,0 +1,9 @@
ps.1.1
tex t0 ; base texture
tex t1 ; lightmap
mul r0.rgb, t0, t1
+ mov r0.a, t0.a

View File

@@ -0,0 +1,5 @@
ps.1.1
tex t0 ; selfillum
mov r0, t0

View File

@@ -0,0 +1,83 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Header: $
// $NoKeywords: $
//===========================================================================//
#include "shaderlib/cshader.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6 )
BEGIN_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6,
"Help for DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6" )
BEGIN_SHADER_PARAMS
SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 )
SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" )
SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
}
SHADER_INIT
{
LoadTexture( BASETEXTURE );
LoadTexture( SELFILLUMTEXTURE );
}
SHADER_DRAW
{
if( g_pHardwareConfig->GetSamplerCount() < 2 )
{
ShaderWarning( "DecalBaseTimesLightmapAlphaBlendSelfIllum: not implemented for single-texturing hardware\n" );
return;
}
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT );
pShaderShadow->DrawFlags( SHADER_DRAW_POSITION |
SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 );
FogToFogColor();
}
DYNAMIC_STATE
{
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP );
BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME );
}
Draw();
SHADOW_STATE
{
SetInitialShadowState( );
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 );
FogToBlack();
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME );
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,142 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "lightmappedgeneric_vs11.inc"
#include "lightmappedgeneric_decal.inc"
#include "mathlib/bumpvects.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8 )
BEGIN_VS_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8, "" )
BEGIN_SHADER_PARAMS
SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 )
SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" )
SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
// FLASHLIGHTFIXME
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
}
SHADER_FALLBACK
{
if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) )
{
return "DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6";
}
return 0;
}
SHADER_INIT
{
LoadTexture( FLASHLIGHTTEXTURE );
LoadTexture( BASETEXTURE );
LoadTexture( SELFILLUMTEXTURE );
}
void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow )
{
if( IsSnapshotting() )
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
int pTexCoords[3] = { 2, 2, 1 };
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 );
lightmappedgeneric_decal_Static_Index vshIndex;
pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() );
pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" );
FogToFogColor();
}
else
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
// Load the z^2 components of the lightmap coordinate axes only
// This is (N dot basis)^2
Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z );
vecZValues *= vecZValues;
Vector4D basis[3];
basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f );
basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f );
basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f );
pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 );
pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED );
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
SetModulationPixelShaderDynamicState( 3 );
lightmappedgeneric_decal_Dynamic_Index vshIndex;
vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
}
Draw();
if( IsSnapshotting() )
{
SetInitialShadowState( );
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
lightmappedgeneric_vs11_Static_Index vshIndex;
vshIndex.SetDETAIL( false );
vshIndex.SetENVMAP( false );
vshIndex.SetENVMAPCAMERASPACE( false );
vshIndex.SetENVMAPSPHERE( false );
vshIndex.SetVERTEXCOLOR( false );
pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() );
pShaderShadow->SetPixelShader( "DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11" );
FogToFogColor();
}
else
{
BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME );
lightmappedgeneric_vs11_Dynamic_Index vshIndex;
vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
}
Draw();
}
SHADER_DRAW
{
if( UsingFlashlight( params ) )
{
DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 );
}
else
{
DrawDecal( params, pShaderAPI, pShaderShadow );
}
}
END_SHADER

View File

@@ -0,0 +1,270 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "BaseVSShader.h"
#include "mathlib/bumpvects.h"
#include "cpp_shader_constant_register_map.h"
#include "lightmappedgeneric_vs20.inc"
#include "lightmappedgeneric_decal_vs20.inc"
#include "lightmappedgeneric_decal_ps20.inc"
#include "lightmappedgeneric_decal_ps20b.inc"
#include "decalbasetimeslightmapalphablendselfillum2_ps20.inc"
#include "decalbasetimeslightmapalphablendselfillum2_ps20b.inc"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX9 )
extern ConVar r_flashlight_version2;
BEGIN_VS_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX9, "" )
BEGIN_SHADER_PARAMS
SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 )
SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" )
SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
if ( g_pHardwareConfig->SupportsBorderColor() )
{
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
}
else
{
params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
}
SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
}
SHADER_FALLBACK
{
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
return "DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8";
}
return 0;
}
SHADER_INIT
{
LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
LoadTexture( SELFILLUMTEXTURE );
}
void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow )
{
if( IsSnapshotting() )
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
pShaderShadow->EnableSRGBWrite( true );
// Base Texture
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
// Lightmaps
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE );
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE );
int pTexCoords[3] = { 2, 2, 1 };
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 );
DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 );
SET_STATIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b );
SET_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 );
SET_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 );
}
FogToFogColor();
}
else
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
// Load the z^2 components of the lightmap coordinate axes only
// This is (N dot basis)^2
Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z );
vecZValues *= vecZValues;
Vector4D basis[3];
basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f );
basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f );
basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f );
pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 );
pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED );
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
SetModulationPixelShaderDynamicState( 3 );
DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 );
pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
float vEyePos_SpecExponent[4];
pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
vEyePos_SpecExponent[3] = 0.0f;
pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 );
}
}
Draw();
if( IsSnapshotting() )
{
SetInitialShadowState( );
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
// Base texture
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
pShaderShadow->EnableSRGBWrite( true );
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false );
SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, false );
SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, false );
SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, false );
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false );
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false );
SET_STATIC_VERTEX_SHADER_COMBO( RELIEF_MAPPING, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, false );
SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false );
#ifdef _X360
SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, 0 );
#endif
SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b );
SET_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 );
SET_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 );
}
FogToFogColor();
}
else
{
BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME );
DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, false );
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, false );
SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
float vEyePos_SpecExponent[4];
pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
vEyePos_SpecExponent[3] = 0.0f;
pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 );
}
}
Draw();
}
void DrawPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bUsingFlashlight )
{
if( bUsingFlashlight )
{
DrawFlashlight_dx90_Vars_t flashlightVars;
flashlightVars.m_bBump = false;
flashlightVars.m_nBumpmapVar = -1;
flashlightVars.m_nBumpmapFrame = -1;
flashlightVars.m_nBumpTransform = -1;
flashlightVars.m_nFlashlightTextureVar = FLASHLIGHTTEXTURE;
flashlightVars.m_nFlashlightTextureFrameVar = FLASHLIGHTTEXTUREFRAME;
flashlightVars.m_bLightmappedGeneric = true;
flashlightVars.m_bWorldVertexTransition = false;
// int nWorldVertexTransitionPassID = 0
flashlightVars.m_nBaseTexture2Var = -1;
flashlightVars.m_nBaseTexture2FrameVar = -1;
flashlightVars.m_bTeeth = false;
flashlightVars.m_nTeethForwardVar = 0;
flashlightVars.m_nTeethIllumFactorVar = 0;
DrawFlashlight_dx90( params, pShaderAPI, pShaderShadow, flashlightVars );
}
else
{
DrawDecal( params, pShaderAPI, pShaderShadow );
}
}
SHADER_DRAW
{
bool bUsingFlashlight = UsingFlashlight( params );
if ( bUsingFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) )
{
DrawPass( params, pShaderAPI, pShaderShadow, false );
if ( pShaderShadow )
{
SetInitialShadowState( );
}
}
DrawPass( params, pShaderAPI, pShaderShadow, bUsingFlashlight );
}
END_SHADER

View File

@@ -0,0 +1,232 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Header: $
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "cpp_shader_constant_register_map.h"
#include "VertexLit_and_unlit_Generic_vs20.inc"
#include "decalmodulate_ps20.inc"
#include "decalmodulate_ps20b.inc"
#ifndef _X360
#include "vertexlit_and_unlit_generic_vs30.inc"
#include "decalmodulate_ps30.inc"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DEFINE_FALLBACK_SHADER( DecalModulate, DecalModulate_DX9 )
extern ConVar r_flashlight_version2;
BEGIN_VS_SHADER( DecalModulate_dx9,
"Help for DecalModulate_dx9" )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_FALLBACK
{
if (g_pHardwareConfig->GetDXSupportLevel() < 90)
return "DecalModulate_DX6";
return 0;
}
SHADER_INIT_PARAMS()
{
SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
#ifndef _X360
if ( g_pHardwareConfig->HasFastVertexTextures() )
{
// The vertex shader uses the vertex id stream
SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
}
#endif
}
SHADER_INIT
{
LoadTexture( BASETEXTURE );
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableAlphaTest( true );
pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f );
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Be sure not to write to dest alpha
pShaderShadow->EnableAlphaWrites( false );
// SRGB conversions hose the blend on some hardware, so keep we everything in gamma space
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
pShaderShadow->EnableSRGBWrite( false );
pShaderShadow->EnableBlending( true );
pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );
pShaderShadow->DisableFogGammaCorrection( true ); //fog should stay exactly middle grey
FogToGrey();
#ifndef _X360
if ( !g_pHardwareConfig->HasFastVertexTextures() )
#endif
{
bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 );
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false );
SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, false );
SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, false );
SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, false );
SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow );
SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, 0 );
SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20b );
SET_STATIC_PIXEL_SHADER( decalmodulate_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20 );
SET_STATIC_PIXEL_SHADER( decalmodulate_ps20 );
}
}
#ifndef _X360
else
{
DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 );
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false );
SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, false );
SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, false );
SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, false );
SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, false );
SET_STATIC_VERTEX_SHADER_COMBO( DECAL, true );
SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, 0 );
SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 );
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps30 );
SET_STATIC_PIXEL_SHADER( decalmodulate_ps30 );
}
#endif
// Set stream format (note that this shader supports compression)
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
#ifndef _X360
// The VS30 shader offsets decals along the normal (for morphed geom)
flags |= g_pHardwareConfig->HasFastVertexTextures() ? VERTEX_NORMAL : 0;
#endif
int pTexCoordDim[3] = { 2, 0, 3 };
int nTexCoordCount = 1;
int userDataSize = 0;
#ifndef _X360
if ( g_pHardwareConfig->HasFastVertexTextures() )
{
nTexCoordCount = 3;
}
#endif
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize );
}
DYNAMIC_STATE
{
if ( pShaderAPI->InFlashlightMode() && ( !IsX360() && ( r_flashlight_version2.GetInt() == 0 ) ) )
{
// Don't draw anything for the flashlight pass
Draw( false );
return;
}
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
// Set an identity base texture transformation
Vector4D transformation[2];
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 );
MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode();
int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
float vEyePos_SpecExponent[4];
pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
vEyePos_SpecExponent[3] = 0.0f;
pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
#ifndef _X360
if ( !g_pHardwareConfig->HasFastVertexTextures() )
#endif
{
DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, 0 ); // Use simplest possible vertex lighting, since ps is so simple
SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, 0 ); //
SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0); //
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, 0 );
SET_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20 );
}
}
#ifndef _X360
else
{
SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 );
DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, 0 ); // Use simplest possible vertex lighting, since ps is so simple
SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, 0 ); //
SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0); //
SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, 0 );
SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() );
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
SET_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 );
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 );
bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() };
pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords );
}
#endif
}
Draw( );
}
END_SHADER

View File

@@ -0,0 +1,110 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "common_hlsl_cpp_consts.h"
#include "Downsample_ps20.inc"
#include "Downsample_ps20b.inc"
BEGIN_VS_SHADER_FLAGS( Downsample, "Help for Downsample", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
END_SHADER_PARAMS
SHADER_INIT
{
LoadTexture( BASETEXTURE );
}
SHADER_FALLBACK
{
// Requires DX9 + above
if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() )
{
// Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( true );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
// Render targets are pegged as sRGB on OSX GL, so just force these reads and writes
bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
int fmt = VERTEX_POSITION;
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
pShaderShadow->SetVertexShader( "Downsample_vs20", 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( downsample_ps20b );
SET_STATIC_PIXEL_SHADER( downsample_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( downsample_ps20 );
SET_STATIC_PIXEL_SHADER( downsample_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
int width, height;
pShaderAPI->GetBackBufferDimensions( width, height );
float v[4];
float dX = 1.0f / width;
float dY = 1.0f / height;
v[0] = -dX;
v[1] = -dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
v[0] = -dX;
v[1] = dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
v[0] = dX;
v[1] = -dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
v[0] = dX;
v[1] = dY;
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 );
// Setup luminance threshold (all values are scaled down by max luminance)
// v[0] = 1.0f / MAX_HDR_OVERBRIGHT;
v[0] = 0.0f;
pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
pShaderAPI->SetVertexShaderIndex( 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20b );
SET_DYNAMIC_PIXEL_SHADER( downsample_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20 );
SET_DYNAMIC_PIXEL_SHADER( downsample_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,23 @@
ps.1.1
def c0, 0.00f, 0.00f, 0.00f, 0.25f
def c1, 0.30f, 0.59f, 0.11f, 0.00f
tex t0
tex t1
tex t2
tex t3
// r1 = average = ( t0 + t1 + t2 + t3 ) * 0.25
mul r1.rgb, t0, c0.a
mad r1.rgb, t1, c0.a, r1
mad r1.rgb, t2, c0.a, r1
mad r1.rgb, t3, c0.a, r1
// r0.a = avg luminance
dp3 r0, r1, c1
// r0.rgb = color = average*(luminance)
mul r0.rgb, r1, r0.a

View File

@@ -0,0 +1,82 @@
// STATIC: "SRGB_ADAPTER" "0..1" [ps20b] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b] [= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "CSTRIKE" "0..1"
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler TexSampler : register( s0 );
float4 params : register( c0 );
struct PS_INPUT
{
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
#if ( CSTRIKE == 0 )
//---------------------------------------//
// Everything but Counter-Strike: Source //
//---------------------------------------//
float4 Shape( float2 uv )
{
float4 pixel = tex2D( TexSampler, uv );
#if ( SRGB_ADAPTER == 1 )
{
pixel.rgb = LinearToGamma( pixel.rgb );
}
#endif
float lum = dot( pixel.xyz, params.xyz );
pixel.xyz = pow( pixel.xyz, params.w ) * lum;
#if ( SRGB_ADAPTER == 1 )
{
pixel.rgb = GammaToLinear( pixel.rgb );
}
#endif
return pixel;
}
float4 main( PS_INPUT i ) : COLOR
{
float4 s0, s1, s2, s3;
// Sample 4 taps
s0 = Shape( i.coordTap0 );
s1 = Shape( i.coordTap1 );
s2 = Shape( i.coordTap2 );
s3 = Shape( i.coordTap3 );
float4 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f;
return FinalOutput( avgColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
#else
//------------------------//
// Counter-Strike: Source //
//------------------------//
float3 Shape( float3 s )
{
float lum = ( 0.3f * s.x ) + ( 0.59f * s.y ) + ( 0.11f * s.z );
return lum * s;
}
float4 main( PS_INPUT i ) : COLOR
{
float3 s0, s1, s2, s3;
// Sample 4 taps
s0 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap0 ) ) );
s1 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap1 ) ) );
s2 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap2 ) ) );
s3 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap3 ) ) );
float3 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f;
return float4( avgColor, 1.0f );
}
#endif

View File

@@ -0,0 +1,30 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler TexSampler : register( s0 );
struct PS_INPUT
{
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
float4 main( PS_INPUT i ) : COLOR
{
float3 s0, s1, s2, s3;
// Sample 4 taps
s0 = tex2D( TexSampler, i.coordTap0);
s1 = tex2D( TexSampler, i.coordTap1);
s2 = tex2D( TexSampler, i.coordTap2);
s3 = tex2D( TexSampler, i.coordTap3);
float3 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f;
return FinalOutput( float4( avgColor, 1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -0,0 +1,40 @@
//====== Copyright <20> 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3];
return o;
}

View File

@@ -0,0 +1,34 @@
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 coordTap0 : TEXCOORD0;
float2 coordTap1 : TEXCOORD1;
float2 coordTap2 : TEXCOORD2;
float2 coordTap3 : TEXCOORD3;
};
float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 );
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0];
o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1];
o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2];
o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3];
return o;
}

View File

@@ -0,0 +1,227 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "BaseVSShader.h"
#include "screenspaceeffect_vs20.inc"
#include "engine_post_ps20.inc"
#include "engine_post_ps20b.inc"
#include "../materialsystem_global.h"
DEFINE_FALLBACK_SHADER( Engine_Post, Engine_Post_dx9 )
BEGIN_VS_SHADER_FLAGS( Engine_Post_dx9, "Engine post-processing effects (software anti-aliasing, bloom, color-correction", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "Full framebuffer texture" )
SHADER_PARAM( AAENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable software anti-aliasing" )
SHADER_PARAM( AAINTERNAL1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" )
SHADER_PARAM( AAINTERNAL2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" )
SHADER_PARAM( AAINTERNAL3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" )
SHADER_PARAM( BLOOMENABLE, SHADER_PARAM_TYPE_BOOL, "1", "Enable bloom" )
END_SHADER_PARAMS
SHADER_INIT_PARAMS()
{
if( !params[ AAENABLE ]->IsDefined() )
{
params[ AAENABLE ]->SetIntValue( 0 );
}
if( !params[ AAINTERNAL1 ]->IsDefined() )
{
params[ AAINTERNAL1 ]->SetVecValue( 0, 0, 0, 0 );
}
if( !params[ AAINTERNAL2 ]->IsDefined() )
{
params[ AAINTERNAL2 ]->SetVecValue( 0, 0, 0, 0 );
}
if( !params[ AAINTERNAL3 ]->IsDefined() )
{
params[ AAINTERNAL3 ]->SetVecValue( 0, 0, 0, 0 );
}
if( !params[ BLOOMENABLE ]->IsDefined() )
{
params[ BLOOMENABLE ]->SetIntValue( 1 );
}
SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE );
}
SHADER_FALLBACK
{
// This shader should not be *used* unless we're >= DX9 (bloomadd.vmt/screenspace_general_dx8 should be used for DX8)
return 0;
}
SHADER_INIT
{
if ( params[BASETEXTURE]->IsDefined() )
{
LoadTexture( BASETEXTURE );
}
if ( params[FBTEXTURE]->IsDefined() )
{
LoadTexture( FBTEXTURE );
}
}
SHADER_DRAW
{
SHADOW_STATE
{
// This shader uses opaque blending, but needs to match the behaviour of bloom_add/screen_spacegeneral,
// which uses additive blending (and is used when bloom is enabled but col-correction and AA are not).
// BUT!
// Hardware sRGB blending is incorrect (on pre-DX10 cards, sRGB values are added directly).
// SO...
// When doing the bloom addition in the pixel shader, we need to emulate that incorrect
// behaviour - by turning sRGB read OFF for the FB texture and by turning sRGB write OFF
// (which is fine, since the AA process works better on an sRGB framebuffer than a linear
// one; gamma colours more closely match luminance perception. The color-correction process
// has always taken gamma-space values as input anyway).
// On OpenGL OSX, we MUST do sRGB reads from the bloom and full framebuffer textures AND sRGB
// writes on the way out to the framebuffer. Hence, our colors are linear in the shader.
// Given this, we use the LINEAR_INPUTS combo to convert to sRGB for the purposes of color
// correction, since that is how the color correction textures are authored.
bool bLinearInput = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
bool bLinearOutput = IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
bool bForceSRGBReadsAndWrites = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
pShaderShadow->EnableBlending( false );
// The (sRGB) bloom texture is bound to sampler 0
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadsAndWrites );
pShaderShadow->EnableSRGBWrite( bForceSRGBReadsAndWrites );
// The (sRGB) full framebuffer texture is bound to sampler 1:
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, bForceSRGBReadsAndWrites );
// Up to 4 (sRGB) color-correction lookup textures are bound to samplers 2-5:
pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, false );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false );
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false );
int format = VERTEX_POSITION;
int numTexCoords = 1;
int * pTexCoordDimensions = NULL;
int userDataSize = 0;
pShaderShadow->VertexShaderVertexFormat( format, numTexCoords, pTexCoordDimensions, userDataSize );
DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts
{
DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20b );
SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_INPUT, bLinearInput );
SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_OUTPUT, bLinearOutput );
SET_STATIC_PIXEL_SHADER( engine_post_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20 );
SET_STATIC_PIXEL_SHADER( engine_post_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
// FIXME: need to set FBTEXTURE to be point-sampled (will speed up this shader significantly on 360)
// and assert that it's set to SHADER_TEXWRAPMODE_CLAMP (since the shader will sample offscreen)
BindTexture( SHADER_SAMPLER1, FBTEXTURE, -1 );
ShaderColorCorrectionInfo_t ccInfo;
pShaderAPI->GetCurrentColorCorrection( &ccInfo );
int colCorrectNumLookups = ccInfo.m_nLookupCount;
for( int i = 0; i < colCorrectNumLookups; i++ )
{
pShaderAPI->BindStandardTexture( (Sampler_t)(SHADER_SAMPLER2 + i), (StandardTextureId_t)(TEXTURE_COLOR_CORRECTION_VOLUME_0 + i) );
}
// Upload 1-pixel X&Y offsets [ (+dX,0,+dY,-dX) is chosen to work with the allowed ps20 swizzles ]
// The shader will sample in a cross (up/down/left/right from the current sample), for 5-tap
// (quality 0) mode and add another 4 samples in a diagonal cross, for 9-tap (quality 1) mode
ITexture * pTarget = params[FBTEXTURE]->GetTextureValue();
int width = pTarget->GetActualWidth();
int height = pTarget->GetActualHeight();
float dX = 1.0f / width;
float dY = 1.0f / height;
float offsets[4] = { +dX, 0, +dY, -dX };
pShaderAPI->SetPixelShaderConstant( 0, &offsets[0], 1 );
// Upload AA tweakables:
// x - strength (this can be used to toggle the AA off, or to weaken it where pathological cases are showing)
// y - reduction of 1-pixel-line blurring (blurring of 1-pixel lines causes issues, so it's tunable)
// z - edge threshold multiplier (default 1.0, < 1.0 => more edges softened, > 1.0 => fewer edges softened)
// w - tap offset multiplier (default 1.0, < 1.0 => sharper image, > 1.0 => blurrier image)
float tweakables[4] = { params[ AAINTERNAL1 ]->GetVecValue()[0],
params[ AAINTERNAL1 ]->GetVecValue()[1],
params[ AAINTERNAL3 ]->GetVecValue()[0],
params[ AAINTERNAL3 ]->GetVecValue()[1] };
pShaderAPI->SetPixelShaderConstant( 1, &tweakables[0], 1 );
// Upload AA UV transform (converts bloom texture UVs to framebuffer texture UVs)
// NOTE: we swap the order of the z and w components since 'wz' is an allowed ps20 swizzle, but 'zw' is not:
float uvTrans[4] = { params[ AAINTERNAL2 ]->GetVecValue()[0],
params[ AAINTERNAL2 ]->GetVecValue()[1],
params[ AAINTERNAL2 ]->GetVecValue()[3],
params[ AAINTERNAL2 ]->GetVecValue()[2] };
pShaderAPI->SetPixelShaderConstant( 2, &uvTrans[0], 1 );
// Upload color-correction weights:
pShaderAPI->SetPixelShaderConstant( 3, &ccInfo.m_flDefaultWeight );
pShaderAPI->SetPixelShaderConstant( 4, ccInfo.m_pLookupWeights );
int aaEnabled = ( params[ AAINTERNAL1 ]->GetVecValue()[0] == 0.0f ) ? 0 : 1;
int aaReduceOnePixelLineBlur = ( params[ AAINTERNAL1 ]->GetVecValue()[1] == 0.0f ) ? 0 : 1;
int aaQualityMode = (int)params[ AAINTERNAL1 ]->GetVecValue()[2];
// int aaDebugMode = (int)params[ AAINTERNAL1 ]->GetVecValue()[3];
int bloomEnabled = ( params[ BLOOMENABLE ]->GetIntValue() == 0 ) ? 0 : 1;
int colCorrectEnabled = ccInfo.m_bIsEnabled;
float flBloomFactor = bloomEnabled ? 1.0f : 0.0f;
float bloomConstant[4] = { flBloomFactor, flBloomFactor, flBloomFactor, flBloomFactor };
pShaderAPI->SetPixelShaderConstant( 5, bloomConstant );
if ( !colCorrectEnabled )
{
colCorrectNumLookups = 0;
}
if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts
{
DECLARE_DYNAMIC_PIXEL_SHADER( engine_post_ps20b );
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_ENABLE, aaEnabled );
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_QUALITY_MODE, aaQualityMode );
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_REDUCE_ONE_PIXEL_LINE_BLUR, aaReduceOnePixelLineBlur );
// SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_DEBUG_MODE, aaDebugMode );
SET_DYNAMIC_PIXEL_SHADER_COMBO( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups );
SET_DYNAMIC_PIXEL_SHADER( engine_post_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( engine_post_ps20 );
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_ENABLE, aaEnabled );
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_QUALITY_MODE, 0 ); // Only enough instruction slots in ps2b
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_REDUCE_ONE_PIXEL_LINE_BLUR, 0 );
// SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_DEBUG_MODE, aaDebugMode );
SET_DYNAMIC_PIXEL_SHADER_COMBO( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups );
SET_DYNAMIC_PIXEL_SHADER( engine_post_ps20 );
}
DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,433 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "LINEAR_INPUT" "0..1" [ps20b]
// STATIC: "LINEAR_OUTPUT" "0..1" [ps20b]
// DYNAMIC: "AA_ENABLE" "0..1"
// rem DYNAMIC: "AA_DEBUG_MODE" "0..3"
#define AA_DEBUG_MODE 0
// DYNAMIC: "AA_QUALITY_MODE" "0..0" [ps20]
// DYNAMIC: "AA_QUALITY_MODE" "0..1" [ps20b]
// DYNAMIC: "AA_QUALITY_MODE" "0..1" [ps30]
// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..0" [ps20]
// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..1" [ps20b]
// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..1" [ps30]
// DYNAMIC: "COL_CORRECT_NUM_LOOKUPS" "0..4"
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
#if !(defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))
// Only allow debug modes and high-quality mode if in ps2b or higher (not enough instruction slots in ps20)
#undef AA_DEBUG_MODE
#define AA_DEBUG_MODE 0
#endif
/*
* Engine_Post combines bloom (the final simple addition) with software anti-aliasing
* and colour-correction. Combining them has these benefits:
* (a) saves fillrate+bandwidth (big on PC)
* (b) saves calls to UpdateScreenEffectTexture (big on 360)
* (c) reduces quantization errors caused by multiple passes
* (d) improves AA quality (it works better on sRGB values than linear)
*
*
* Software AA Summary
* -------------------
*
* This AA process works by sampling neighbour pixels (4 or 8 of them):
*
* 5-tap filter: # 9-tap filter: ###
* (AA_QUALITY_MODE 0) ### (AA_QUALITY_MODE 1) ###
* # ###
*
* It then figures out which of these neighbours are 'unlike' the centre pixel.
* This is based on RGB distance, weighted by the maximum luminance of the samples
* (so the difference between 0.1 and 0.2 is the same as between 0.5 and 1.0).
* This detects high-contrast edges in both dark and bright scenes.
*
* It then counts how many 'unlike' samples there are. Some example cases for 5-tap:
*
* O # # # # #
* OOO OOO #OO OOO #O# #O#
* O O O # O #
* Zero One TwoA TwoB Three Four
*
* We then blend towards the average of the unlike neighbours, based on how many
* unlike neighbours there are. The key case is 'TwoA' - this detects stairstep pixels
* on non-axis-aligned edges. In that case, we blend the output colour towards the
* average of the unlike samples by 33%. This yields a 3-pixel transition (0->33->66->100)
* where before there was a 1-pixel transition (0->100).
*
* The 9-tap filter (which works the same as 5-tap, just with more samples and different
* weights) has two advantages over the 5-tap filter:
* - it can differentiate between stairsteps on 45-degree edges and near-horizontal edges
* (so the 5-tap version smudges 45-degree edges more than you want, e.g. chain-link fences)
* - it blurs less texture detail, by virtue of averaging out noise over more samples
*
* One problem case that both filters have to consider is one-pixel-thick lines (this is
* case 'TwoB' above). Sometimes you do want to soften these lines (for slivers of brightly-lit
* geometry in a dark area, e.g. a window frame), but sometimes you do NOT want to soften them
* (for thin geometry which is alternating between 1-pixel and 2-pixel thickness, e.g. cables,
* and also where 1-pixel lines appear in textures, e.g. roof tiles). So, blurring of 1-pixel
* lines is tunable (it defaults to half-blurred as a compromise between the want/don't cases),
* in the 'AA_REDUCE_ONE_PIXEL_LINE_BLUR' section below. Case TwoB is differentiated from TwoA by
* computing the centroid of the unlike samples (the centroid will be at zero for case TwoB,
* but not for TwoA).
*
*/
sampler BaseTextureSampler : register( s0 );
sampler FBTextureSampler : register( s1 );
sampler ColorCorrectionVolumeTexture0 : register( s2 );
sampler ColorCorrectionVolumeTexture1 : register( s3 );
sampler ColorCorrectionVolumeTexture2 : register( s4 );
sampler ColorCorrectionVolumeTexture3 : register( s5 );
float4 psTapOffs_Packed : register( c0 ); // psTapOffs_packed contains 1-pixel offsets: ( +dX, 0, +dY, -dX )
float4 tweakables : register( c1 ); // (x - AA strength/unused) (y - reduction of 1-pixel-line blur)
// (z - edge threshold multipler) (w - tap offset multiplier)
float4 uvTransform : register( c2 ); // Transform BaseTexture UVs for use with the FBTexture
float ColorCorrectionDefaultWeight : register( c3 );
float4 ColorCorrectionVolumeWeights : register( c4 );
float BloomFactor : register( c5 );
float4 GetBloomColor( float2 bloomUV )
{
#if ( LINEAR_INPUT == 1 )
{
// In this case, which is only used on OpenGL, we want sRGB data from this tex2D.
// Hence, we have to undo the sRGB conversion that we are forced to apply by OpenGL
return LinearToGamma( tex2D( BaseTextureSampler, bloomUV ) );
}
#else
{
return tex2D( BaseTextureSampler, bloomUV );
}
#endif
}
float4 PerformColorCorrection( float4 outColor, float2 fbTexCoord )
{
#if ( COL_CORRECT_NUM_LOOKUPS > 0 )
{
// NOTE: This code requires the color correction texture to be 32 units to be correct.
// This code will cause (0,0,0) to be read from 0.5f/32
// and (1,1,1) to be read from 31.5f/32
float4 offsetOutColor = outColor*(31.0f/32.0f) + (0.5f/32.0f);
outColor.rgb = outColor.rgb * ColorCorrectionDefaultWeight;
outColor.rgb += tex3D( ColorCorrectionVolumeTexture0, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.x;
#if ( COL_CORRECT_NUM_LOOKUPS > 1 )
{
outColor.rgb += tex3D( ColorCorrectionVolumeTexture1, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.y;
#if ( COL_CORRECT_NUM_LOOKUPS > 2 )
{
outColor.rgb += tex3D( ColorCorrectionVolumeTexture2, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.z;
#if ( COL_CORRECT_NUM_LOOKUPS > 3 )
{
outColor.rgb += tex3D( ColorCorrectionVolumeTexture3, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.w;
}
#endif
}
#endif
}
#endif
}
#endif
return outColor;
}
float3 PerformAA( float3 baseColor, float2 fbTexCoord, out float3 unlike, out float unlikeSum, out float lerpFactor )
{
float3 a, b, c, d, e, f, g, h;
float3 dA, dB, dC, dD, dE, dF, dG, dH;
float4 deltas, deltas2;
float4 weights, weights2;
float4 lumS;
float maxLumS;
// Set FAST_DELTAS to '1' to use Manhattan distance (in colour-space) rather than Euclidean distance:
const int FAST_DELTAS = 1;
#if AA_QUALITY_MODE == 0
const float COLOUR_DELTA_BASE = (FAST_DELTAS == 0) ? 0.11f : 0.5f;
const float COLOUR_DELTA_CONTRAST = 100;
// Scaling down colour deltas (DELTA_SCALE) reduces the over-blurring of 45-degree edges
// by the 5-tap filter. Conversely, increasing it smooths stairsteps more strongly.
const float DELTA_SCALE = 0.75f;
#else // AA_QUALITY_MODE == 0
const float COLOUR_DELTA_BASE = (FAST_DELTAS == 0) ? 0.24f : 0.65f;
const float COLOUR_DELTA_CONTRAST = 100;
const float DELTA_SCALE = 1.0f;
#endif // AA_QUALITY_MODE == 0
const float MAX_LERP_FACTOR = 0.66f;
const float SQRT3 = 1.73205080757f;
float onePixelLineBlurReduction = tweakables.y;
// psTapOffs_packed contains 1-pixel offsets: ( +dX, 0, +dY, -dX )
float4 texelDelta = psTapOffs_Packed*tweakables.w;
// Allowed ps20 swizzles:
// .xyzw on (+dX,0,+dY,-dX) gives: (+dX, 0) & (-dX, 0) (former with 'add', latter with 'sub')
// .yzxw on (+dX,0,+dY,-dX) gives: ( 0,+dY) & ( 0,-dY)
// .wzyx on (+dX,0,+dY,-dX) gives: (-dX,+dY) & (+dX,-dY)
// .zxyw on (not used)
// NOTE: These don't give us (+dX,+dY) and (-dX,-dY), we need to copy +dY: ( +dX, 0, +dY, -dX ) -> ( +dX, +dY, +dY, -dX )
// NOTE: tex2D() can't swizzle the source register in ps2x, so we have no
// choice but to add each float2 offset to fbTexCoord one at a time :o/
a = tex2D( FBTextureSampler, fbTexCoord + texelDelta.yz ).rgb; // ( 0,+1)
b = tex2D( FBTextureSampler, fbTexCoord + texelDelta.xy ).rgb; // (+1, 0)
c = tex2D( FBTextureSampler, fbTexCoord - texelDelta.yz ).rgb; // ( 0,-1)
d = tex2D( FBTextureSampler, fbTexCoord - texelDelta.xy ).rgb; // (-1, 0)
#if AA_QUALITY_MODE == 1
// 9-tap method (do diagonal neighbours too)
e = tex2D( FBTextureSampler, fbTexCoord + texelDelta.wz ).rgb; // (-1,+1)
f = tex2D( FBTextureSampler, fbTexCoord - texelDelta.wz ).rgb; // (+1,-1)
texelDelta.y = texelDelta.z; // Can't quite get all 8 sample offsets from a single float4 with the allowed swizzles! :o/
g = tex2D( FBTextureSampler, fbTexCoord + texelDelta.xy ).rgb; // (+1,+1)
h = tex2D( FBTextureSampler, fbTexCoord - texelDelta.xy ).rgb; // (-1,-1)
#endif // AA_QUALITY_MODE == 1
// Compute the like<-->unlike weights
dA = a - baseColor;
dB = b - baseColor;
dC = c - baseColor;
dD = d - baseColor;
#if AA_QUALITY_MODE == 1
dE = e - baseColor;
dF = f - baseColor;
dG = g - baseColor;
dH = h - baseColor;
#endif // AA_QUALITY_MODE == 1
#if ( FAST_DELTAS == 0 )
{
// Colour-space Euclidean distance
deltas = float4( dot(dA, dA), dot(dB, dB), dot(dC, dC), dot(dD, dD) );
deltas = DELTA_SCALE*DELTA_SCALE*(deltas / 3);
deltas = sqrt(deltas);
}
#else
{
// Colour-space Manhattan distance
// OPT: to avoid the 'abs', try dividing colours by maxLumS then dotprodding w/ baseColor
deltas.x = dot( abs( dA ), 1 );
deltas.y = dot( abs( dB ), 1 );
deltas.z = dot( abs( dC ), 1 );
deltas.w = dot( abs( dD ), 1 );
deltas *= DELTA_SCALE;
}
#endif
weights = deltas;
#if AA_QUALITY_MODE == 1
#if ( FAST_DELTAS == 0 )
{
deltas2 = float4( dot(dE, dE), dot(dF, dF), dot(dG, dG), dot(dH, dH) );
deltas2 = DELTA_SCALE*DELTA_SCALE*(deltas2 / 3);
deltas2 = sqrt(deltas2);
}
#else
{
deltas2.x = dot( abs( dE ), 1);
deltas2.y = dot( abs( dF ), 1);
deltas2.z = dot( abs( dG ), 1);
deltas2.w = dot( abs( dH ), 1);
deltas2 *= DELTA_SCALE;
}
#endif
weights2 = deltas2;
#endif // AA_QUALITY_MODE == 1
// Adjust weights relative to maximum sample luminance (local, relative contrast: 0.1 Vs 0.2 is the same as 0.5 Vs 1.0)
lumS = float4( dot(a, a), dot(b, b), dot(c, c), dot(d, d) );
lumS.xy = max( lumS.xy, lumS.wz );
lumS.x = max( lumS.x, lumS.y );
maxLumS = max( lumS.x, dot( baseColor, baseColor ) );
#if AA_QUALITY_MODE == 1
lumS = float4( dot(e, e), dot(f, f), dot(g, g), dot(h, h) );
lumS.xy = max( lumS.xy, lumS.wz );
lumS.x = max( lumS.x, lumS.y );
maxLumS = max( lumS.x, maxLumS );
#endif // AA_QUALITY_MODE == 1
float lumScale = 1.0f / sqrt( maxLumS );
weights *= lumScale;
#if AA_QUALITY_MODE == 1
weights2 *= lumScale;
#endif // AA_QUALITY_MODE == 1
// Contrast-adjust weights such that only large contrast differences are taken into account
// (pushes weights to 0.0 for 'like' neighbours and to 1.0 for 'unlike' neighbours)
float colourDeltaBase = tweakables.z*COLOUR_DELTA_BASE;
weights = saturate(colourDeltaBase + COLOUR_DELTA_CONTRAST*(weights - colourDeltaBase));
#if AA_QUALITY_MODE == 1
weights2 = saturate(colourDeltaBase + COLOUR_DELTA_CONTRAST*(weights2 - colourDeltaBase));
#endif // AA_QUALITY_MODE == 1
// Determine the average 'unlike' colour
unlikeSum = dot(weights, 1);
unlike = weights.x*a + weights.y*b + weights.z*c + weights.w*d;
#if AA_QUALITY_MODE == 1
unlikeSum += dot(weights2, 1);
unlike += weights2.x*e + weights2.y*f + weights2.z*g + weights2.w*h;
#endif // AA_QUALITY_MODE == 1
// NOTE: this can cause div-by-zero, but lerpFactor ends up at zero in that case so it doesn't matter
unlike = unlike / unlikeSum;
#if AA_REDUCE_ONE_PIXEL_LINE_BLUR
// Reduce lerpFactor for 1-pixel-thick lines - otherwise you lose texture detail, and it looks
// really weird where geometry (e.g. cables) alternates between being 1 and 2 pixels thick.
// [ The "*2" below is because the values here were tuned to reduce blurring one 1-pixel lines
// by about half (which is a good compromise between the bad cases at either end). So you
// want the controlling convar to default to 0.5 ]
const float ONE_PIXEL_LINE_BIAS_BASE = 0.4f;
const float ONE_PIXEL_LINE_BIAS_CONTRAST = 16.0f;
float2 unlikeCentroid = 0;
unlikeCentroid.x += dot( 1-weights, float4( 0, +1, 0, -1 ) ); // This 2x4 matrix is the transpose of
unlikeCentroid.y += dot( 1-weights, float4( +1, 0, -1, 0 ) ); // the neighbour sample texel offsets
#if AA_QUALITY_MODE == 0
unlikeCentroid /= 4 - unlikeSum;
#else // AA_QUALITY_MODE == 0
unlikeCentroid.x += dot( 1-weights2, float4( -1, +1, +1, -1 ) );
unlikeCentroid.y += dot( 1-weights2, float4( +1, -1, +1, -1 ) );
unlikeCentroid /= 8 - unlikeSum;
#endif // AA_QUALITY_MODE == 0
float onePixelLineBias = 1 - saturate( length(unlikeCentroid) ); // OPTIMIZE: try using distSquared, remove this sqrt
onePixelLineBias = onePixelLineBlurReduction*saturate(ONE_PIXEL_LINE_BIAS_BASE + ONE_PIXEL_LINE_BIAS_CONTRAST*(onePixelLineBias - ONE_PIXEL_LINE_BIAS_BASE));
#if AA_QUALITY_MODE == 0
unlikeSum -= 2*onePixelLineBias*0.4f*saturate( 3 - unlikeSum ); // The 'min' thing avoids this affecting lone/pair pixels
#else // AA_QUALITY_MODE == 0
unlikeSum -= 2*onePixelLineBias*1.9f*saturate( 7 - unlikeSum );
#endif // AA_QUALITY_MODE == 0
#endif // AA_REDUCE_ONE_PIXEL_LINE_BLUR
// Compute the lerp factor we use to blend between 'baseColor' and 'unlike'.
// We want to lerp 'stairstep' pixels (which have 2 unlike neighbours)
// 33% towards the 'unlike' colour, such that these hard, 1-pixel transitions
// (0% -> 100%) become soft, 3-pixel transitions (0% -> 33% -> 66% -> 100%).
float strengthMultiplier = tweakables.x;
#if ( AA_QUALITY_MODE == 0 )
{
lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( (unlikeSum - 1) / 3 ) );
// Uncomment the following to blend slightly across vertical/horizontal edges (better for 45-degree edges, worse for 90-degree edges)
//lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( unlikeSum / 6 ) );
}
#else // AA_QUALITY_MODE != 0
{
lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( (unlikeSum - 3) / 3 ) );
}
#endif
// Clamp the blend factor so that lone dot pixels aren't blurred into oblivion
lerpFactor = min( lerpFactor, MAX_LERP_FACTOR );
baseColor = lerp( baseColor, unlike, lerpFactor );
return baseColor;
}
float4 GenerateAADebugColor( float4 outColor, float3 unlike, float unlikeSum, float lerpFactor )
{
#if ( AA_DEBUG_MODE == 1 )
{
// Debug: Visualize the number of 'unlike' samples
outColor.rgb = 0;
if ( AA_QUALITY_MODE == 0 )
{
if (unlikeSum >= 0.95f) outColor.rgb = float3(1,0,0);
if (unlikeSum >= 1.95f) outColor.rgb = float3(0,1,0);
if (unlikeSum >= 2.95f) outColor.rgb = float3(0,0,1);
}
else
{
if (unlikeSum >= 2.95f) outColor.rgb = float3(1,0,0);
if (unlikeSum >= 3.95f) outColor.rgb = float3(0,1,0);
if (unlikeSum >= 4.95f) outColor.rgb = float3(0,0,1);
}
// Don't sRGB-write
}
#elif ( AA_DEBUG_MODE == 2 )
{
// Debug: Visualize the strength of lerpFactor
outColor.rgb = 0;
outColor.g = lerpFactor;
// Don't sRGB-write
}
#elif ( AA_DEBUG_MODE == 3 )
{
// Debug: Visualize the 'unlike' colour that we blend towards
outColor.rgb = lerp( 0, unlike, saturate(5*lerpFactor) );
// Do sRGB-write (if it's enabled)
outColor = FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
#endif
return outColor;
}
float2 PerformUVTransform( float2 bloomUVs )
{
// NOTE: 'wz' is used since 'zw' is not a valid swizzle for ps20 shaders
return bloomUVs*uvTransform.wz + uvTransform.xy;
}
struct PS_INPUT
{
float2 baseTexCoord : TEXCOORD0;
#if defined( _X360 ) //avoid a shader patch on 360 due to pixel shader inputs being fewer than vertex shader outputs
float2 ZeroTexCoord : TEXCOORD1;
float2 bloomTexCoord : TEXCOORD2;
#endif
};
float4 main( PS_INPUT i ) : COLOR
{
float2 fbTexCoord = PerformUVTransform( i.baseTexCoord );
float3 baseColor = tex2D( FBTextureSampler, fbTexCoord ).rgb;
#if ( LINEAR_INPUT == 1 )
{
// In this case, which is only used on OpenGL, we want sRGB data from this tex2D.
// Hence, we have to undo the sRGB conversion that we are forced to apply by OpenGL
baseColor = LinearToGamma( baseColor );
}
#endif
float4 outColor = float4( baseColor, 1 );
#if ( AA_ENABLE == 1 )
{
float unlikeSum, lerpFactor;
float3 unlike;
outColor.rgb = PerformAA( outColor.rgb, fbTexCoord, unlike, unlikeSum, lerpFactor );
#if ( AA_DEBUG_MODE > 0 )
{
return GenerateAADebugColor( outColor, unlike, unlikeSum, lerpFactor );
}
#endif
}
#endif
float4 bloomColor = BloomFactor * GetBloomColor( i.baseTexCoord );
outColor.rgb += bloomColor.rgb;
outColor = PerformColorCorrection( outColor, fbTexCoord );
outColor = FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
// Go to linear since we're forced to do an sRGB write on OpenGL in ps2b
#if ( LINEAR_OUTPUT == 1 )
{
outColor = GammaToLinear( outColor );
}
#endif
return outColor;
}

View File

@@ -1,16 +1,16 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw the eyes
; t0 - texture
; t1 - iris
; t2 - glint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
lrp r0, t1.a, t1, t0 ; Blend in the iris with the background
mad r0.rgb, r0, v0, t2 + ; Modulate by the illumination, add in the glint
mov r0.a, t0.a
ps.1.1
;------------------------------------------------------------------------------
; Draw the eyes
; t0 - texture
; t1 - iris
; t2 - glint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
lrp r0, t1.a, t1, t0 ; Blend in the iris with the background
mad r0.rgb, r0, v0, t2 + ; Modulate by the illumination, add in the glint
mov r0.a, t0.a

View File

@@ -1,18 +1,18 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw the eyes
; t0 - texture
; t1 - iris
; t2 - glint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
lrp r0, t1.a, t1, t0 ; Blend in the iris with the background
mul_x2 r0, v0, r0 ; Modulate by the illumination with overbright
add r0.rgb, r0, t2 + ; Add in the glint
mov r0.a, t0.a
ps.1.1
;------------------------------------------------------------------------------
; Draw the eyes
; t0 - texture
; t1 - iris
; t2 - glint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
lrp r0, t1.a, t1, t0 ; Blend in the iris with the background
mul_x2 r0, v0, r0 ; Modulate by the illumination with overbright
add r0.rgb, r0, t2 + ; Add in the glint
mov r0.a, t0.a

View File

@@ -1,145 +1,145 @@
//======= Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======
// $SHADER_SPECIFIC_CONST_0 = eyeball origin
// $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5
// $SHADER_SPECIFIC_CONST_2 = iris projection U
// $SHADER_SPECIFIC_CONST_3 = iris projection V
// $SHADER_SPECIFIC_CONST_4 = glint projection U
// $SHADER_SPECIFIC_CONST_5 = glint projection V
//=============================================================================
// STATIC: "INTRO" "0..1"
// STATIC: "HALFLAMBERT" "0..1"
// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20]
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
// DYNAMIC: "DOWATERFOG" "0..1"
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
// DYNAMIC: "STATIC_LIGHT" "0..1"
// DYNAMIC: "MORPHING" "0..1" [vs30]
// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20]
#include "vortwarp_vs20_helper.h"
static const int g_bSkinning = SKINNING ? true : false;
static const int g_FogType = DOWATERFOG;
static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 );
const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 );
const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 );
const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 );
const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 );
const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 );
#if INTRO
const float4 const4 : register( SHADER_SPECIFIC_CONST_6 );
#define g_Time const4.w
#define modelOrigin const4.xyz
#endif
#ifdef SHADER_MODEL_VS_3_0
// NOTE: cMorphTargetTextureDim.xy = target dimensions,
// cMorphTargetTextureDim.z = 4tuples/morph
const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 );
const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 );
sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
#endif
struct VS_INPUT
{
float4 vPos : POSITION; // Position
float4 vBoneWeights : BLENDWEIGHT; // Skin weights
float4 vBoneIndices : BLENDINDICES; // Skin indices
float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates
float3 vPosFlex : POSITION1; // Delta positions for flexing
#ifdef SHADER_MODEL_VS_3_0
float vVertexID : POSITION2;
#endif
};
struct VS_OUTPUT
{
float4 projPos : POSITION; // Projection-space position
#if !defined( _X360 )
float fog : FOG; // Fixed-function fog factor
#endif
float2 baseTC : TEXCOORD0; // Base texture coordinate
float2 irisTC : TEXCOORD1; // Iris texture coordinates
float2 glintTC : TEXCOORD2; // Glint texture coordinates
float3 vColor : TEXCOORD3; // Vertex-lit color
float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o;
bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
bool bStaticLight = STATIC_LIGHT ? true : false;
float4 vPosition = v.vPos;
float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out
#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
ApplyMorph( v.vPosFlex, vPosition.xyz );
#else
ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz );
#endif
// Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!)
float3 worldNormal, worldPos;
SkinPositionAndNormal(
g_bSkinning,
vPosition, dummy,
v.vBoneWeights, v.vBoneIndices,
worldPos, worldNormal );
#if INTRO
WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, dummy, dummy, dummy );
#endif
// Transform into projection space
float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = vProjPos;
vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
#if !defined( _X360 )
// Set fixed-function fog factor
o.fog = CalcFog( worldPos, vProjPos, g_FogType );
#endif
// Normal = (Pos - Eye origin) - just step on dummy normal created above
worldNormal = worldPos - cEyeOrigin;
// Normal -= 0.5f * (Normal dot Eye Up) * Eye Up
float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f;
worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal);
// Vertex lighting
#if ( USE_STATIC_CONTROL_FLOW || defined ( SHADER_MODEL_VS_3_0 ) )
o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert );
#else
o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
#endif
// Texture 0 is the base texture
// Texture 1 is a planar projection used for the iris
// Texture 2 is a planar projection used for the glint
o.baseTC = v.vTexCoord0;
o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) );
o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) );
o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) );
o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) );
return o;
}
//======= Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======
// $SHADER_SPECIFIC_CONST_0 = eyeball origin
// $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5
// $SHADER_SPECIFIC_CONST_2 = iris projection U
// $SHADER_SPECIFIC_CONST_3 = iris projection V
// $SHADER_SPECIFIC_CONST_4 = glint projection U
// $SHADER_SPECIFIC_CONST_5 = glint projection V
//=============================================================================
// STATIC: "INTRO" "0..1"
// STATIC: "HALFLAMBERT" "0..1"
// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20]
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "SKINNING" "0..1"
// DYNAMIC: "DOWATERFOG" "0..1"
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
// DYNAMIC: "STATIC_LIGHT" "0..1"
// DYNAMIC: "MORPHING" "0..1" [vs30]
// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20]
#include "vortwarp_vs20_helper.h"
static const int g_bSkinning = SKINNING ? true : false;
static const int g_FogType = DOWATERFOG;
static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 );
const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 );
const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 );
const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 );
const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 );
const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 );
#if INTRO
const float4 const4 : register( SHADER_SPECIFIC_CONST_6 );
#define g_Time const4.w
#define modelOrigin const4.xyz
#endif
#ifdef SHADER_MODEL_VS_3_0
// NOTE: cMorphTargetTextureDim.xy = target dimensions,
// cMorphTargetTextureDim.z = 4tuples/morph
const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 );
const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 );
sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
#endif
struct VS_INPUT
{
float4 vPos : POSITION; // Position
float4 vBoneWeights : BLENDWEIGHT; // Skin weights
float4 vBoneIndices : BLENDINDICES; // Skin indices
float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates
float3 vPosFlex : POSITION1; // Delta positions for flexing
#ifdef SHADER_MODEL_VS_3_0
float vVertexID : POSITION2;
#endif
};
struct VS_OUTPUT
{
float4 projPos : POSITION; // Projection-space position
#if !defined( _X360 )
float fog : FOG; // Fixed-function fog factor
#endif
float2 baseTC : TEXCOORD0; // Base texture coordinate
float2 irisTC : TEXCOORD1; // Iris texture coordinates
float2 glintTC : TEXCOORD2; // Glint texture coordinates
float3 vColor : TEXCOORD3; // Vertex-lit color
float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o;
bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
bool bStaticLight = STATIC_LIGHT ? true : false;
float4 vPosition = v.vPos;
float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out
#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
ApplyMorph( v.vPosFlex, vPosition.xyz );
#else
ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz );
#endif
// Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!)
float3 worldNormal, worldPos;
SkinPositionAndNormal(
g_bSkinning,
vPosition, dummy,
v.vBoneWeights, v.vBoneIndices,
worldPos, worldNormal );
#if INTRO
WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, dummy, dummy, dummy );
#endif
// Transform into projection space
float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = vProjPos;
vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
#if !defined( _X360 )
// Set fixed-function fog factor
o.fog = CalcFog( worldPos, vProjPos, g_FogType );
#endif
// Normal = (Pos - Eye origin) - just step on dummy normal created above
worldNormal = worldPos - cEyeOrigin;
// Normal -= 0.5f * (Normal dot Eye Up) * Eye Up
float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f;
worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal);
// Vertex lighting
#if ( USE_STATIC_CONTROL_FLOW || defined ( SHADER_MODEL_VS_3_0 ) )
o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert );
#else
o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
#endif
// Texture 0 is the base texture
// Texture 1 is a planar projection used for the iris
// Texture 2 is a planar projection used for the glint
o.baseTC = v.vTexCoord0;
o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) );
o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) );
o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) );
o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) );
return o;
}

View File

@@ -0,0 +1,83 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "BaseVSShader.h"
#include "common_hlsl_cpp_consts.h"
#include "HDRCombineTo16Bit_ps20.inc"
#include "HDRCombineTo16Bit_ps20b.inc"
#include "HDRCombineTo16Bit_vs20.inc"
#include "convar.h"
BEGIN_VS_SHADER_FLAGS( HDRCombineTo16Bit, "Help for HDRCombineTo16Bit", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SOURCEMRTRENDERTARGET, SHADER_PARAM_TYPE_TEXTURE, "", "" )
END_SHADER_PARAMS
SHADER_INIT
{
LoadTexture( SOURCEMRTRENDERTARGET );
}
SHADER_FALLBACK
{
// Requires DX9 + above
if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
{
Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( false );
pShaderShadow->EnableDepthTest( false );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
int fmt = VERTEX_POSITION;
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
DECLARE_STATIC_VERTEX_SHADER( hdrcombineto16bit_vs20 );
SET_STATIC_VERTEX_SHADER( hdrcombineto16bit_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20b );
SET_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20 );
SET_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, SOURCEMRTRENDERTARGET, -1 );
DECLARE_DYNAMIC_VERTEX_SHADER( hdrcombineto16bit_vs20 );
SET_DYNAMIC_VERTEX_SHADER( hdrcombineto16bit_vs20 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20b );
SET_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20 );
SET_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,25 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler LowSampler : register( s0 );
sampler HiSampler : register( s1 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
float4 main( PS_INPUT i ) : COLOR
{
float4 lowColor = tex2D( LowSampler, i.texCoord );
float3 hiColor = tex2D( HiSampler, i.texCoord );
lowColor.rgb = GammaToLinear( lowColor.rgb );
hiColor.rgb = GammaToLinear( hiColor.rgb );
float4 result = float4( ( 1.0f / MAX_HDR_OVERBRIGHT ) * max( lowColor.xyz, hiColor.xyz * MAX_HDR_OVERBRIGHT ), lowColor.a );
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}

View File

@@ -0,0 +1,24 @@
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 texCoord : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.texCoord = v.vBaseTexCoord;
return o;
}

View File

@@ -0,0 +1,82 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "BaseVSShader.h"
#include "common_hlsl_cpp_consts.h"
#include "HDRSelectRange_ps20.inc"
#include "HDRSelectRange_ps20b.inc"
BEGIN_VS_SHADER_FLAGS( HDRSelectRange, "Help for HDRSelectRange", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( SOURCEMRTRENDERTARGET, SHADER_PARAM_TYPE_TEXTURE, "", "" )
END_SHADER_PARAMS
SHADER_INIT
{
LoadTexture( SOURCEMRTRENDERTARGET );
}
SHADER_FALLBACK
{
// Requires DX9 + above
if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
{
Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableAlphaWrites( false );
pShaderShadow->EnableDepthTest( false );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
int fmt = VERTEX_POSITION;
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
pShaderShadow->SetVertexShader( "HDRSelectRange_vs20", 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_STATIC_PIXEL_SHADER( hdrselectrange_ps20b );
SET_STATIC_PIXEL_SHADER( hdrselectrange_ps20b );
}
else
{
DECLARE_STATIC_PIXEL_SHADER( hdrselectrange_ps20 );
SET_STATIC_PIXEL_SHADER( hdrselectrange_ps20 );
}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, SOURCEMRTRENDERTARGET, -1 );
pShaderAPI->SetVertexShaderIndex( 0 );
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
{
DECLARE_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20b );
SET_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20b );
}
else
{
DECLARE_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20 );
SET_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20 );
}
}
Draw();
}
END_SHADER

View File

@@ -0,0 +1,45 @@
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
sampler LowSampler : register( s0 );
sampler HiSampler : register( s1 );
struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
struct MYHDR_PS_OUTPUT
{
float4 color[2] : COLOR0;
};
MYHDR_PS_OUTPUT main( PS_INPUT i ) : COLOR
{
float3 lowColor = GammaToLinear( tex2D( LowSampler, i.texCoord ) );
float3 hiColor = GammaToLinear( tex2D( HiSampler, i.texCoord ) );
float4 lowOut;
lowOut.a = 1.0f;
float4 hiOut;
hiOut.a = 1.0f;
float3 hdrColor = max( lowColor, hiColor * MAX_HDR_OVERBRIGHT );
float fMax = max( hdrColor.b, max( hdrColor.r, hdrColor.g ) );
float blendFactor = saturate( ( fMax - 0.9f ) * 10.0f );
blendFactor = 1.0f;
lowOut.rgb = LinearToGamma( lowColor * ( 1.0f - blendFactor ) );
hiOut.rgb = LinearToGamma( hiColor * ( blendFactor ) );
MYHDR_PS_OUTPUT output;
output.color[0] = lowOut;
output.color[1] = hiOut;
return output;
}

View File

@@ -0,0 +1,24 @@
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vBaseTexCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
float2 texCoord : TEXCOORD0;
};
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
o.projPos = float4( v.vPos, 1.0f );
o.texCoord = v.vBaseTexCoord;
return o;
}

View File

@@ -0,0 +1,111 @@
// DYNAMIC: "MODE" "0..9"
#include "common_ps_fxc.h"
const float g_Alpha : register( c0 );
sampler BaseTextureSampler : register( s0 );
sampler BaseTextureSampler2 : register( s1 );
struct PS_INPUT
{
float2 baseTexCoord : TEXCOORD0;
float2 baseTexCoord2 : TEXCOORD1;
};
HALF Grey( HALF3 input )
{
return dot( ( float3 )( 1.0f / 3.0f ), input );
}
HALF4 main( PS_INPUT i ) : COLOR
{
float3 scene = tex2D( BaseTextureSampler, i.baseTexCoord );
float3 gman = tex2D( BaseTextureSampler2, i.baseTexCoord2 );
#if MODE == 0
// negative greyscale of scene * gman
float scale = 1.0f / 3.0f;
scene.xyz = dot( float3( scale, scale, scale), scene.xyz );
scene = 1.0f - scene;
return float4( scene * gman, g_Alpha );
#endif
#if MODE == 1
if( Grey( gman ) < 0.3 )
{
return float4( 1.0f - gman, g_Alpha );
}
else
{
return float4( ( 1.0f - gman ) * scene, g_Alpha );
}
#endif
#if MODE == 2
return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
#endif
#if MODE == 3
return float4( lerp( scene, Grey( gman ), Grey( gman ) ), g_Alpha );
#endif
#if MODE == 4
return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
#endif
#if MODE == 5
float sceneLum = scene.r;
if( sceneLum > 0.0f )
{
return float4( scene, g_Alpha );
}
else
{
return float4( gman, g_Alpha );
}
#endif
#if MODE == 6
return float4( scene + gman, g_Alpha );
#endif
#if MODE == 7
return float4( scene, g_Alpha );
#endif
#if MODE == 8
return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
#endif
#if MODE == 9
/*
float3 cGammaLayer1 = scene;
float3 cGammaLayer2 = gman;
float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
float3 cGammaOverlayResult;
if ( flLayer1Brightness < 0.5f )
{
cGammaOverlayResult.rgb = ( 2.0f * cGammaLayer1.rgb * cGammaLayer2.rgb );
}
else
{
cGammaOverlayResult.rgb = ( 1.0f - ( 2.0f * ( 1.0f - cGammaLayer1.rgb ) * ( 1.0f - cGammaLayer2.rgb ) ) );
}
//*/
float3 cLayer1 = scene;
float3 cLayer2 = gman;
float flLayer1Brightness = saturate( dot( cLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
// Modify layer 1 to be more contrasty.
cLayer1.rgb = saturate( cLayer1.rgb * cLayer1.rgb * 2.0f );
float3 cGammaOverlayResult = cLayer1.rgb + cLayer2.rgb * saturate( 1.0f - flLayer1Brightness * 2.0f );
return float4( cGammaOverlayResult.rgb, g_Alpha );
#endif
}

View File

@@ -0,0 +1,159 @@
; DYNAMIC: "MODE" "0..8"
ps.1.1
//HALF Grey( HALF3 input )
//{
// return dot( ( float3 )( 1.0f / 3.0f ), input );
//}
#if MODE == 0
// negative greyscale of scene * gman
// float scale = 1.0f / 3.0f;
// scene.xyz = dot( float3( scale, scale, scale), scene.xyz );
// scene = 1.0f - scene;
// return float4( scene * gman, g_Alpha );
def c1, 0.333333343, 0.333333343, 0.333333343, 1
def c2, 1, 0, 0, 0
tex t0
tex t1
dp3 r0, c1, t0
add r0.w, -r0.w, c1.w
mul r0.xyz, t1, r0.w
dp3 r1, c2, c0
mov r0.w, r1.w
#endif
#if MODE == 1
//if( Grey( gman ) < 0.3 )
// return float4( 1.0f - gman, g_Alpha );
//else
// return float4( ( 1.0f - gman ) * scene, g_Alpha );
def c1, 0.333333343, 0.333333343, 0.333333343, 0.300000012
def c2, 1, 1, 1, 1
def c3, 1, 0, 0, 0.5
tex t0
tex t1
dp3 r1, c1, t1
add t0.w, r1.w, -c1.w
+ add r1.xyz, -t1, c2
dp3 t1, c3, c0
mov t1.w, t1.w
+ mul t1.xyz, t0, r1
dp3 t2, c3, c0
mov r1.w, t2.w
mad r0.w, t0.w, -c2.w, c3.w
cnd r0, r0.w, r1, t1
#endif
#if MODE == 2
// return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
def c1, 1, 0, 0, 1
def c2, 0, 0, 0, 1
tex t0
tex t1
dp3 r0, c1, c0
mul r0.w, r0.w, -c1.w
add r0.w, r0.w, c2.w
add r1.w, -r0.w, c2.w
+ mul r0.xyz, t0, r0.w
mad r0.xyz, t1, r1.w, r0
dp3 r1, c1, c0
mov r0.w, r1.w
#endif
#if MODE == 3
// return float4( lerp( scene, Grey( gman ), Grey( gman ) ), g_Alpha );
def c1, 0.333333343, 0.333333343, 0.333333343, 1
def c2, 1, 0, 0, 0
tex t0
tex t1
dp3 r0, c1, t1
add r1.w, -r0.w, c1.w
mul r1.xyz, t0, r1.w
mad r0.xyz, r0, r0, r1
dp3 r1, c2, c0
mov r0.w, r1.w
#endif
#if MODE == 4
// return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
def c1, 1, 0, 0, 1
def c2, 0, 0, 0, 1
tex t0
tex t1
dp3 r0, c1, c0
mul r0.w, r0.w, -c1.w
add r0.w, r0.w, c2.w
add r1.w, -r0.w, c2.w
+ mul r0.xyz, t0, r0.w
mad r0.xyz, t1, r1.w, r0
dp3 r1, c1, c0
mov r0.w, r1.w
#endif
#if MODE == 5
//float sceneLum = scene.r;
//if( sceneLum > 0.0f )
// return float4( scene, g_Alpha );
//else
// return float4( gman, g_Alpha );
def c1, 1, 0, 0, 1
def c2, 0, 0, 0, 0.45
tex t0 ; gman (sceneLum)
tex t1 ; scene
dp3 r1, c1, c0
mov t1.w, r1.w ; t1.w = alpha
dp3 r1, c1, c0
mov t0.w, r1.w ; t0.w = alpha
dp3 r1, c1, t0 ; r1.w = gman.r
add r0, r1.w, c2.w
cnd r0, r0.w, t0, t1
#endif
#if MODE == 6
// return float4( scene + gman, g_Alpha );
def c1, 1, 0, 0, 0
tex t0
tex t1
add r0.xyz, t0, t1
dp3 r1, c1, c0
mov r0.w, r1.w
#endif
#if MODE == 7
// return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
def c1, 1, 0, 0, 1
def c2, 0, 0, 0, 1
tex t0
tex t1
dp3 r0, c1, c0
mul r0.w, r0.w, -c1.w
add r0.w, r0.w, c2.w
add r1.w, -r0.w, c2.w
+ mul r0.xyz, t0, r0.w
mad r0.xyz, t1, r1.w, r0
dp3 r1, c1, c0
mov r0.w, r1.w
#endif
#if MODE == 8
// return float4( lerp( scene, gman, g_Alpha ), g_Alpha );
def c1, 1, 0, 0, 1
def c2, 0, 0, 0, 1
tex t0
tex t1
dp3 r0, c1, c0
mul r0.w, r0.w, -c1.w
add r0.w, r0.w, c2.w
add r1.w, -r0.w, c2.w
+ mul r0.xyz, t0, r0.w
mad r0.xyz, t1, r1.w, r0
dp3 r1, c1, c0
mov r0.w, r1.w
#endif

View File

@@ -0,0 +1,339 @@
// DYNAMIC: "MODE" "0..9"
// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
// STATIC: "LINEAR_TO_SRGB" "0..1" [ps20b]
#define HDRTYPE HDR_TYPE_NONE
#include "common_ps_fxc.h"
const float g_Alpha : register( c0 );
sampler BaseTextureSampler : register( s0 );
sampler BaseTextureSampler2 : register( s1 );
struct PS_INPUT
{
float2 baseTexCoord : TEXCOORD0;
};
float3 RGBtoHSV( in float3 rgb )
{
float3 hsv;
float fmin, fmax, delta;
fmin = min( min( rgb.r, rgb.g ), rgb.b );
fmax = max( max( rgb.r, rgb.g) , rgb.b );
hsv.b = fmax; // v
delta = fmax - fmin;
if( delta != 0 )
{
hsv.g = delta / fmax; // s
if( rgb.r == fmax )
hsv.r = ( rgb.g - rgb.b ) / delta; // between yellow & magenta
else if( rgb.g == fmax )
hsv.r = 2 + ( rgb.b - rgb.r ) / delta; // between cyan & yellow
else
hsv.r = 4 + ( rgb.r - rgb.g ) / delta; // between magenta & cyan
hsv.r *= 60; // degrees
if( hsv.r < 0 )
hsv.r += 360;
}
else
{
// r = g = b = 0 // s = 0, v is undefined
hsv.g = 0;
hsv.r = -1;
}
return hsv;
}
float3 HSVtoRGB( in float3 hsv )
{
int i;
float3 rgb;
float h = hsv.r;
float s = hsv.g;
float v = hsv.b;
float f, p, q, t;
if( s == 0 )
{
// achromatic (grey)
rgb.rgb = v;
}
else
{
h /= 60; // sector 0 to 5
i = floor( h );
f = h - i; // factorial part of h
p = v * ( 1 - s );
q = v * ( 1 - s * f );
t = v * ( 1 - s * ( 1 - f ) );
if( h < 1)
{
rgb.r = v;
rgb.g = t;
rgb.b = p;
}
else if( h >= 1 && h < 2 )
{
rgb.r = q;
rgb.g = v;
rgb.b = p;
}
else if( h >= 2 && h < 3 )
{
rgb.r = p;
rgb.g = v;
rgb.b = t;
}
else if( h >= 3 && h < 4 )
{
rgb.r = p;
rgb.g = q;
rgb.b = v;
}
else if( h >= 4 && h < 5 )
{
rgb.r = t;
rgb.g = p;
rgb.b = v;
}
else // if ( h >= 5 )
{
rgb.r = v;
rgb.g = p;
rgb.b = q;
}
}
return rgb;
}
// We have to run through this input converter on OpenGL if the
// rest of the shader code is expecting sRGB values
float3 SampleTexture( sampler texSampler, float2 tc )
{
float3 c = tex2D( texSampler, tc ).xyz;
#if ( LINEAR_TO_SRGB )
{
c = LinearToGamma( c );
}
#endif
return c;
}
// We have to run through this output converter on OpenGL if we
// expect to be writing out sRGB values (since sRGB will be forced on)
float3 OutputColor( float3 result )
{
#if ( LINEAR_TO_SRGB )
{
return GammaToLinear( result );
}
#endif
return result;
}
float4 main( PS_INPUT i ) : COLOR
{
float3 result;
#if MODE == 0
// negative greyscale of scene * gman
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float scale = 1.0f / 3.0f;
scene.xyz = dot( float3( scale, scale, scale), scene.xyz );
scene = float3( 1, 1, 1 ) - scene;
return FinalOutput( float4( OutputColor( scene * gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 1
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float scale = 1.0f / 3.0f;
scene.xyz = dot( float3( scale, scale, scale ), scene.xyz );
float gmanLum = dot( float3( scale, scale, scale ), gman );
if( gmanLum < 0.3 )
{
result = OutputColor( float3( 1, 1, 1 ) - gman );
return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
else
{
result = OutputColor( ( float3( 1, 1, 1 ) - gman ) * scene );
return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
#endif
#if MODE == 2
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float startRamp = .2;
float endRamp = .5;
float scale = 1.0f / 3.0f;
float gmanLum = dot( float3( scale, scale, scale ), gman );
float sceneLum = dot( float3( scale, scale, scale ), scene );
float blend = ( gmanLum - startRamp ) * ( 1.0f / ( endRamp - startRamp ) );
blend = saturate( blend );
// return gmanLum * ( 1.0f - blend ) + scene * blend;
result = OutputColor( min( gmanLum.xxx, scene ) );
return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 3
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float scale = 1.0f / 3.0f;
float gmanLum = dot( float3( scale, scale, scale ), gman );
float sceneLum = dot( float3( scale, scale, scale ), scene );
float a = 0.0f;
float b = 0.4f;
float c = 0.7f;
float d = 1.0f;
float blend;
if( gmanLum < b )
{
blend = ( gmanLum - a ) / ( b - a );
}
else if( gmanLum > c )
{
blend = 1.0f - ( ( gmanLum - c) / ( d - c ) );
}
else
{
blend = 1.0f;
}
blend = saturate( blend );
result = OutputColor( gmanLum.xxx * ( float3( 1, 1, 1 ) - blend.xxx ) + scene * blend.xxx );
return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 4
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float scale = 1.0f / 3.0f;
float gmanLum = dot( float3( scale, scale, scale ), gman );
float sceneLum = dot( float3( scale, scale, scale ), scene );
float a = 0.0f;
float b = 0.4f;
float c = 0.7f;
float d = 1.0f;
float blend;
if( gmanLum < b )
{
blend = ( gmanLum - a ) / ( b - a );
}
else if( gmanLum > c )
{
blend = 1.0f - ( ( gmanLum - c) / ( d - c ) );
}
else
{
blend = 1.0f;
}
blend = saturate( blend );
result = OutputColor( gman * ( float3( 1, 1, 1 ) - blend.xxx ) + scene * blend.xxx );
return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 5
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
float scale = 1.0f / 3.0f;
// float sceneLum = dot( float3( scale, scale, scale ), scene );
float sceneLum = scene.r;
if( sceneLum > 0.0f )
{
return FinalOutput( float4( OutputColor( scene ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
else
{
float3 hsv = RGBtoHSV( gman );
// float blend = saturate( hsv.b - .5 );
float blend = hsv.b - .5;
hsv.b *= 1.0f + blend;
hsv.g *= 1.0f - blend;
return FinalOutput( float4( OutputColor( HSVtoRGB( hsv ) ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}
#endif
#if MODE == 6
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
return FinalOutput( float4( OutputColor( scene + gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 7
float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord );
return FinalOutput( float4( OutputColor( scene ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 8
float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord );
return FinalOutput( float4( OutputColor( gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
#if MODE == 9
// Fetch textures
float3 cLayer1 = SampleTexture( BaseTextureSampler, i.baseTexCoord.xy );
float3 cLayer2 = SampleTexture( BaseTextureSampler2, i.baseTexCoord.xy );
/*
// Put colors roughly back into gamma space
float3 cGammaLayer1 = pow( cLayer1, 0.454545f );
float3 cGammaLayer2 = pow( cLayer2, 0.454545f );
// Brightness
//float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.3f, 0.59f, 0.11f ) ) );
//float flLayer2Brightness = saturate( dot( cGammaLayer2.rgb, float3( 0.3f, 0.59f, 0.11f ) ) );
float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
float flLayer2Brightness = saturate( dot( cGammaLayer2.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
// Blend layers in rough gamma space
float3 cGammaOverlayResult;
if ( flLayer1Brightness < 0.5f )
{
cGammaOverlayResult.rgb = ( 2.0f * cGammaLayer1.rgb * cGammaLayer2.rgb );
}
else
{
cGammaOverlayResult.rgb = ( 1.0f - ( 2.0f * ( 1.0f - cGammaLayer1.rgb ) * ( 1.0f - cGammaLayer2.rgb ) ) );
}
// Convert back to linear space
float3 cLinearOverlayResult = pow( cGammaOverlayResult.rgb, 2.2f );
//*/
float flLayer1Brightness = saturate( dot( cLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
float flLayer2Brightness = saturate( dot( cLayer2.rgb, float3( 0.333f, 0.334f, 0.333f ) ) );
// Modify layer 1 to be more contrasty
cLayer1.rgb = saturate( cLayer1.rgb * cLayer1.rgb * 2.0f );
float3 cLinearOverlayResult = cLayer1.rgb + cLayer2.rgb * saturate( 1.0f - flLayer1Brightness * 2.0f );
// Tonemap, fog, etc.
return FinalOutput( float4( OutputColor( cLinearOverlayResult.rgb ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
#endif
}

View File

@@ -0,0 +1,17 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
; Get the color from the texture
tex t0
tex t1
add r0, t0, t1
;mov r0, t1

View File

@@ -0,0 +1,82 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
# DYNAMIC: "SKINNING" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
$cView0 = $SHADER_SPECIFIC_CONST_0;
$cView1 = $SHADER_SPECIFIC_CONST_1;
$cView2 = $SHADER_SPECIFIC_CONST_2;
&AllocateRegister( \$worldPos );
&AllocateRegister( \$worldNormal );
&SkinPositionAndNormal( $worldPos, $worldNormal );
;------------------------------------------------------------------------------
; Transform the position from world to view space
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $worldPos, $cViewProj0
dp4 $projPos.y, $worldPos, $cViewProj1
dp4 $projPos.z, $worldPos, $cViewProj2
dp4 $projPos.w, $worldPos, $cViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
&AllocateRegister( \$viewNormal );
; Transform the normal from object to view space
dp3 $viewNormal.x, $worldNormal, $cView0
dp3 $viewNormal.y, $worldNormal, $cView1
dp3 $viewNormal.z, $worldNormal, $cView2
&FreeRegister( \$worldNormal );
; normalize normal (do we need to do this?)
&Normalize( $viewNormal );
&AllocateRegister( \$viewPos );
; Transform position from object to view space
dp4 $viewPos.x, $worldPos, $cView0
dp4 $viewPos.y, $worldPos, $cView1
dp4 $viewPos.z, $worldPos, $cView2
&FreeRegister( \$worldPos );
&AllocateRegister( \$vertToEye );
; vector from point to eye in view space
mov $vertToEye.xyz, -$viewPos
&FreeRegister( \$viewPos );
; normalize
&Normalize( $vertToEye );
dp3 $viewNormal.x, $vertToEye, $viewNormal
add $viewNormal.x, $viewNormal.x, $SHADER_SPECIFIC_CONST_5 ; FIXME
&FreeRegister( \$vertToEye );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
mov oT0, $viewNormal
mov oT1, $vTexCoord0
&FreeRegister( \$viewNormal );

View File

@@ -0,0 +1,40 @@
vs.1.1
# STATIC: "HALF_LAMBERT" "0..1"
# DYNAMIC: "DOWATERFOG" "0..1"
# DYNAMIC: "LIGHT_COMBO" "0..21"
# DYNAMIC: "SKINNING" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
&AllocateRegister( \$worldNormal );
&SkinPositionAndNormal( $worldPos, $worldNormal );
;------------------------------------------------------------------------------
; Transform the position from model to proj
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $worldPos, $cViewProj0
dp4 $projPos.y, $worldPos, $cViewProj1
dp4 $projPos.z, $worldPos, $cViewProj2
dp4 $projPos.w, $worldPos, $cViewProj3
mov oPos, $projPos
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
&DoLighting( $worldPos, $worldNormal );
&FreeRegister( \$worldPos );
&FreeRegister( \$worldNormal );

View File

@@ -1,15 +1,15 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,17 +1,17 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
tex t3 ; envmap mask
mul r0.rgb, t2, 1-t3.a
mul r0.rgb, c2, r0 ; apply the envmaptint
+ mul r0.a, c2.a, v0.a
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
tex t3 ; envmap mask
mul r0.rgb, t2, 1-t3.a
mul r0.rgb, c2, r0 ; apply the envmaptint
+ mul r0.a, c2.a, v0.a

View File

@@ -1,17 +1,17 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
tex t3 ; envmap mask
mul r0.rgb, t2, t3
mul r0.rgb, c2, r0
+ mul r0.a, c2.a, v0.a
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
tex t3 ; envmap mask
mul r0.rgb, t2, t3
mul r0.rgb, c2, r0
+ mul r0.a, c2.a, v0.a

View File

@@ -1,15 +1,15 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
mul r0.rgb, t2, c2
+ mul r0.a, v0.a, c2.a
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c2 - envmaptint
;------------------------------------------------------------------------------
tex t2 ; cube map
mul r0.rgb, t2, c2
+ mul r0.a, v0.a, c2.a

View File

@@ -1,22 +1,22 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
tex t3
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, t2, 1-t3.a ; envmap * envmapmask (alpha)
mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
tex t3
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, t2, 1-t3.a ; envmap * envmapmask (alpha)
mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only)

View File

@@ -1,14 +1,14 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
; Get the color from the texture
tex t0
mul r0, t0, c0
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
; Get the color from the texture
tex t0
mul r0, t0, c0

View File

@@ -1,38 +1,38 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1

View File

@@ -1,43 +1,43 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
mov oT2, $vTexCoord1
; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh.
mov oD0, $vColor
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
mov oT2, $vTexCoord1
; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh.
mov oD0, $vColor

View File

@@ -1,66 +1,66 @@
; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
ps.1.1
;------------------------------------------------------------------------------
; Environment mapping on a bumped surface
; t0 - Normalmap
; t3 - Cube environment map (*must* be a cube map!)
;
; c0 - color to multiply the results by
; c1 - envmap contrast
; c2 - envmap saturation
; c3 - grey weights
; c4 - fresnel amount
; Input texture coords required here are a little wonky.
; tc0.uv <- U,V into the normal map
; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform
; from tangent space->env map space
; tc1.q, tc2.q, tc3.q <- eye vector in env map space
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Perform matrix multiply to get a local normal bump. Then
; reflect the eye vector through the normal and sample from
; a cubic environment map.
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
; FIXME FIXME - Need to do specialized versions of this with and without:
; - constant color
; - fresnel amount of exactly 0 or 1 or in between
; - envmap contrast of 0, 1, or in between
; - envmap saturation of 0, 1, or in between
; r0 = constant color * result of bump into envmap
mul r0.rgb, t3, c0
; dot eye-vector with per-pixel normal from t0
dp3_sat r1, v0_bx2, t0_bx2
; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel
mul r1.rgb, r0, r0 ; color squared
+mul r0.a, 1-r1.a, 1-r1.a ; squared
lrp r0.rgb, c1, r1, r0 ; blend between color and color * color
+mul r0.a, r0.a, r0.a ; quartic
dp3 r1.rgb, r0, c3 ; color greyscaled
+mul r0.a, r0.a, 1-r1.a ; quintic
; FIXME - these should be able to pair (I think), but don't on nvidia for some reason.
; (I think) cannot pair due to use of >2 constants in single stage
lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale
mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration
mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc
#if NORMALMAPALPHAENVMAPMASK
+mul r0.a, c0.a, t0.a ; Fade amount * alpha from the texture
#else
+mov r0.a, c0.a ; Just use the fade amount
#endif
; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
ps.1.1
;------------------------------------------------------------------------------
; Environment mapping on a bumped surface
; t0 - Normalmap
; t3 - Cube environment map (*must* be a cube map!)
;
; c0 - color to multiply the results by
; c1 - envmap contrast
; c2 - envmap saturation
; c3 - grey weights
; c4 - fresnel amount
; Input texture coords required here are a little wonky.
; tc0.uv <- U,V into the normal map
; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform
; from tangent space->env map space
; tc1.q, tc2.q, tc3.q <- eye vector in env map space
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Perform matrix multiply to get a local normal bump. Then
; reflect the eye vector through the normal and sample from
; a cubic environment map.
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
; FIXME FIXME - Need to do specialized versions of this with and without:
; - constant color
; - fresnel amount of exactly 0 or 1 or in between
; - envmap contrast of 0, 1, or in between
; - envmap saturation of 0, 1, or in between
; r0 = constant color * result of bump into envmap
mul r0.rgb, t3, c0
; dot eye-vector with per-pixel normal from t0
dp3_sat r1, v0_bx2, t0_bx2
; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel
mul r1.rgb, r0, r0 ; color squared
+mul r0.a, 1-r1.a, 1-r1.a ; squared
lrp r0.rgb, c1, r1, r0 ; blend between color and color * color
+mul r0.a, r0.a, r0.a ; quartic
dp3 r1.rgb, r0, c3 ; color greyscaled
+mul r0.a, r0.a, 1-r1.a ; quintic
; FIXME - these should be able to pair (I think), but don't on nvidia for some reason.
; (I think) cannot pair due to use of >2 constants in single stage
lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale
mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration
mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc
#if NORMALMAPALPHAENVMAPMASK
+mul r0.a, c0.a, t0.a ; Fade amount * alpha from the texture
#else
+mov r0.a, c0.a ; Just use the fade amount
#endif

View File

@@ -1,96 +1,96 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; Shader specific constant:
; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0]
;------------------------------------------------------------------------------
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
; Transform position from object to world
dp4 $worldPos.x, $vPos, $cModel0
dp4 $worldPos.y, $vPos, $cModel1
dp4 $worldPos.z, $vPos, $cModel2
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
; Transform tangent space basis vectors to env map space (world space)
; This will produce a set of vectors mapping from tangent space to env space
; We'll use this to transform normals from the normal map from tangent space
; to environment map space.
; NOTE: use dp3 here since the basis vectors are vectors, not points
dp3 oT1.x, $vTangentS, $cModel0
dp3 oT2.x, $vTangentS, $cModel1
dp3 oT3.x, $vTangentS, $cModel2
dp3 oT1.y, $vTangentT, $cModel0
dp3 oT2.y, $vTangentT, $cModel1
dp3 oT3.y, $vTangentT, $cModel2
dp3 oT1.z, $vNormal, $cModel0
dp3 oT2.z, $vNormal, $cModel1
dp3 oT3.z, $vNormal, $cModel2
; Compute the vector from vertex to camera
&AllocateRegister( \$worldEyeVect );
sub $worldEyeVect.xyz, $cEyePos, $worldPos
&FreeRegister( \$worldPos );
; Move it into the w component of the texture coords, as the wacky
; pixel shader wants it there.
mov oT1.w, $worldEyeVect.x
mov oT2.w, $worldEyeVect.y
mov oT3.w, $worldEyeVect.z
alloc $tangentEyeVect
; transform the eye vector to tangent space
dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS
dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT
dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal
&FreeRegister( \$worldEyeVect );
&Normalize( $tangentEyeVect );
; stick the tangent space eye vector into oD0
mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf
&FreeRegister( \$tangentEyeVect );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; Shader specific constant:
; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0]
;------------------------------------------------------------------------------
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
; Transform position from object to world
dp4 $worldPos.x, $vPos, $cModel0
dp4 $worldPos.y, $vPos, $cModel1
dp4 $worldPos.z, $vPos, $cModel2
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
; Transform tangent space basis vectors to env map space (world space)
; This will produce a set of vectors mapping from tangent space to env space
; We'll use this to transform normals from the normal map from tangent space
; to environment map space.
; NOTE: use dp3 here since the basis vectors are vectors, not points
dp3 oT1.x, $vTangentS, $cModel0
dp3 oT2.x, $vTangentS, $cModel1
dp3 oT3.x, $vTangentS, $cModel2
dp3 oT1.y, $vTangentT, $cModel0
dp3 oT2.y, $vTangentT, $cModel1
dp3 oT3.y, $vTangentT, $cModel2
dp3 oT1.z, $vNormal, $cModel0
dp3 oT2.z, $vNormal, $cModel1
dp3 oT3.z, $vNormal, $cModel2
; Compute the vector from vertex to camera
&AllocateRegister( \$worldEyeVect );
sub $worldEyeVect.xyz, $cEyePos, $worldPos
&FreeRegister( \$worldPos );
; Move it into the w component of the texture coords, as the wacky
; pixel shader wants it there.
mov oT1.w, $worldEyeVect.x
mov oT2.w, $worldEyeVect.y
mov oT3.w, $worldEyeVect.z
alloc $tangentEyeVect
; transform the eye vector to tangent space
dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS
dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT
dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal
&FreeRegister( \$worldEyeVect );
&Normalize( $tangentEyeVect );
; stick the tangent space eye vector into oD0
mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf
&FreeRegister( \$tangentEyeVect );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1

View File

@@ -1,72 +1,72 @@
; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
ps.1.4
;------------------------------------------------------------------------------
; Phase 1
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
texld r0, t0
; Get environment matrix
texcrd r1.rgb, t1
texcrd r2.rgb, t2
texcrd r3.rgb, t3
; Normalize eye-ray vector through normalizer cube map
texld r4, t4 ; <---- CUBE MAP here!!!
;mov r0.rgba, r4
; Transform normal
dp3 r5.r, r1, r0_bx2
dp3 r5.g, r2, r0_bx2
dp3 r5.b, r3, r0_bx2
; Reflection calculatiom
dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye)
mul r3.rgb, r5, r3 ; 2N(N.Eye)
dp3 r2.rgb, r5, r5 ; N.N
mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N)
#if NORMALMAPALPHAENVMAPMASK
; Alpha gets lost after phase marker, so store it here
mov r5, r0.a
#endif
;------------------------------------------------------------------------------
; Phase 2
;------------------------------------------------------------------------------
; What's left over from the last phase:
; r0 - normal
; r1 - free
; r2 - vector to sample in envmap
; r3 - free
; r4 - normal
; r5 - normal map alpha (rgba)
phase
; Sample environment map
texld r3, r2
; dot eye-vector with per-pixel normal from r0
dp3_sat r1, v0_bx2, r0_bx2
; Result goes in output color (multiply by constant color c0)
mul r0.rgb, r3, c0
; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel
mul r1.rgb, r0, r0
+mul r0.a, 1-r1.a, 1-r1.a ; squared
lrp r0.rgb, c1, r1, r0 ; blend between color and color * color
+mul r0.a, r0.a, r0.a ; quartic
dp3 r1.rgb, r0, c3
+mul r0.a, r0.a, 1-r1.a ; quintic
lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale
mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration
mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc
#if NORMALMAPALPHAENVMAPMASK
+mul r0.a, c0.a, r5.r ; Fade amount * alpha from the texture
#else
+mov r0.a, c0.a ; Just use the fade amount
#endif
; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
ps.1.4
;------------------------------------------------------------------------------
; Phase 1
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
texld r0, t0
; Get environment matrix
texcrd r1.rgb, t1
texcrd r2.rgb, t2
texcrd r3.rgb, t3
; Normalize eye-ray vector through normalizer cube map
texld r4, t4 ; <---- CUBE MAP here!!!
;mov r0.rgba, r4
; Transform normal
dp3 r5.r, r1, r0_bx2
dp3 r5.g, r2, r0_bx2
dp3 r5.b, r3, r0_bx2
; Reflection calculatiom
dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye)
mul r3.rgb, r5, r3 ; 2N(N.Eye)
dp3 r2.rgb, r5, r5 ; N.N
mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N)
#if NORMALMAPALPHAENVMAPMASK
; Alpha gets lost after phase marker, so store it here
mov r5, r0.a
#endif
;------------------------------------------------------------------------------
; Phase 2
;------------------------------------------------------------------------------
; What's left over from the last phase:
; r0 - normal
; r1 - free
; r2 - vector to sample in envmap
; r3 - free
; r4 - normal
; r5 - normal map alpha (rgba)
phase
; Sample environment map
texld r3, r2
; dot eye-vector with per-pixel normal from r0
dp3_sat r1, v0_bx2, r0_bx2
; Result goes in output color (multiply by constant color c0)
mul r0.rgb, r3, c0
; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel
mul r1.rgb, r0, r0
+mul r0.a, 1-r1.a, 1-r1.a ; squared
lrp r0.rgb, c1, r1, r0 ; blend between color and color * color
+mul r0.a, r0.a, r0.a ; quartic
dp3 r1.rgb, r0, c3
+mul r0.a, r0.a, 1-r1.a ; quintic
lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale
mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration
mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc
#if NORMALMAPALPHAENVMAPMASK
+mul r0.a, c0.a, r5.r ; Fade amount * alpha from the texture
#else
+mov r0.a, c0.a ; Just use the fade amount
#endif

View File

@@ -1,92 +1,92 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; Shader specific constant:
; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0]
;------------------------------------------------------------------------------
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
; Transform position from object to world
dp4 $worldPos.x, $vPos, $cModel0
dp4 $worldPos.y, $vPos, $cModel1
dp4 $worldPos.z, $vPos, $cModel2
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
; Transform tangent space basis vectors to env map space (world space)
; This will produce a set of vectors mapping from tangent space to env space
; We'll use this to transform normals from the normal map from tangent space
; to environment map space.
; NOTE: use dp3 here since the basis vectors are vectors, not points
dp3 oT1.x, $vTangentS, $cModel0
dp3 oT2.x, $vTangentS, $cModel1
dp3 oT3.x, $vTangentS, $cModel2
dp3 oT1.y, $vTangentT, $cModel0
dp3 oT2.y, $vTangentT, $cModel1
dp3 oT3.y, $vTangentT, $cModel2
dp3 oT1.z, $vNormal, $cModel0
dp3 oT2.z, $vNormal, $cModel1
dp3 oT3.z, $vNormal, $cModel2
; Compute the vector from vertex to camera
&AllocateRegister( \$worldEyeVect );
sub $worldEyeVect.xyz, $cEyePos, $worldPos
&FreeRegister( \$worldPos );
; eye vector
mov oT4.xyz, $worldEyeVect
alloc $tangentEyeVect
; transform the eye vector to tangent space
dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS
dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT
dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal
&FreeRegister( \$worldEyeVect );
&Normalize( $tangentEyeVect );
; stick the tangent space eye vector into oD0
mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf
&FreeRegister( \$tangentEyeVect );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
;------------------------------------------------------------------------------
; Shader specific constant:
; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0]
;------------------------------------------------------------------------------
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$worldPos );
; Transform position from object to world
dp4 $worldPos.x, $vPos, $cModel0
dp4 $worldPos.y, $vPos, $cModel1
dp4 $worldPos.z, $vPos, $cModel2
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
&CalcFog( $worldPos, $projPos );
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Lighting
;------------------------------------------------------------------------------
; Transform tangent space basis vectors to env map space (world space)
; This will produce a set of vectors mapping from tangent space to env space
; We'll use this to transform normals from the normal map from tangent space
; to environment map space.
; NOTE: use dp3 here since the basis vectors are vectors, not points
dp3 oT1.x, $vTangentS, $cModel0
dp3 oT2.x, $vTangentS, $cModel1
dp3 oT3.x, $vTangentS, $cModel2
dp3 oT1.y, $vTangentT, $cModel0
dp3 oT2.y, $vTangentT, $cModel1
dp3 oT3.y, $vTangentT, $cModel2
dp3 oT1.z, $vNormal, $cModel0
dp3 oT2.z, $vNormal, $cModel1
dp3 oT3.z, $vNormal, $cModel2
; Compute the vector from vertex to camera
&AllocateRegister( \$worldEyeVect );
sub $worldEyeVect.xyz, $cEyePos, $worldPos
&FreeRegister( \$worldPos );
; eye vector
mov oT4.xyz, $worldEyeVect
alloc $tangentEyeVect
; transform the eye vector to tangent space
dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS
dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT
dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal
&FreeRegister( \$worldEyeVect );
&Normalize( $tangentEyeVect );
; stick the tangent space eye vector into oD0
mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf
&FreeRegister( \$tangentEyeVect );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1

View File

@@ -1,79 +1,79 @@
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) +
; r0 = ( N dot basis[0] )
; don't "_sat" here so that everything adds up to one even if the normal is outside of the basis!!!!!
dp3 r0, t0_bx2, c0
; r1 = ( N dot basis[1] )
dp3 r1, t0_bx2, c1
;----
; r0 = ( N dot basis[0] )
; r1 = ( N dot basis[1] )
;----
; r0.rgb = ( N dot basis[0] )^2
mul r0.rgb, r0, r0
; r1.a = ( N dot basis[1] )^2
+mul r1.a, r1, r1
;----
; r0.rgb = ( N dot basis[0] )^2
; r1.a = ( N dot basis[1] )^2
;----
mul t1, r0, t1
;----
; r1.a = ( N dot basis[1] )^2
; t1 = lightmapColor[0] * ( N dot basis[0] )^2
;----
dp3 r0, t0_bx2, c2
;----
; r1.a = ( N dot basis[1] )^2
; t1 = lightmapColor[0] * ( N dot basis[0] )^2
; r0 = ( N dot basis[2] )
;----
mad t1.rgb, r1.a, t2, t1
+mul r0.a, r0, r0
;----
; t1.rgb = lightmapColor[0] * ( N dot basis[0] )^2 + lightmapColor[1] * ( N dot basis[1] )^2
; r0.a = ( N dot basis[2] )^2
;----
mad r0.rgba, r0.a, t3, t1
;----
; r0.rgb = lightmapColor[0] * ( N dot basis[0] )^2 +
; lightmapColor[1] * ( N dot basis[1] )^2 +
; lightmapColor[2] * ( N dot basis[2] )^2
;----
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) +
; r0 = ( N dot basis[0] )
; don't "_sat" here so that everything adds up to one even if the normal is outside of the basis!!!!!
dp3 r0, t0_bx2, c0
; r1 = ( N dot basis[1] )
dp3 r1, t0_bx2, c1
;----
; r0 = ( N dot basis[0] )
; r1 = ( N dot basis[1] )
;----
; r0.rgb = ( N dot basis[0] )^2
mul r0.rgb, r0, r0
; r1.a = ( N dot basis[1] )^2
+mul r1.a, r1, r1
;----
; r0.rgb = ( N dot basis[0] )^2
; r1.a = ( N dot basis[1] )^2
;----
mul t1, r0, t1
;----
; r1.a = ( N dot basis[1] )^2
; t1 = lightmapColor[0] * ( N dot basis[0] )^2
;----
dp3 r0, t0_bx2, c2
;----
; r1.a = ( N dot basis[1] )^2
; t1 = lightmapColor[0] * ( N dot basis[0] )^2
; r0 = ( N dot basis[2] )
;----
mad t1.rgb, r1.a, t2, t1
+mul r0.a, r0, r0
;----
; t1.rgb = lightmapColor[0] * ( N dot basis[0] )^2 + lightmapColor[1] * ( N dot basis[1] )^2
; r0.a = ( N dot basis[2] )^2
;----
mad r0.rgba, r0.a, t3, t1
;----
; r0.rgb = lightmapColor[0] * ( N dot basis[0] )^2 +
; lightmapColor[1] * ( N dot basis[1] )^2 +
; lightmapColor[2] * ( N dot basis[2] )^2
;----

View File

@@ -1,54 +1,54 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
; make a 3
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
&FreeRegister( \$offset );
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
; make a 3
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
&FreeRegister( \$offset );

View File

@@ -1,39 +1,39 @@
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
; t4 - Base
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
ps.1.4
; Get the 3-vector from the normal map
texld r0, t0
; Sample the lightmaps
texld r1, t1
texld r2, t2
texld r3, t3
; Sample the base texture
texld r4, t4
; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * base
dp3 r5.r, r0_bx2, c0
dp3 r5.g, r0_bx2, c1
dp3 r5.b, r0_bx2, c2
mul r5.rgb, r5, r5
mul r1, r1, r5.r
mad r1, r2, r5.g, r1
mad r1, r3, r5.g, r1
; assume overbright_2 !!!
mul_x2 r0, r1, r4
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
; t4 - Base
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
ps.1.4
; Get the 3-vector from the normal map
texld r0, t0
; Sample the lightmaps
texld r1, t1
texld r2, t2
texld r3, t3
; Sample the base texture
texld r4, t4
; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * base
dp3 r5.r, r0_bx2, c0
dp3 r5.g, r0_bx2, c1
dp3 r5.b, r0_bx2, c2
mul r5.rgb, r5, r5
mul r1, r1, r5.r
mad r1, r2, r5.g, r1
mad r1, r3, r5.g, r1
; assume overbright_2 !!!
mul_x2 r0, r1, r4

View File

@@ -1,55 +1,55 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
&FreeRegister( \$offset );
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
&FreeRegister( \$offset );

View File

@@ -1,47 +1,47 @@
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
; t4 - Base1
; t5 - Base2
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
ps.1.4
; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * lerp(base1, base2, lightmapColor[0].a)
; Get the 3-vector from the normal map
texld r0, t0
dp3 r5.r, r0_bx2, c0
dp3 r5.g, r0_bx2, c1
dp3 r5.b, r0_bx2, c2
mul r5.rgb, r5, r5
phase
; Sample the lightmaps
texld r1, t1
texld r2, t2
texld r3, t3
; Sample the base textures
texld r4, t4
texld r5, t5
mul r1, r1, r5.r
mad r1, r2, r5.g, r1
mad r1, r3, r5.g, r1
; blend base textures
lrp r4, r4, r5, r1.a
; assume overbright_2 !!!
mul_x2 r0, r1, r4
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
; t4 - Base1
; t5 - Base2
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space
;------------------------------------------------------------------------------
ps.1.4
; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * lerp(base1, base2, lightmapColor[0].a)
; Get the 3-vector from the normal map
texld r0, t0
dp3 r5.r, r0_bx2, c0
dp3 r5.g, r0_bx2, c1
dp3 r5.b, r0_bx2, c2
mul r5.rgb, r5, r5
phase
; Sample the lightmaps
texld r1, t1
texld r2, t2
texld r3, t3
; Sample the base textures
texld r4, t4
texld r5, t5
mul r1, r1, r5.r
mad r1, r2, r5.g, r1
mad r1, r3, r5.g, r1
; blend base textures
lrp r4, r4, r5, r1.a
; assume overbright_2 !!!
mul_x2 r0, r1, r4

View File

@@ -1,57 +1,57 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
dp4 oT5.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
dp4 oT5.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
&FreeRegister( \$offset );
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.xy, $vTexCoord2
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
dp4 oT5.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
dp4 oT5.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
&FreeRegister( \$offset );

View File

@@ -1,47 +1,47 @@
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - decal texture
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - ( ( N dot basis[0] )^2 ), ( ( N dot basis[1] )^2 ), ( ( N dot basis[2] )^2 )
;------------------------------------------------------------------------------
; Get the decal color
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) +
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 )
mul r0, t1, c0
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + lightmapColor[1] * ( ( N dot basis[1] )^2 )
mad r0, t2, c1, r0
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 )
mad r0, t3, c2, r0
; Modulate by decal texture
mul r0.rgb, r0, t0
+ mov r0.a, t0.a
; Modulate by constant color
mul r0, r0, c3
; Modulate by per-vertex factor
mul r0, r0, v0
ps.1.1
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - decal texture
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
; c0, c1, c2 - ( ( N dot basis[0] )^2 ), ( ( N dot basis[1] )^2 ), ( ( N dot basis[2] )^2 )
;------------------------------------------------------------------------------
; Get the decal color
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 ) +
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 )
mul r0, t1, c0
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + lightmapColor[1] * ( ( N dot basis[1] )^2 )
mad r0, t2, c1, r0
; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +
; lightmapColor[1] * ( ( N dot basis[1] )^2 ) +
; lightmapColor[2] * ( ( N dot basis[2] )^2 )
mad r0, t3, c2, r0
; Modulate by decal texture
mul r0.rgb, r0, t0
+ mov r0.a, t0.a
; Modulate by constant color
mul r0, r0, c3
; Modulate by per-vertex factor
mul r0, r0, v0

View File

@@ -1,56 +1,56 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.x, $vTexCoord2.x
mov $offset.y, $cZero
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
; make a 3
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
mov oD0, $vColor
&FreeRegister( \$offset );
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; Vertex blending
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
; Compute the texture coordinates given the offset between
; each bumped lightmap
&AllocateRegister( \$offset );
mov $offset.x, $vTexCoord2.x
mov $offset.y, $cZero
dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
add oT1.xy, $offset, $vTexCoord1
mad oT2.xy, $offset, $cTwo, $vTexCoord1
; make a 3
alloc $three
add $three, $cOne, $cTwo
mad oT3.xy, $offset, $three, $vTexCoord1
free $three
mov oD0, $vColor
&FreeRegister( \$offset );

View File

@@ -1,18 +1,18 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r1.rgb, r0, t2 ; detail texture
lrp r0.rgb, c2, r1, r0
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r1.rgb, r0, t2 ; detail texture
lrp r0.rgb, c2, r1, r0
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,16 +1,16 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t1
tex t2
mul r0.rgb, t1, v0 + ; base times vertex color (with alpha)
mov r0.a, v0.a
mul_x2 r0.rgb, r0, t2 ; detail texture
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t1
tex t2
mul r0.rgb, t1, v0 + ; base times vertex color (with alpha)
mov r0.a, v0.a
mul_x2 r0.rgb, r0, t2 ; detail texture
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,23 +1,23 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0.rgb, t0, v0 + ; base times vertex color (no alpha)
mov r0.a, v0.a ; Grab alpha from vertex color
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r1.rgb, r0, t2 ; detail texture
lrp r0.rgb, c2, r1, r0
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, c1, t0 ; Self illum * tint
lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0.rgb, t0, v0 + ; base times vertex color (no alpha)
mov r0.a, v0.a ; Grab alpha from vertex color
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r1.rgb, r0, t2 ; detail texture
lrp r0.rgb, c2, r1, r0
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, c1, t0 ; Self illum * tint
lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap

View File

@@ -1,21 +1,21 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t1
tex t2
mov r0.rgb, v0 + ; vertex color
mul r0.a, v0.a, t2.a ; vertex alpha * envmap alpha
mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t1
tex t2
mov r0.rgb, v0 + ; vertex color
mul r0.a, v0.a, t2.a ; vertex alpha * envmap alpha
mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,20 +1,20 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only)

View File

@@ -1,45 +1,45 @@
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform
; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform
; $SHADER_SPECIFIC_CONST_4 = Modulation color
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
; YUCK! This is to make texcoords continuous for mat_softwaretl
mov oT0, $cZero
; Texture coordinates
mov oT1, $vTexCoord1
mov oD0, $cOne
vs.1.1
# DYNAMIC: "DOWATERFOG" "0..1"
#include "macros.vsh"
;------------------------------------------------------------------------------
; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform
; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform
; $SHADER_SPECIFIC_CONST_4 = Modulation color
;------------------------------------------------------------------------------
&AllocateRegister( \$projPos );
; Transform position from object to projection space
dp4 $projPos.x, $vPos, $cModelViewProj0
dp4 $projPos.y, $vPos, $cModelViewProj1
dp4 $projPos.z, $vPos, $cModelViewProj2
dp4 $projPos.w, $vPos, $cModelViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $DOWATERFOG == 1 )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
&FreeRegister( \$projPos );
; YUCK! This is to make texcoords continuous for mat_softwaretl
mov oT0, $cZero
; Texture coordinates
mov oT1, $vTexCoord1
mov oD0, $cOne

View File

@@ -1,6 +1,6 @@
ps.1.1
tex t1
mov r0.rgba, t1
ps.1.1
tex t1
mov r0.rgba, t1

View File

@@ -1,24 +1,24 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t1
tex t2
tex t3
mov r0.rgb, v0 ; vertex color
mul r1, t2, t3 ; envmap * envmapmask
mad r0.rgb, r1, c2, r0 + ; + envmap * envmapmask * envmaptint (color only)
mul r0.a, v0.a, r1.a ; alpha = vertex alpha * envmap alpha * envmapmask alpha
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t1
tex t2
tex t3
mov r0.rgb, v0 ; vertex color
mul r1, t2, t3 ; envmap * envmapmask
mad r0.rgb, r1, c2, r0 + ; + envmap * envmapmask * envmaptint (color only)
mul r0.a, v0.a, r1.a ; alpha = vertex alpha * envmap alpha * envmapmask alpha
mul r0.rgb, t1, r0 ; fold in lightmap (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,22 +1,22 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
tex t3
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, t2, t3 ; envmap * envmapmask
mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
; c1 - self-illum tint
; c2 - envmap tint
;------------------------------------------------------------------------------
tex t0
tex t1
tex t2
tex t3
mul r0, t0, v0 ; base times vertex color (with alpha)
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, t2, t3 ; envmap * envmapmask
mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only)

View File

@@ -1,20 +1,20 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between grey and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mul_sat r1.a, t0, v0 ; base times vertex alpha
lrp r0, r1.a, r1, c2 ; interpolate between white + color
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between grey and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mul_sat r1.a, t0, v0 ; base times vertex alpha
lrp r0, r1.a, r1, c2 ; interpolate between white + color

View File

@@ -1,20 +1,20 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between grey and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mov_sat r1.a, v0 ; vertex alpha
lrp r0, r1.a, r1, c2 ; interpolate between white + color
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between grey and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mov_sat r1.a, v0 ; vertex alpha
lrp r0, r1.a, r1, c2 ; interpolate between white + color

View File

@@ -1,23 +1,23 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between white and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mov_sat r1.a, v0 ; opacity == vertex opacity (no alpha in texture)
lrp r0.rgb, t0.a, c1, r1 ; Blend between self-illum + lightmap
+ mov r0.a, c2.a
lrp r0.rgb, r1.a, r0, c2 ; interpolate between white + color
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
def c2, 1.0f, 1.0f, 1.0f, 1.0f
tex t0
tex t1
; Blend between white and lightmap color based on total alpha
mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap
+ mov_sat r1.a, v0 ; opacity == vertex opacity (no alpha in texture)
lrp r0.rgb, t0.a, c1, r1 ; Blend between self-illum + lightmap
+ mov r0.a, c2.a
lrp r0.rgb, r1.a, r0, c2 ; interpolate between white + color

View File

@@ -1,14 +1,14 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t1
mul r0.rgb, t1, v0 + ; base times vertex color (with alpha)
mov r0.a, v0.a
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t1
mul r0.rgb, t1, v0 + ; base times vertex color (with alpha)
mov r0.a, v0.a
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)

View File

@@ -1,34 +1,34 @@
ps.1.1
def c0, 1,0,0,0
def c1, 0,1,0,0
def c2, 0,0,1,0
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * n.r + lightmapColor[1] * n.g + lightmapColor[2] * n.b
mov r0, t0
dp3 r1, t0, c0
mul r0.rgb, r1, t1
dp3 r1, t0, c1
mad r0.rgb, r1, t2, r0
dp3 r1, t0, c2
mad r0.rgb, r1, t3, r0
ps.1.1
def c0, 1,0,0,0
def c1, 0,1,0,0
def c2, 0,0,1,0
;------------------------------------------------------------------------------
; Computes the diffuse component of lighting using lightmap + bumpmap
; t0 - Normalmap
; t1 - Lightmap1
; t2 - Lightmap2
; t3 - Lightmap3
;
; The texture coordinates need to be defined as follows:
; tc0 - Normalmap and lightmap texture coordinates
;------------------------------------------------------------------------------
; Get the 3-vector from the normal map
tex t0
; Sample the lightmaps
tex t1
tex t2
tex t3
; output = lightmapColor[0] * n.r + lightmapColor[1] * n.g + lightmapColor[2] * n.b
mov r0, t0
dp3 r1, t0, c0
mul r0.rgb, r1, t1
dp3 r1, t0, c1
mad r0.rgb, r1, t2, r0
dp3 r1, t0, c2
mad r0.rgb, r1, t3, r0

View File

@@ -1,21 +1,21 @@
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
mul r0.rgb, t0, v0 + ; base times vertex color (no alpha)
mov r0.a, v0.a ; Grab alpha from vertex color
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, c1, t0 ; Self illum * tint
lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap
ps.1.1
;------------------------------------------------------------------------------
; Draw a texture . . woo hoo!
; t0 - texture
;
; The texture coordinates need to be defined as follows:
; tc0 - texcoords
;------------------------------------------------------------------------------
tex t0
tex t1
mul r0.rgb, t0, v0 + ; base times vertex color (no alpha)
mov r0.a, v0.a ; Grab alpha from vertex color
mul r0.rgb, t1, r0 ; fold in lighting (color only)
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
mul r1, c1, t0 ; Self illum * tint
lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap

Some files were not shown because too many files have changed in this diff Show More