v14
This commit is contained in:
parent
26ad53d60d
commit
c044ead770
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,22 @@
|
|||
use File::DosGlob;
|
||||
@ARGV = map {
|
||||
my @g = File::DosGlob::glob($_) if /[*?]/;
|
||||
@g ? @g : $_;
|
||||
} @ARGV;
|
||||
|
||||
open FILE, ">__tmpshaderlist.txt";
|
||||
|
||||
foreach $arg (@ARGV)
|
||||
{
|
||||
if( $arg =~ m/\.fxc$/i || $arg =~ m/\.vsh$/i || $arg =~ m/\.psh$/i )
|
||||
{
|
||||
print $arg . "\n";
|
||||
print FILE $arg . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
close FILE;
|
||||
|
||||
system "buildshaders.bat __tmpshaderlist";
|
||||
|
||||
unlink "__tmpshaderlist.txt";
|
|
@ -0,0 +1,116 @@
|
|||
use String::CRC32;
|
||||
BEGIN {use File::Basename; push @INC, dirname($0); }
|
||||
require "valve_perl_helpers.pl";
|
||||
|
||||
sub GetShaderType
|
||||
{
|
||||
my $shadername = shift;
|
||||
my $shadertype;
|
||||
if( $shadername =~ m/\.vsh/i )
|
||||
{
|
||||
$shadertype = "vsh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.psh/i )
|
||||
{
|
||||
$shadertype = "psh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.fxc/i )
|
||||
{
|
||||
$shadertype = "fxc";
|
||||
}
|
||||
else
|
||||
{
|
||||
die;
|
||||
}
|
||||
return $shadertype;
|
||||
}
|
||||
|
||||
sub GetShaderSrc
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/^(.*)-----/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
sub GetShaderType
|
||||
{
|
||||
my $shadername = shift;
|
||||
my $shadertype;
|
||||
if( $shadername =~ m/\.vsh/i )
|
||||
{
|
||||
$shadertype = "vsh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.psh/i )
|
||||
{
|
||||
$shadertype = "psh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.fxc/i )
|
||||
{
|
||||
$shadertype = "fxc";
|
||||
}
|
||||
else
|
||||
{
|
||||
die;
|
||||
}
|
||||
return $shadertype;
|
||||
}
|
||||
|
||||
sub GetShaderBase
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/-----(.*)$/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $shadertype = &GetShaderType( $shadername );
|
||||
$shadername =~ s/\.$shadertype//i;
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
$g_x360 = 0;
|
||||
$g_vcsext = ".vcs";
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
$inputbase = shift;
|
||||
|
||||
if( $inputbase =~ m/-x360/ )
|
||||
{
|
||||
$g_x360 = 1;
|
||||
$g_vcsext = ".360.vcs";
|
||||
}
|
||||
else
|
||||
{
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
# rip the txt off the end if it's there.
|
||||
$inputbase =~ s/\.txt//i;
|
||||
|
||||
my @srcfiles = &LoadShaderListFile( $inputbase );
|
||||
|
||||
foreach $srcfile ( @srcfiles )
|
||||
{
|
||||
my $shadertype = &GetShaderType( $srcfile );
|
||||
my $shaderbase = &GetShaderBase( $srcfile );
|
||||
my $shadersrc = &GetShaderSrc( $srcfile );
|
||||
my $vcsFileName = "..\\..\\..\\game\\platform\\shaders\\$shadertype\\$shaderbase" . $g_vcsext;
|
||||
# print "shadersrc: $shadersrc vcsFileName: $vcsFileName\n";
|
||||
|
||||
if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) )
|
||||
{
|
||||
next; # skip _ps20 files for 360
|
||||
}
|
||||
|
||||
&CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 1 );
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
BEGIN {use File::Basename; push @INC, dirname($0); }
|
||||
require "valve_perl_helpers.pl";
|
||||
use Cwd;
|
||||
use String::CRC32;
|
||||
|
||||
my $txtfilename = shift;
|
||||
my $arg = shift;
|
||||
|
||||
my $is360 = 0;
|
||||
my $platformextension = "";
|
||||
if( $arg =~ m/-x360/i )
|
||||
{
|
||||
$is360 = 1;
|
||||
$platformextension = ".360";
|
||||
}
|
||||
|
||||
open TXTFILE, "<$txtfilename";
|
||||
|
||||
my $src;
|
||||
my $dst;
|
||||
while( $src = <TXTFILE> )
|
||||
{
|
||||
# get rid of comments
|
||||
$src =~ s,//.*,,g;
|
||||
|
||||
# skip blank lines
|
||||
if( $src =~ m/^\s*$/ )
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
# Get rid of newlines.
|
||||
$src =~ s/\n//g;
|
||||
|
||||
# Save off the shader source filename.
|
||||
my $dst = $src;
|
||||
|
||||
$dst =~ s/_tmp//gi;
|
||||
|
||||
# Does the dst exist?
|
||||
my $dstexists = -e $dst;
|
||||
my $srcexists = -e $src;
|
||||
# What are the time stamps for the src and dst?
|
||||
my $srcmodtime = ( stat $src )[9];
|
||||
my $dstmodtime = ( stat $dst )[9];
|
||||
|
||||
if( $dstexists && !$srcexists )
|
||||
{
|
||||
printf STDERR "$src doesn't exist, deleting $dst\n";
|
||||
unlink $dst;
|
||||
}
|
||||
|
||||
# Open for edit or add if different than what is in perforce already.
|
||||
if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
|
||||
{
|
||||
# Make the target writable if it exists
|
||||
if( $dstexists )
|
||||
{
|
||||
MakeFileWritable( $dst );
|
||||
}
|
||||
|
||||
my $dir = $dst;
|
||||
$dir =~ s,([^/\\]*$),,; # rip the filename off the end
|
||||
my $filename = $1;
|
||||
|
||||
# create the target directory if it doesn't exist
|
||||
if( !$dstexists )
|
||||
{
|
||||
&MakeDirHier( $dir, 0777 );
|
||||
}
|
||||
|
||||
# copy the file to its targets. . . we want to see STDERR here if there is an error.
|
||||
my $cmd = "copy $src $dst > nul";
|
||||
# print STDERR "$cmd\n";
|
||||
system $cmd;
|
||||
|
||||
MakeFileReadOnly( $dst );
|
||||
}
|
||||
}
|
||||
|
||||
close TXTFILE;
|
|
@ -0,0 +1,161 @@
|
|||
BEGIN {use File::Basename; push @INC, dirname($0); }
|
||||
require "valve_perl_helpers.pl";
|
||||
use Cwd;
|
||||
use String::CRC32;
|
||||
|
||||
sub ReadInputFileWithIncludes
|
||||
{
|
||||
local( $filename ) = shift;
|
||||
|
||||
local( *INPUT );
|
||||
local( $output );
|
||||
|
||||
open INPUT, "<$filename" || die;
|
||||
|
||||
local( $line );
|
||||
local( $linenum ) = 1;
|
||||
while( $line = <INPUT> )
|
||||
{
|
||||
if( $line =~ m/\#include\s+\"(.*)\"/i )
|
||||
{
|
||||
$output.= ReadInputFileWithIncludes( $1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
close INPUT;
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub PatchCRC
|
||||
{
|
||||
my $filename = shift;
|
||||
my $crc = shift;
|
||||
# print STDERR "PatchCRC( $filename, $crc )\n";
|
||||
local( *FP );
|
||||
open FP, "+<$filename" || die;
|
||||
binmode( FP );
|
||||
seek FP, 6 * 4, 0;
|
||||
my $uInt = "I";
|
||||
if( $filename =~ m/360/ )
|
||||
{
|
||||
$uInt = "N";
|
||||
}
|
||||
print FP pack $uInt, $crc;
|
||||
close FP;
|
||||
}
|
||||
|
||||
my $txtfilename = shift;
|
||||
my $arg = shift;
|
||||
|
||||
my $is360 = 0;
|
||||
my $platformextension = "";
|
||||
if( $arg =~ m/-x360/i )
|
||||
{
|
||||
$is360 = 1;
|
||||
$platformextension = ".360";
|
||||
}
|
||||
|
||||
open TXTFILE, "<$txtfilename";
|
||||
|
||||
my $src;
|
||||
my $dst;
|
||||
while( $src = <TXTFILE> )
|
||||
{
|
||||
# get rid of comments
|
||||
$src =~ s,//.*,,g;
|
||||
|
||||
# skip blank lines
|
||||
if( $src =~ m/^\s*$/ )
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
# Get rid of newlines.
|
||||
$src =~ s/\n//g;
|
||||
|
||||
# Save off the shader source filename.
|
||||
my $shadersrcfilename = $src;
|
||||
$shadersrcfilename =~ s/-----.*$//;
|
||||
# use only target basename.
|
||||
$src =~ s/^.*-----//;
|
||||
|
||||
# where the binary vcs file is
|
||||
my $spath = "";
|
||||
|
||||
if ( $shadersrcfilename =~ m@\.fxc@i )
|
||||
{
|
||||
$spath = "shaders\\fxc\\";
|
||||
}
|
||||
if ( $shadersrcfilename =~ m@\.vsh@i )
|
||||
{
|
||||
$spath = "shaders\\vsh\\";
|
||||
}
|
||||
if ( $shadersrcfilename =~ m@\.psh@i )
|
||||
{
|
||||
$spath = "shaders\\psh\\";
|
||||
}
|
||||
|
||||
# make the source have path and extension
|
||||
$src = $spath . $src . $platformextension . ".vcs";
|
||||
|
||||
# build the dest filename.
|
||||
$dst = $src;
|
||||
|
||||
$dst =~ s/shaders\\/..\\..\\..\\game\\platform\\shaders\\/i;
|
||||
|
||||
# Does the dst exist?
|
||||
my $dstexists = -e $dst;
|
||||
my $srcexists = -e $src;
|
||||
# What are the time stamps for the src and dst?
|
||||
my $srcmodtime = ( stat $src )[9];
|
||||
my $dstmodtime = ( stat $dst )[9];
|
||||
|
||||
# Write $dst to a file so that we can do perforce stuff to it later.
|
||||
local( *VCSLIST );
|
||||
open VCSLIST, ">>vcslist.txt" || die;
|
||||
print VCSLIST $dst . "\n";
|
||||
close VCSLIST;
|
||||
|
||||
# Open for edit or add if different than what is in perforce already.
|
||||
if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
|
||||
{
|
||||
if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i )
|
||||
{
|
||||
# Get the CRC for the source file.
|
||||
my $srccode = ReadInputFileWithIncludes( $shadersrcfilename );
|
||||
my $crc = crc32( $srccode );
|
||||
|
||||
# Patch the source VCS file with the CRC32 of the source code used to build that file.
|
||||
PatchCRC( $src, $crc );
|
||||
}
|
||||
|
||||
# Make the target vcs writable if it exists
|
||||
if( $dstexists )
|
||||
{
|
||||
MakeFileWritable( $dst );
|
||||
}
|
||||
|
||||
my $dir = $dst;
|
||||
$dir =~ s,([^/\\]*$),,; # rip the filename off the end
|
||||
my $filename = $1;
|
||||
|
||||
# create the target directory if it doesn't exist
|
||||
if( !$dstexists )
|
||||
{
|
||||
&MakeDirHier( $dir, 0777 );
|
||||
}
|
||||
|
||||
# copy the file to its targets. . . we want to see STDERR here if there is an error.
|
||||
my $cmd = "copy $src $dst > nul";
|
||||
# print STDERR "$cmd\n";
|
||||
system $cmd;
|
||||
|
||||
MakeFileReadOnly( $dst );
|
||||
}
|
||||
}
|
||||
|
||||
close TXTFILE;
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,110 @@
|
|||
#!perl
|
||||
use File::Find;
|
||||
|
||||
&BuildRemapTable;
|
||||
|
||||
find(\&convert, "." );
|
||||
|
||||
|
||||
sub convert
|
||||
{
|
||||
return unless (/\.pcf$/i);
|
||||
return if (/^tmp\.pcf$/i);
|
||||
return if (/^tmp2\.pcf$/i);
|
||||
return if (/360\.pcf$/i);
|
||||
print STDERR "process ", $File::Find::name," ($_) dir=",`cd`," \n";
|
||||
my $fname=$_;
|
||||
print `p4 edit $fname`;
|
||||
print `dmxconvert -i $_ -o tmp.pcf -oe keyvalues2`;
|
||||
open(TMP, "tmp.pcf" ) || return;
|
||||
open(OUT, ">tmp2.pcf" ) || die;
|
||||
while(<TMP>)
|
||||
{
|
||||
s/[\n\r]//g;
|
||||
if ( (/^(\s*\"functionName\"\s*\"string\"\s*\")(.*)\"(.*)$/) &&
|
||||
length($map{$2}) )
|
||||
{
|
||||
$_=$1.$map{$2}.'"'.$3;
|
||||
}
|
||||
if ( (/^(\s*\"name\"\s*\"string\"\s*\")(.*)\"(.*)$/) &&
|
||||
length($map{$2}) )
|
||||
{
|
||||
$_=$1.$map{$2}.'"'.$3;
|
||||
}
|
||||
print OUT "$_\n";
|
||||
}
|
||||
close OUT;
|
||||
close TMP;
|
||||
print `dmxconvert -i tmp2.pcf -o $fname -ie keyvalues2 -oe binary`;
|
||||
unlink "tmp.pcf";
|
||||
unlink "tmp2.pcf";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub BuildRemapTable
|
||||
{
|
||||
$map{"alpha_fade"}= "Alpha Fade and Decay";
|
||||
$map{"alpha_fade_in_random"}= "Alpha Fade In Random";
|
||||
$map{"alpha_fade_out_random"}= "Alpha Fade Out Random";
|
||||
$map{"basic_movement"}= "Movement Basic";
|
||||
$map{"color_fade"}= "Color Fade";
|
||||
$map{"controlpoint_light"}= "Color Light From Control Point";
|
||||
$map{"Dampen Movement Relative to Control Point"}= "Movement Dampen Relative to Control Point";
|
||||
$map{"Distance Between Control Points Scale"}= "Remap Distance Between Two Control Points to Scalar";
|
||||
$map{"Distance to Control Points Scale"}= "Remap Distance to Control Point to Scalar";
|
||||
$map{"lifespan_decay"}= "Lifespan Decay";
|
||||
$map{"lock to bone"}= "Movement Lock to Bone";
|
||||
$map{"postion_lock_to_controlpoint"}= "Movement Lock to Control Point";
|
||||
$map{"maintain position along path"}= "Movement Maintain Position Along Path";
|
||||
$map{"Match Particle Velocities"}= "Movement Match Particle Velocities";
|
||||
$map{"Max Velocity"}= "Movement Max Velocity";
|
||||
$map{"noise"}= "Noise Scalar";
|
||||
$map{"vector noise"}= "Noise Vector";
|
||||
$map{"oscillate_scalar"}= "Oscillate Scalar";
|
||||
$map{"oscillate_vector"}= "Oscillate Vector";
|
||||
$map{"Orient Rotation to 2D Direction"}= "Rotation Orient to 2D Direction";
|
||||
$map{"radius_scale"}= "Radius Scale";
|
||||
$map{"Random Cull"}= "Cull Random";
|
||||
$map{"remap_scalar"}= "Remap Scalar";
|
||||
$map{"rotation_movement"}= "Rotation Basic";
|
||||
$map{"rotation_spin"}= "Rotation Spin Roll";
|
||||
$map{"rotation_spin yaw"}= "Rotation Spin Yaw";
|
||||
$map{"alpha_random"}= "Alpha Random";
|
||||
$map{"color_random"}= "Color Random";
|
||||
$map{"create from parent particles"}= "Position From Parent Particles";
|
||||
$map{"Create In Hierarchy"}= "Position In CP Hierarchy";
|
||||
$map{"random position along path"}= "Position Along Path Random";
|
||||
$map{"random position on model"}= "Position on Model Random";
|
||||
$map{"sequential position along path"}= "Position Along Path Sequential";
|
||||
$map{"position_offset_random"}= "Position Modify Offset Random";
|
||||
$map{"position_warp_random"}= "Position Modify Warp Random";
|
||||
$map{"position_within_box"}= "Position Within Box Random";
|
||||
$map{"position_within_sphere"}= "Position Within Sphere Random";
|
||||
$map{"Inherit Velocity"}= "Velocity Inherit from Control Point";
|
||||
$map{"Initial Repulsion Velocity"}= "Velocity Repulse from World";
|
||||
$map{"Initial Velocity Noise"}= "Velocity Noise";
|
||||
$map{"Initial Scalar Noise"}= "Remap Noise to Scalar";
|
||||
$map{"Lifespan from distance to world"}= "Lifetime from Time to Impact";
|
||||
$map{"Pre-Age Noise"}= "Lifetime Pre-Age Noise";
|
||||
$map{"lifetime_random"}= "Lifetime Random";
|
||||
$map{"radius_random"}= "Radius Random";
|
||||
$map{"random yaw"}= "Rotation Yaw Random";
|
||||
$map{"Randomly Flip Yaw"}= "Rotation Yaw Flip Random";
|
||||
$map{"rotation_random"}= "Rotation Random";
|
||||
$map{"rotation_speed_random"}= "Rotation Speed Random";
|
||||
$map{"sequence_random"}= "Sequence Random";
|
||||
$map{"second_sequence_random"}= "Sequence Two Random";
|
||||
$map{"trail_length_random"}= "Trail Length Random";
|
||||
$map{"velocity_random"}= "Velocity Random";
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,333 @@
|
|||
use String::CRC32;
|
||||
BEGIN {use File::Basename; push @INC, dirname($0); }
|
||||
require "valve_perl_helpers.pl";
|
||||
|
||||
sub BuildDefineOptions
|
||||
{
|
||||
local( $output );
|
||||
local( $combo ) = shift;
|
||||
local( $i );
|
||||
for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
|
||||
{
|
||||
local( $val ) = ( $combo % ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) ) + $dynamicDefineMin[$i];
|
||||
$output .= "/D$dynamicDefineNames[$i]=$val ";
|
||||
$combo = $combo / ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 );
|
||||
}
|
||||
for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
|
||||
{
|
||||
local( $val ) = ( $combo % ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) ) + $staticDefineMin[$i];
|
||||
$output .= "/D$staticDefineNames[$i]=$val ";
|
||||
$combo = $combo / ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub CalcNumCombos
|
||||
{
|
||||
local( $i, $numCombos );
|
||||
$numCombos = 1;
|
||||
for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
|
||||
{
|
||||
$numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
|
||||
}
|
||||
for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
|
||||
{
|
||||
$numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
|
||||
}
|
||||
return $numCombos;
|
||||
}
|
||||
|
||||
sub CalcNumDynamicCombos
|
||||
{
|
||||
local( $i, $numCombos );
|
||||
$numCombos = 1;
|
||||
for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
|
||||
{
|
||||
$numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
|
||||
}
|
||||
return $numCombos;
|
||||
}
|
||||
|
||||
$g_dx9 = 1;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
$psh_filename = shift;
|
||||
|
||||
if( $psh_filename =~ m/-source/ )
|
||||
{
|
||||
$g_SourceDir = shift;
|
||||
}
|
||||
elsif( $psh_filename =~ m/-x360/ )
|
||||
{
|
||||
$g_x360 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
$psh_filename =~ s/-----.*$//;
|
||||
|
||||
|
||||
# Get the shader binary version number from a header file.
|
||||
open FILE, "<$g_SourceDir\\public\\materialsystem\\shader_vcs_version.h" || die;
|
||||
while( $line = <FILE> )
|
||||
{
|
||||
if( $line =~ m/^\#define\s+SHADER_VCS_VERSION_NUMBER\s+(\d+)\s*$/ )
|
||||
{
|
||||
$shaderVersion = $1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
if( !defined $shaderVersion )
|
||||
{
|
||||
die "couldn't get shader version from shader_vcs_version.h";
|
||||
}
|
||||
close FILE;
|
||||
|
||||
|
||||
|
||||
local( @staticDefineNames );
|
||||
local( @staticDefineMin );
|
||||
local( @staticDefineMax );
|
||||
local( @dynamicDefineNames );
|
||||
local( @dynamicDefineMin );
|
||||
local( @dynamicDefineMax );
|
||||
|
||||
# Parse the combos.
|
||||
open PSH, "<$psh_filename";
|
||||
while( <PSH> )
|
||||
{
|
||||
last if( !m,^;, );
|
||||
s,^;\s*,,;
|
||||
if( m/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
|
||||
{
|
||||
local( $name, $min, $max );
|
||||
$name = $1;
|
||||
$min = $2;
|
||||
$max = $3;
|
||||
# print "\"STATIC: $name\" \"$min..$max\"\n";
|
||||
if (/\[(.*)\]/)
|
||||
{
|
||||
$platforms=$1;
|
||||
next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
|
||||
next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
|
||||
}
|
||||
push @staticDefineNames, $name;
|
||||
push @staticDefineMin, $min;
|
||||
push @staticDefineMax, $max;
|
||||
}
|
||||
elsif( m/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
|
||||
{
|
||||
local( $name, $min, $max );
|
||||
$name = $1;
|
||||
$min = $2;
|
||||
$max = $3;
|
||||
# print "\"DYNAMIC: $name\" \"$min..$max\"\n";
|
||||
if (/\[(.*)\]/)
|
||||
{
|
||||
$platforms=$1;
|
||||
next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
|
||||
next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
|
||||
}
|
||||
push @dynamicDefineNames, $name;
|
||||
push @dynamicDefineMin, $min;
|
||||
push @dynamicDefineMax, $max;
|
||||
}
|
||||
}
|
||||
close PSH;
|
||||
|
||||
$numCombos = &CalcNumCombos();
|
||||
$numDynamicCombos = &CalcNumDynamicCombos();
|
||||
print "$psh_filename\n";
|
||||
#print "$numCombos combos\n";
|
||||
#print "$numDynamicCombos dynamic combos\n";
|
||||
|
||||
if( $g_x360 )
|
||||
{
|
||||
$pshtmp = "pshtmp9_360";
|
||||
}
|
||||
elsif( $g_dx9 )
|
||||
{
|
||||
$pshtmp = "pshtmp9";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pshtmp = "pshtmp8";
|
||||
}
|
||||
$basename = $psh_filename;
|
||||
$basename =~ s/\.psh$//i;
|
||||
|
||||
for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ )
|
||||
{
|
||||
my $tempFilename = "shader$shaderCombo.o";
|
||||
unlink $tempFilename;
|
||||
|
||||
if( $g_x360 )
|
||||
{
|
||||
$cmd = "$g_SourceDir\\x360xdk\\bin\\win32\\psa /D_X360=1 /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL";
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = "$g_SourceDir\\dx9sdk\\utilities\\psa /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL";
|
||||
}
|
||||
|
||||
if( !stat $pshtmp )
|
||||
{
|
||||
mkdir $pshtmp, 0777 || die $!;
|
||||
}
|
||||
|
||||
# print $cmd . "\n";
|
||||
system $cmd || die $!;
|
||||
|
||||
# Make sure a file got generated because sometimes the die above won't happen on compile errors.
|
||||
my $filesize = (stat $tempFilename)[7];
|
||||
if ( !$filesize )
|
||||
{
|
||||
die "Error compiling shader$shaderCombo.o";
|
||||
}
|
||||
|
||||
push @outputHeader, @hdr;
|
||||
}
|
||||
|
||||
$basename =~ s/\.fxc//gi;
|
||||
push @outputHeader, "static PrecompiledShaderByteCode_t " . $basename . "_pixel_shaders[" . $numCombos . "] = \n";
|
||||
push @outputHeader, "{\n";
|
||||
local( $j );
|
||||
for( $j = 0; $j < $numCombos; $j++ )
|
||||
{
|
||||
local( $thing ) = "pixelShader_" . $basename . "_" . $j;
|
||||
push @outputHeader, "\t{ " . "$thing, sizeof( $thing ) },\n";
|
||||
}
|
||||
push @outputHeader, "};\n";
|
||||
|
||||
push @outputHeader, "struct $basename" . "PixelShader_t : public PrecompiledShader_t\n";
|
||||
push @outputHeader, "{\n";
|
||||
push @outputHeader, "\t$basename" . "PixelShader_t()\n";
|
||||
push @outputHeader, "\t{\n";
|
||||
push @outputHeader, "\t\tm_nFlags = 0;\n";
|
||||
push @outputHeader, "\t\tm_pByteCode = " . $basename . "_pixel_shaders;\n";
|
||||
push @outputHeader, "\t\tm_nShaderCount = $numCombos;\n";
|
||||
#push @outputHeader, "\t\tm_nDynamicCombos = m_nShaderCount;\n";
|
||||
push @outputHeader, "\t\t// NOTE!!! psh_prep.pl shaders are always static combos!\n";
|
||||
push @outputHeader, "\t\tm_nDynamicCombos = 1;\n";
|
||||
push @outputHeader, "\t\tm_pName = \"$basename\";\n";
|
||||
if( $basename =~ /vs\d\d/ ) # hack
|
||||
{
|
||||
push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_PIXEL_SHADER, this );\n";
|
||||
}
|
||||
push @outputHeader, "\t}\n";
|
||||
push @outputHeader, "\tvirtual const PrecompiledShaderByteCode_t &GetByteCode( int shaderID )\n";
|
||||
push @outputHeader, "\t{\n";
|
||||
push @outputHeader, "\t\treturn m_pByteCode[shaderID];\n";
|
||||
push @outputHeader, "\t}\n";
|
||||
push @outputHeader, "};\n";
|
||||
|
||||
push @outputHeader, "static $basename" . "PixelShader_t $basename" . "_PixelShaderInstance;\n";
|
||||
|
||||
|
||||
&MakeDirHier( "shaders/psh" );
|
||||
|
||||
my $vcsName = "";
|
||||
if( $g_x360 )
|
||||
{
|
||||
$vcsName = $basename . ".360.vcs";
|
||||
}
|
||||
else
|
||||
{
|
||||
$vcsName = $basename . ".vcs";
|
||||
}
|
||||
|
||||
open COMPILEDSHADER, ">shaders/psh/$vcsName" || die;
|
||||
binmode( COMPILEDSHADER );
|
||||
|
||||
#
|
||||
# Write out the part of the header that we know. . we'll write the rest after writing the object code.
|
||||
#
|
||||
|
||||
#print $numCombos . "\n";
|
||||
|
||||
# Pack arguments
|
||||
my $sInt = "i";
|
||||
my $uInt = "I";
|
||||
if ( $g_x360 )
|
||||
{
|
||||
# Change arguments to "big endian long"
|
||||
$sInt = "N";
|
||||
$uInt = "N";
|
||||
}
|
||||
|
||||
open PSH, "<$psh_filename";
|
||||
my $crc = crc32( *PSH );
|
||||
close PSH;
|
||||
#print STDERR "crc for $psh_filename: $crc\n";
|
||||
|
||||
# version
|
||||
print COMPILEDSHADER pack $sInt, 4;
|
||||
# totalCombos
|
||||
print COMPILEDSHADER pack $sInt, $numCombos;
|
||||
# dynamic combos
|
||||
print COMPILEDSHADER pack $sInt, $numDynamicCombos;
|
||||
# flags
|
||||
print COMPILEDSHADER pack $uInt, 0x0; # nothing here for now.
|
||||
# centroid mask
|
||||
print COMPILEDSHADER pack $uInt, 0;
|
||||
# reference size for diffs
|
||||
print COMPILEDSHADER pack $uInt, 0;
|
||||
# crc32 of the source code
|
||||
print COMPILEDSHADER pack $uInt, $crc;
|
||||
|
||||
my $beginningOfDir = tell COMPILEDSHADER;
|
||||
|
||||
# Write out a blank directionary. . we'll fill it in later.
|
||||
for( $i = 0; $i < $numCombos; $i++ )
|
||||
{
|
||||
# offset from beginning of file.
|
||||
print COMPILEDSHADER pack $sInt, 0;
|
||||
# size
|
||||
print COMPILEDSHADER pack $sInt, 0;
|
||||
}
|
||||
|
||||
my $startByteCode = tell COMPILEDSHADER;
|
||||
my @byteCodeStart;
|
||||
my @byteCodeSize;
|
||||
|
||||
# Write out the shader object code.
|
||||
for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ )
|
||||
{
|
||||
my $filename = "shader$shaderCombo\.o";
|
||||
my $filesize = (stat $filename)[7];
|
||||
|
||||
$byteCodeStart[$shaderCombo] = tell COMPILEDSHADER;
|
||||
$byteCodeSize[$shaderCombo] = $filesize;
|
||||
open SHADERBYTECODE, "<$filename";
|
||||
binmode SHADERBYTECODE;
|
||||
|
||||
my $bin;
|
||||
my $numread = read SHADERBYTECODE, $bin, $filesize;
|
||||
# print "filename: $filename numread: $numread filesize: $filesize\n";
|
||||
close SHADERBYTECODE;
|
||||
unlink $filename;
|
||||
|
||||
print COMPILEDSHADER $bin;
|
||||
}
|
||||
|
||||
# Seek back to the directory and write it out.
|
||||
seek COMPILEDSHADER, $beginningOfDir, 0;
|
||||
for( $i = 0; $i < $numCombos; $i++ )
|
||||
{
|
||||
# offset from beginning of file.
|
||||
print COMPILEDSHADER pack $sInt, $byteCodeStart[$i];
|
||||
# size
|
||||
print COMPILEDSHADER pack $sInt, $byteCodeSize[$i];
|
||||
}
|
||||
|
||||
close COMPILEDSHADER;
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
#! perl
|
||||
|
||||
my $fname=shift || die "format is shaderinfo blah.vcs";
|
||||
|
||||
open(SHADER, $fname) || die "can't open $fname";
|
||||
binmode SHADER;
|
||||
|
||||
read(SHADER,$header,20);
|
||||
($ver,$ntotal,$ndynamic,$flags,$centroidmask)=unpack("LLLLL",$header);
|
||||
|
||||
#print "Version $ver total combos=$ntotal, num dynamic combos=$ndynamic,\n flags=$flags, centroid mask=$centroidmask\n";
|
||||
|
||||
read(SHADER,$refsize,4);
|
||||
$refsize=unpack("L",$refsize);
|
||||
#print "Size of reference shader for diffing=$refsize\n";
|
||||
|
||||
seek(SHADER,$refsize,1);
|
||||
|
||||
$nskipped_combos=0;
|
||||
for(1..$ntotal)
|
||||
{
|
||||
read(SHADER,$combodata,8);
|
||||
($ofs,$combosize)=unpack("LL",$combodata);
|
||||
if ( $ofs == 0xffffffff)
|
||||
{
|
||||
$nskipped_combos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
#print "$nskipped_combos skipped, for an actual total of ",$ntotal-$nskipped_combos,"\n";
|
||||
#print "Real to skipped ratio = ",($ntotal-$nskipped_combos)/$ntotal,"\n";
|
||||
# csv output - name, real combos, virtual combos, dynamic combos
|
||||
my $real_combos=$ntotal-$nskipped_combos;
|
||||
print "$fname,$real_combos,$ntotal,$ndynamic\n";
|
|
@ -0,0 +1,54 @@
|
|||
$infilename = shift;
|
||||
$outfilename1 = shift;
|
||||
$outfilename2 = shift;
|
||||
open INPUT, $infilename || die;
|
||||
@input = <INPUT>;
|
||||
close INPUT;
|
||||
|
||||
open MERGEDMINE, ">$outfilename1" || die;
|
||||
open MERGEDTHEIRS, ">$outfilename2" || die;
|
||||
|
||||
for( $i = 0; $i < scalar( @input ); $i++ )
|
||||
{
|
||||
$line = $input[$i];
|
||||
|
||||
if( $line =~ m/^(.*)<<<<<<</ )
|
||||
{
|
||||
$first = 1;
|
||||
$second = 0;
|
||||
print MERGEDMINE $1;
|
||||
print MERGEDTHEIRS $1;
|
||||
next;
|
||||
}
|
||||
# Make sure that we are in a split block so that comments with ======= don't mess us up.
|
||||
if( $line =~ m/^(.*)=======$/ && $first == 1 )
|
||||
{
|
||||
$first = 0;
|
||||
$second = 1;
|
||||
print MERGEDMINE $1;
|
||||
next;
|
||||
}
|
||||
if( $line =~ m/^(.*)>>>>>>>/ )
|
||||
{
|
||||
$first = $second = 0;
|
||||
print MERGEDTHEIRS $1;
|
||||
next;
|
||||
}
|
||||
|
||||
if( $first )
|
||||
{
|
||||
print MERGEDMINE $line;
|
||||
}
|
||||
elsif( $second )
|
||||
{
|
||||
print MERGEDTHEIRS $line;
|
||||
}
|
||||
else
|
||||
{
|
||||
print MERGEDMINE $line;
|
||||
print MERGEDTHEIRS $line;
|
||||
}
|
||||
}
|
||||
|
||||
close MERGEDMINE;
|
||||
close MERGEDTHEIRS;
|
|
@ -0,0 +1,6 @@
|
|||
foreach $_ (sort <> )
|
||||
{
|
||||
next if( defined( $prevline ) && $_ eq $prevline );
|
||||
$prevline = $_;
|
||||
print;
|
||||
}
|
|
@ -0,0 +1,305 @@
|
|||
use String::CRC32;
|
||||
BEGIN {use File::Basename; push @INC, dirname($0); }
|
||||
require "valve_perl_helpers.pl";
|
||||
|
||||
$dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0;
|
||||
|
||||
$depnum = 0;
|
||||
$baseSourceDir = ".";
|
||||
|
||||
my %dep;
|
||||
|
||||
sub GetAsmShaderDependencies_R
|
||||
{
|
||||
local( $shadername ) = shift;
|
||||
local( *SHADER );
|
||||
|
||||
open SHADER, "<$shadername";
|
||||
while( <SHADER> )
|
||||
{
|
||||
if( m/^\s*\#\s*include\s+\"(.*)\"/ )
|
||||
{
|
||||
# make sure it isn't in there already.
|
||||
if( !defined( $dep{$1} ) )
|
||||
{
|
||||
$dep{$1} = 1;
|
||||
GetAsmShaderDependencies_R( $1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
close SHADER;
|
||||
}
|
||||
|
||||
sub GetAsmShaderDependencies
|
||||
{
|
||||
local( $shadername ) = shift;
|
||||
undef %dep;
|
||||
GetAsmShaderDependencies_R( $shadername );
|
||||
# local( $i );
|
||||
# foreach $i ( keys( %dep ) )
|
||||
# {
|
||||
# print "$shadername depends on $i\n";
|
||||
# }
|
||||
return keys( %dep );
|
||||
}
|
||||
|
||||
sub GetShaderType
|
||||
{
|
||||
my $shadername = shift;
|
||||
my $shadertype;
|
||||
if( $shadername =~ m/\.vsh/i )
|
||||
{
|
||||
$shadertype = "vsh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.psh/i )
|
||||
{
|
||||
$shadertype = "psh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.fxc/i )
|
||||
{
|
||||
$shadertype = "fxc";
|
||||
}
|
||||
else
|
||||
{
|
||||
die;
|
||||
}
|
||||
return $shadertype;
|
||||
}
|
||||
|
||||
sub GetShaderSrc
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/^(.*)-----/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
sub GetShaderBase
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/-----(.*)$/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $shadertype = &GetShaderType( $shadername );
|
||||
$shadername =~ s/\.$shadertype//i;
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
sub DoAsmShader
|
||||
{
|
||||
my $argstring = shift;
|
||||
my $shadername = &GetShaderSrc( $argstring );
|
||||
my $shaderbase = &GetShaderBase( $argstring );
|
||||
my $shadertype = &GetShaderType( $argstring );
|
||||
my $incfile = "";
|
||||
if( $shadertype eq "fxc" || $shadertype eq "vsh" )
|
||||
{
|
||||
$incfile = $shadertype . "tmp9" . $g_tmpfolder . "\\$shaderbase.inc ";
|
||||
}
|
||||
|
||||
my $vcsfile = $shaderbase . $g_vcsext;
|
||||
my $bWillCompileVcs = 1;
|
||||
if( ( $shadertype eq "fxc") && $dynamic_compile )
|
||||
{
|
||||
$bWillCompileVcs = 0;
|
||||
}
|
||||
if( $shadercrcpass{$argstring} )
|
||||
{
|
||||
$bWillCompileVcs = 0;
|
||||
}
|
||||
|
||||
if( $bWillCompileVcs )
|
||||
{
|
||||
&output_makefile_line( $incfile . "shaders\\$shadertype\\$vcsfile: $shadername ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @dep\n") ;
|
||||
}
|
||||
else
|
||||
{
|
||||
# psh files don't need a rule at this point since they don't have inc files and we aren't compiling a vcs.
|
||||
if( $shadertype eq "fxc" || $shadertype eq "vsh" )
|
||||
{
|
||||
&output_makefile_line( $incfile . ": $shadername ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @dep\n") ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
my $x360switch = "";
|
||||
my $moreswitches = "";
|
||||
if( !$bWillCompileVcs && $shadertype eq "fxc" )
|
||||
{
|
||||
$moreswitches .= "-novcs ";
|
||||
}
|
||||
if( $g_x360 )
|
||||
{
|
||||
$x360switch = "-x360";
|
||||
|
||||
if( $bWillCompileVcs && ( $shaderbase =~ m/_ps20$/i ) )
|
||||
{
|
||||
$moreswitches .= "-novcs ";
|
||||
$bWillCompileVcs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# if we are psh and we are compiling the vcs, we don't need this rule.
|
||||
if( !( $shadertype eq "psh" && !$bWillCompileVcs ) )
|
||||
{
|
||||
&output_makefile_line( "\tperl $g_SourceDir\\devtools\\bin\\" . $shadertype . "_prep.pl $moreswitches $x360switch -source \"$g_SourceDir\" $argstring\n") ;
|
||||
}
|
||||
|
||||
if( $bWillCompileVcs )
|
||||
{
|
||||
&output_makefile_line( "\techo $shadername>> filestocopy.txt\n") ;
|
||||
my $dep;
|
||||
foreach $dep( @dep )
|
||||
{
|
||||
&output_makefile_line( "\techo $dep>> filestocopy.txt\n") ;
|
||||
}
|
||||
}
|
||||
&output_makefile_line( "\n") ;
|
||||
}
|
||||
|
||||
if( scalar( @ARGV ) == 0 )
|
||||
{
|
||||
die "Usage updateshaders.pl shaderprojectbasename\n\tie: updateshaders.pl stdshaders_dx6\n";
|
||||
}
|
||||
|
||||
$g_x360 = 0;
|
||||
$g_tmpfolder = "_tmp";
|
||||
$g_vcsext = ".vcs";
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
$inputbase = shift;
|
||||
|
||||
if( $inputbase =~ m/-source/ )
|
||||
{
|
||||
$g_SourceDir = shift;
|
||||
}
|
||||
elsif( $inputbase =~ m/-x360/ )
|
||||
{
|
||||
$g_x360 = 1;
|
||||
$g_tmpfolder = "_360_tmp";
|
||||
$g_vcsext = ".360.vcs";
|
||||
}
|
||||
elsif( $inputbase =~ m/-execute/ )
|
||||
{
|
||||
$g_execute = 1;
|
||||
}
|
||||
elsif( $inputbase =~ m/-nv3x/ )
|
||||
{
|
||||
$nv3x = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
my @srcfiles = &LoadShaderListFile( $inputbase );
|
||||
|
||||
open MAKEFILE, ">makefile\.$inputbase";
|
||||
open COPYFILE, ">makefile\.$inputbase\.copy";
|
||||
open INCLIST, ">inclist.txt";
|
||||
open VCSLIST, ">vcslist.txt";
|
||||
|
||||
# make a default dependency that depends on all of the shaders.
|
||||
&output_makefile_line( "default: ") ;
|
||||
foreach $shader ( @srcfiles )
|
||||
{
|
||||
my $shadertype = &GetShaderType( $shader );
|
||||
my $shaderbase = &GetShaderBase( $shader );
|
||||
my $shadersrc = &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";
|
||||
&output_makefile_line( " $incFileName" );
|
||||
&output_inclist_line( "$incFileName\n" );
|
||||
}
|
||||
|
||||
my $vcsfile = $shaderbase . $g_vcsext;
|
||||
|
||||
my $compilevcs = 1;
|
||||
if( $shadertype eq "fxc" && $dynamic_compile )
|
||||
{
|
||||
$compilevcs = 0;
|
||||
}
|
||||
if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) )
|
||||
{
|
||||
$compilevcs = 0;
|
||||
}
|
||||
if( $compilevcs )
|
||||
{
|
||||
my $vcsFileName = "..\\..\\..\\game\\platform\\shaders\\$shadertype\\$shaderbase" . $g_vcsext;
|
||||
# We want to check for perforce operations even if the crc matches in the event that a file has been manually reverted and needs to be checked out again.
|
||||
&output_vcslist_line( "$vcsFileName\n" );
|
||||
$shadercrcpass{$shader} = &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 0 );
|
||||
if( $shadercrcpass{$shader} )
|
||||
{
|
||||
$compilevcs = 0;
|
||||
}
|
||||
}
|
||||
if( $compilevcs )
|
||||
{
|
||||
&output_makefile_line( " shaders\\$shadertype\\$vcsfile" );
|
||||
# emit a list of vcs files to copy to the target since we want to build them.
|
||||
&output_copyfile_line( GetShaderSrc($shader) . "-----" . GetShaderBase($shader) . "\n" );
|
||||
}
|
||||
}
|
||||
&output_makefile_line( "\n\n") ;
|
||||
|
||||
# Insert all of our vertex shaders and depencencies
|
||||
$lastshader = "";
|
||||
foreach $shader ( @srcfiles )
|
||||
{
|
||||
my $currentshader = &GetShaderSrc( $shader );
|
||||
if ( $lastshader ne $currentshader )
|
||||
{
|
||||
$lastshader = $currentshader;
|
||||
@dep = &GetAsmShaderDependencies( $lastshader );
|
||||
}
|
||||
&DoAsmShader( $shader );
|
||||
}
|
||||
close VCSLIST;
|
||||
close INCLIST;
|
||||
close COPYFILE;
|
||||
close MAKEFILE;
|
||||
|
||||
# nuke the copyfile if it is zero length
|
||||
if( ( stat "makefile\.$inputbase\.copy" )[7] == 0 )
|
||||
{
|
||||
unlink "makefile\.$inputbase\.copy";
|
||||
}
|
||||
|
||||
sub output_makefile_line
|
||||
{
|
||||
local ($_)=@_;
|
||||
print MAKEFILE $_;
|
||||
}
|
||||
|
||||
sub output_copyfile_line
|
||||
{
|
||||
local ($_)=@_;
|
||||
print COPYFILE $_;
|
||||
}
|
||||
|
||||
sub output_vcslist_line
|
||||
{
|
||||
local ($_)=@_;
|
||||
print VCSLIST $_;
|
||||
}
|
||||
|
||||
sub output_inclist_line
|
||||
{
|
||||
local ($_)=@_;
|
||||
print INCLIST $_;
|
||||
}
|
||||
|
|
@ -0,0 +1,539 @@
|
|||
sub BackToForwardSlash
|
||||
{
|
||||
my( $path ) = shift;
|
||||
$path =~ s,\\,/,g;
|
||||
return $path;
|
||||
}
|
||||
|
||||
sub RemoveFileName
|
||||
{
|
||||
my( $in ) = shift;
|
||||
$in = &BackToForwardSlash( $in );
|
||||
$in =~ s,/[^/]*$,,;
|
||||
return $in;
|
||||
}
|
||||
|
||||
sub RemovePath
|
||||
{
|
||||
my( $in ) = shift;
|
||||
$in = &BackToForwardSlash( $in );
|
||||
$in =~ s,^(.*)/([^/]*)$,$2,;
|
||||
return $in;
|
||||
}
|
||||
|
||||
sub MakeDirHier
|
||||
{
|
||||
my( $in ) = shift;
|
||||
# print "MakeDirHier( $in )\n";
|
||||
$in = &BackToForwardSlash( $in );
|
||||
my( @path );
|
||||
while( $in =~ m,/, ) # while $in still has a slash
|
||||
{
|
||||
my( $end ) = &RemovePath( $in );
|
||||
push @path, $end;
|
||||
# print $in . "\n";
|
||||
$in = &RemoveFileName( $in );
|
||||
}
|
||||
my( $i );
|
||||
my( $numelems ) = scalar( @path );
|
||||
my( $curpath );
|
||||
for( $i = $numelems - 1; $i >= 0; $i-- )
|
||||
{
|
||||
$curpath .= "/" . $path[$i];
|
||||
my( $dir ) = $in . $curpath;
|
||||
if( !stat $dir )
|
||||
{
|
||||
# print "mkdir $dir\n";
|
||||
mkdir $dir, 0777;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub FileExists
|
||||
{
|
||||
my $filename = shift;
|
||||
my @statresult = stat $filename;
|
||||
my $iswritable = @statresult != 0;
|
||||
return $iswritable;
|
||||
}
|
||||
|
||||
sub MakeFileWritable
|
||||
{
|
||||
my $filename = shift;
|
||||
if ( &FileExists( $filename ) )
|
||||
{
|
||||
chmod 0666, $filename || die;
|
||||
}
|
||||
}
|
||||
|
||||
sub MakeFileReadOnly
|
||||
{
|
||||
my $filename = shift;
|
||||
chmod 0444, $filename || die;
|
||||
}
|
||||
|
||||
# Run a command and get stdout and stderr to an array
|
||||
sub RunCommand
|
||||
{
|
||||
my $cmd = shift;
|
||||
# print STDERR "command: $cmd\n";
|
||||
system "$cmd > cmdout.txt 2>&1" || die;
|
||||
local( *FILE );
|
||||
open FILE, "<cmdout.txt" || die;
|
||||
my @output = <FILE>;
|
||||
# print STDERR "command output: @output\n";
|
||||
close FILE;
|
||||
unlink "cmdout.txt" || die;
|
||||
return @output;
|
||||
}
|
||||
|
||||
sub PerforceEditOrAdd
|
||||
{
|
||||
return;
|
||||
my $filename = shift;
|
||||
my $changelistarg = shift;
|
||||
|
||||
# Is the file on the client?
|
||||
my $cmd = "p4 fstat \"$filename\"";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
my $p4output = join "", @p4output;
|
||||
if( $p4output =~ m/no such file/ )
|
||||
{
|
||||
# not on client. . add
|
||||
my $cmd = "p4 add $changelistarg $filename";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
my $p4output = join "", @p4output;
|
||||
if( $p4output =~ m/opened for add/ )
|
||||
{
|
||||
print $p4output;
|
||||
return;
|
||||
}
|
||||
print "ERROR: $p4output";
|
||||
return;
|
||||
}
|
||||
|
||||
# The file is known to be on the client at this point.
|
||||
|
||||
# Is it open for edit?
|
||||
if( $p4output =~ m/action edit/ )
|
||||
{
|
||||
# Is is open for edit, let's see if it's still different.
|
||||
# check for opened files that are not different from the revision in the depot.
|
||||
my $cmd = "p4 diff -sr \"$filename\"";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
my $outputstring = join "", @p4output;
|
||||
# check for empty string
|
||||
if( !( $outputstring =~ m/^\s*$/ ) )
|
||||
{
|
||||
my $cmd = "p4 revert \"$filename\"";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
my $outputstring = join "", @p4output;
|
||||
print $outputstring;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check for unopened files that are different from the revision in the depot.
|
||||
my $cmd = "p4 diff -se \"$filename\"";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
my $outputstring = join "", @p4output;
|
||||
# check for empty string
|
||||
if( $outputstring =~ m/^\s*$/ )
|
||||
{
|
||||
&MakeFileReadOnly( $filename );
|
||||
return;
|
||||
}
|
||||
|
||||
# We need to edit the file since it is known to be different here.
|
||||
my $cmd = "p4 edit $changelistarg \"$filename\"";
|
||||
my @p4output = &RunCommand( $cmd );
|
||||
|
||||
my $line;
|
||||
foreach $line ( @p4output )
|
||||
{
|
||||
if( $line =~ m/not on client/ )
|
||||
{
|
||||
#print "notonclient...";
|
||||
print "ERROR: @p4output\n";
|
||||
return;
|
||||
}
|
||||
if( $line =~ m/currently opened for edit/ )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( $line =~ m/opened for edit/ )
|
||||
{
|
||||
print $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub FileIsWritable
|
||||
{
|
||||
local( $filename ) = shift;
|
||||
local( @statresult ) = stat $filename;
|
||||
local( $mode, $iswritable );
|
||||
$mode = oct( $statresult[2] );
|
||||
$iswritable = ( $mode & 2 ) != 0;
|
||||
return $iswritable;
|
||||
}
|
||||
|
||||
sub TouchFile
|
||||
{
|
||||
my $filename = shift;
|
||||
if( !&FileExists( $filename ) )
|
||||
{
|
||||
if( !open FILE, ">$filename" )
|
||||
{
|
||||
die;
|
||||
}
|
||||
close FILE;
|
||||
}
|
||||
my $now = time;
|
||||
local( *FILE );
|
||||
utime $now, $now, $filename;
|
||||
}
|
||||
|
||||
sub FileExistsInPerforce
|
||||
{
|
||||
my $filename = shift;
|
||||
my @output = &RunCommand( "p4 fstat $filename" );
|
||||
my $line;
|
||||
foreach $line (@output)
|
||||
{
|
||||
if( $line =~ m/no such file/ )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub PerforceWriteFile
|
||||
{
|
||||
my $filename = shift;
|
||||
my $filecontents = shift;
|
||||
|
||||
# Make the target vcs writable if it exists
|
||||
MakeFileWritable( $filename );
|
||||
|
||||
# Write the file.
|
||||
local( *FP );
|
||||
open FP, ">$filename";
|
||||
print FP $filecontents;
|
||||
close FP;
|
||||
}
|
||||
|
||||
sub WriteFile
|
||||
{
|
||||
my $filename = shift;
|
||||
my $filecontents = shift;
|
||||
|
||||
# Make the target vcs writable if it exists
|
||||
MakeFileWritable( $filename );
|
||||
|
||||
# Write the file.
|
||||
local( *FP );
|
||||
open FP, ">$filename";
|
||||
print FP $filecontents;
|
||||
close FP;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
sub MakeSureFileExists
|
||||
{
|
||||
local( $filename ) = shift;
|
||||
local( $testexists ) = shift;
|
||||
local( $testwrite ) = shift;
|
||||
|
||||
local( @statresult ) = stat $filename;
|
||||
if( !@statresult && $testexists )
|
||||
{
|
||||
die "$filename doesn't exist!\n";
|
||||
}
|
||||
local( $mode, $iswritable );
|
||||
$mode = oct( $statresult[2] );
|
||||
$iswritable = ( $mode & 2 ) != 0;
|
||||
if( !$iswritable && $testwrite )
|
||||
{
|
||||
die "$filename isn't writable!\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub LoadShaderListFile_GetShaderType
|
||||
{
|
||||
my $shadername = shift;
|
||||
my $shadertype;
|
||||
if( $shadername =~ m/\.vsh/i )
|
||||
{
|
||||
$shadertype = "vsh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.psh/i )
|
||||
{
|
||||
$shadertype = "psh";
|
||||
}
|
||||
elsif( $shadername =~ m/\.fxc/i )
|
||||
{
|
||||
$shadertype = "fxc";
|
||||
}
|
||||
else
|
||||
{
|
||||
die;
|
||||
}
|
||||
return $shadertype;
|
||||
}
|
||||
|
||||
sub LoadShaderListFile_GetShaderSrc
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/^(.*)-----/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
sub LoadShaderListFile_GetShaderBase
|
||||
{
|
||||
my $shadername = shift;
|
||||
if ( $shadername =~ m/-----(.*)$/i )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $shadertype = &LoadShaderListFile_GetShaderType( $shadername );
|
||||
$shadername =~ s/\.$shadertype//i;
|
||||
return $shadername;
|
||||
}
|
||||
}
|
||||
|
||||
sub LoadShaderListFile
|
||||
{
|
||||
my $inputbase = shift;
|
||||
|
||||
my @srcfiles;
|
||||
&MakeSureFileExists( "$inputbase.txt", 1, 0 );
|
||||
|
||||
open SHADERLISTFILE, "<$inputbase.txt" || die;
|
||||
my $line;
|
||||
while( $line = <SHADERLISTFILE> )
|
||||
{
|
||||
$line =~ s/\/\/.*$//; # remove comments "//..."
|
||||
$line =~ s/^\s*//; # trim leading whitespace
|
||||
$line =~ s/\s*$//; # trim trailing whitespace
|
||||
next if( $line =~ m/^\s*$/ );
|
||||
if( $line =~ m/\.fxc/ || $line =~ m/\.vsh/ || $line =~ m/\.psh/ )
|
||||
{
|
||||
my $shaderbase = &LoadShaderListFile_GetShaderBase( $line );
|
||||
|
||||
if( $ENV{"DIRECTX_FORCE_MODEL"} =~ m/^30$/i ) # forcing all shaders to be ver. 30
|
||||
{
|
||||
my $targetbase = $shaderbase;
|
||||
$targetbase =~ s/_ps2x/_ps30/i;
|
||||
$targetbase =~ s/_ps20b/_ps30/i;
|
||||
$targetbase =~ s/_ps20/_ps30/i;
|
||||
$targetbase =~ s/_vs20/_vs30/i;
|
||||
$targetbase =~ s/_vsxx/_vs30/i;
|
||||
push @srcfiles, ( $line . "-----" . $targetbase );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $shaderbase =~ m/_ps2x/i )
|
||||
{
|
||||
my $targetbase = $shaderbase;
|
||||
$targetbase =~ s/_ps2x/_ps20/i;
|
||||
push @srcfiles, ( $line . "-----" . $targetbase );
|
||||
|
||||
$targetbase = $shaderbase;
|
||||
$targetbase =~ s/_ps2x/_ps20b/i;
|
||||
push @srcfiles, ( $line . "-----" . $targetbase );
|
||||
}
|
||||
elsif( $shaderbase =~ m/_vsxx/i )
|
||||
{
|
||||
my $targetbase = $shaderbase;
|
||||
$targetbase =~ s/_vsxx/_vs20/i;
|
||||
push @srcfiles, ( $line . "-----" . $targetbase );
|
||||
}
|
||||
else
|
||||
{
|
||||
push @srcfiles, ( $line . "-----" . $shaderbase );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close SHADERLISTFILE;
|
||||
return @srcfiles;
|
||||
}
|
||||
|
||||
sub ReadInputFileWithIncludes
|
||||
{
|
||||
local( $filename ) = shift;
|
||||
# print STDERR "ReadInputFileWithIncludes: $filename\n";
|
||||
|
||||
local( *INPUT );
|
||||
local( $output );
|
||||
|
||||
# print STDERR "before open\n";
|
||||
open INPUT, "<$filename" || die;
|
||||
# print STDERR "after open\n";
|
||||
|
||||
local( $line );
|
||||
while( $line = <INPUT> )
|
||||
{
|
||||
# print STDERR $line;
|
||||
if( $line =~ m/\#include\s+\"(.*)\"/i )
|
||||
{
|
||||
$output.= ReadInputFileWithIncludes( $1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
close INPUT;
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub GetCRCFromSourceFile
|
||||
{
|
||||
my $filename = shift;
|
||||
my $data = &ReadInputFileWithIncludes( $filename );
|
||||
# print STDERR $data;
|
||||
$crc = crc32( $data );
|
||||
# print STDERR "GetCRCFromSourceFile: $crc\n";
|
||||
return $crc;
|
||||
}
|
||||
|
||||
sub GetCRCFromVCSFile
|
||||
{
|
||||
my $filename = shift;
|
||||
# print STDERR "GetCRCFromVCSFile $filename\n";
|
||||
local( *FP );
|
||||
open FP, "<$filename" || die "GetCRCFromVCSFile: can't open file $filename\n";
|
||||
binmode( FP );
|
||||
|
||||
# unpack arguments
|
||||
my $sInt = "i";
|
||||
my $uInt = "I";
|
||||
if( $filename =~ m/\.360\./ )
|
||||
{
|
||||
# Change arguments to "big endian long"
|
||||
$sInt = "N";
|
||||
$uInt = "N";
|
||||
}
|
||||
|
||||
my $header;
|
||||
read FP, $header, 7 * 4 || die "updateshaders.pl:GetCRCFromVCSFile: can't read header for $filename\n";
|
||||
my $version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc;
|
||||
($version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc) = unpack "$sInt$sInt$sInt$uInt$uInt$uInt$uInt", $header;
|
||||
unless( $version == 4 || $version == 5 || $version == 6 )
|
||||
{
|
||||
print STDERR "ERROR: GetCRCFromVCSFile: $filename is version $version\n";
|
||||
return 0;
|
||||
}
|
||||
# print STDERR "version: $version\n";
|
||||
# print STDERR "numCombos: $numCombos\n";
|
||||
# print STDERR "numDynamicCombos: $numDynamicCombos\n";
|
||||
# print STDERR "flags: $flags\n";
|
||||
# print STDERR "centroidMask: $centroidMask\n";
|
||||
# print STDERR "refSize: $refSize\n";
|
||||
# print STDERR "GetCRCFromVCSFile: $crc\n";
|
||||
close( FP );
|
||||
return $crc;
|
||||
}
|
||||
|
||||
sub CheckCRCAgainstTarget
|
||||
{
|
||||
my $srcFileName = shift;
|
||||
my $vcsFileName = shift;
|
||||
my $warn = shift;
|
||||
|
||||
# Make sure both files exist.
|
||||
# print STDERR "$srcFileName doesn't exist\n" if( !( -e $srcFileName ) );
|
||||
# print STDERR "$vcsFileName doesn't exist\n" if( !( -e $vcsFileName ) );
|
||||
if( !( -e $srcFileName ) )
|
||||
{
|
||||
if( $warn )
|
||||
{
|
||||
print "$srcFileName missing\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if( !( -e $vcsFileName ) )
|
||||
{
|
||||
if( $warn )
|
||||
{
|
||||
print "$vcsFileName missing\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
# print STDERR "CheckCRCAgainstTarget( $srcFileName, $vcsFileName );\n";
|
||||
# print STDERR "vcsFileName: $vcsFileName\n";
|
||||
# print STDERR "vcsFileName: $srcFileName\n";
|
||||
my $vcsCRC = &GetCRCFromVCSFile( $vcsFileName );
|
||||
my $srcCRC = &GetCRCFromSourceFile( $srcFileName );
|
||||
if( $warn && ( $vcsCRC != $srcCRC ) )
|
||||
{
|
||||
print "$vcsFileName checksum ($vcsCRC) != $srcFileName checksum: ($srcCRC)\n";
|
||||
}
|
||||
|
||||
# return 0; # use this to skip crc checking.
|
||||
# if( $vcsCRC == $srcCRC )
|
||||
# {
|
||||
# print STDERR "CRC passed for $srcFileName $vcsFileName $vcsCRC\n";
|
||||
# }
|
||||
return $vcsCRC == $srcCRC;
|
||||
}
|
||||
|
||||
1;
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -1642,7 +1642,7 @@ void CBaseModPanel::OnEvent( KeyValues *pEvent )
|
|||
}
|
||||
}
|
||||
|
||||
CUIGameData::Get()->OpenWaitScreen( szWaitScreenText, flMinDisplayTime, pSettings );
|
||||
CUIGameData::Get()->OpenWaitScreen( szWaitScreenText, flMinDisplayTime, pSettings, 7.0f );
|
||||
}
|
||||
else if ( !Q_stricmp( "searchresult", szProgress ) )
|
||||
{
|
||||
|
|
|
@ -615,7 +615,7 @@ bool CUIGameData::IsXUIOpen()
|
|||
return m_bXUIOpen;
|
||||
}
|
||||
|
||||
void CUIGameData::OpenWaitScreen( const char * messageText, float minDisplayTime, KeyValues *pSettings )
|
||||
void CUIGameData::OpenWaitScreen( const char * messageText, float minDisplayTime, KeyValues *pSettings, float maxDisplayTime )
|
||||
{
|
||||
if ( UI_IsDebug() )
|
||||
{
|
||||
|
@ -642,6 +642,7 @@ void CUIGameData::OpenWaitScreen( const char * messageText, float minDisplayTime
|
|||
waitScreen->SetNavBack( backFrame );
|
||||
waitScreen->ClearData();
|
||||
waitScreen->AddMessageText( messageText, minDisplayTime );
|
||||
waitScreen->SetMaxDisplayTime( maxDisplayTime );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ public:
|
|||
|
||||
bool IsXUIOpen();
|
||||
|
||||
void OpenWaitScreen( const char * messageText, float minDisplayTime = 3.0f, KeyValues *pSettings = NULL );
|
||||
void OpenWaitScreen( const char * messageText, float minDisplayTime = 3.0f, KeyValues *pSettings = NULL, float maxDisplayTime = 0.0f );
|
||||
void UpdateWaitPanel( const char * messageText, float minDisplayTime = 3.0f );
|
||||
void UpdateWaitPanel( const wchar_t * messageText, float minDisplayTime = 3.0f );
|
||||
void CloseWaitScreen( vgui::Panel * callbackPanel, const char * messageName );
|
||||
|
|
|
@ -252,7 +252,11 @@ void GenericWaitScreen::CheckIfNeedsToClose()
|
|||
{
|
||||
if ( m_MsgStartDisplayTime + m_MsgMaxDisplayTime < time )
|
||||
{
|
||||
NavigateBack();
|
||||
if ( !NavigateBack() )
|
||||
{
|
||||
Close();
|
||||
CBaseModPanel::GetSingleton().OpenFrontScreen();
|
||||
}
|
||||
|
||||
if ( m_pfnMaxTimeOut )
|
||||
m_pfnMaxTimeOut();
|
||||
|
|
|
@ -167,6 +167,7 @@ ConVar asw_stim_time_scale("asw_stim_time_scale", "0.35", FCVAR_REPLICATED | FCV
|
|||
ConVar asw_time_scale_delay("asw_time_scale_delay", "0.15", FCVAR_REPLICATED | FCVAR_CHEAT, "Delay before timescale changes to give a chance for the client to comply and predict.");
|
||||
ConVar asw_ignore_need_two_player_requirement("asw_ignore_need_two_player_requirement", "0", FCVAR_REPLICATED, "If set to 1, ignores the mission setting that states two players are needed to start the mission.");
|
||||
ConVar mp_gamemode( "mp_gamemode", "campaign", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Current game mode, acceptable values are campaign and single_mission.", false, 0.0f, false, 0.0f );
|
||||
ConVar mm_max_players( "mm_max_players", "4", FCVAR_REPLICATED | FCVAR_CHEAT, "Max players for matchmaking system" );
|
||||
ConVar asw_sentry_friendly_fire_scale( "asw_sentry_friendly_fire_scale", "0", FCVAR_REPLICATED, "Damage scale for sentry gun friendly fire"
|
||||
#ifdef GAME_DLL
|
||||
,UpdateMatchmakingTagsCallback );
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
// An interface that should not ever be accessed directly from shaders
|
||||
// but instead is visible only to shaderlib.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef ISHADERSYSTEM_H
|
||||
#define ISHADERSYSTEM_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "interface.h"
|
||||
#include <materialsystem/IShader.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
enum Sampler_t;
|
||||
class ITexture;
|
||||
class IShader;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Shader system interface version
|
||||
//-----------------------------------------------------------------------------
|
||||
#define SHADERSYSTEM_INTERFACE_VERSION "ShaderSystem002"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Modulation flags
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
SHADER_USING_ALPHA_MODULATION = 0x1,
|
||||
SHADER_USING_FLASHLIGHT = 0x2,
|
||||
SHADER_USING_FIXED_FUNCTION_BAKED_LIGHTING = 0x4,
|
||||
SHADER_USING_EDITOR = 0x8,
|
||||
|
||||
// the BUFFER0 and GBUFFER1 bits provide 3 g-buffermodes plus the normal modes.
|
||||
// the modes are:
|
||||
// Normal rendering = ( gbuffer1 = 0, gbuffer0 = 0 )
|
||||
// Output pos, normal, albedo via mrts = (0,1)
|
||||
// output fixed lighted single image = (1,0)
|
||||
// output the normal = (1,1)
|
||||
SHADER_USING_GBUFFER0 = 0x10,
|
||||
SHADER_USING_GBUFFER1 = 0x20,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader system (a singleton)
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderSystem
|
||||
{
|
||||
public:
|
||||
virtual ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrameVar, int nTextureChannel = 0 ) =0;
|
||||
|
||||
// Binds a texture
|
||||
virtual void BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrameVar = 0 ) = 0;
|
||||
virtual void BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrameVar = 0 ) = 0;
|
||||
|
||||
// Takes a snapshot
|
||||
virtual void TakeSnapshot( ) = 0;
|
||||
|
||||
// Draws a snapshot
|
||||
virtual void DrawSnapshot( const unsigned char *pInstanceCommandBuffer, bool bMakeActualDrawCall = true ) = 0;
|
||||
|
||||
// Are we using graphics?
|
||||
virtual bool IsUsingGraphics() const = 0;
|
||||
|
||||
// Are editor materials enabled?
|
||||
virtual bool CanUseEditorMaterials() const = 0;
|
||||
|
||||
// Bind vertex texture
|
||||
virtual void BindVertexTexture( VertexTextureSampler_t vtSampler, ITexture *pTexture, int nFrameVar = 0 ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Shader plug-in DLL interface version
|
||||
//-----------------------------------------------------------------------------
|
||||
#define SHADER_DLL_INTERFACE_VERSION "ShaderDLL004"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Shader interface versions
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderDLLInternal
|
||||
{
|
||||
public:
|
||||
// Here's where the app systems get to learn about each other
|
||||
virtual bool Connect( CreateInterfaceFn factory, bool bIsMaterialSystem ) = 0;
|
||||
virtual void Disconnect( bool bIsMaterialSystem ) = 0;
|
||||
|
||||
// Returns the number of shaders defined in this DLL
|
||||
virtual int ShaderCount() const = 0;
|
||||
|
||||
// Returns information about each shader defined in this DLL
|
||||
virtual IShader *GetShader( int nShader ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderDLLInternal *GetShaderDLLInternal();
|
||||
|
||||
|
||||
#endif // ISHADERSYSTEM_H
|
|
@ -0,0 +1,176 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IMATERIALINTERNAL_H
|
||||
#define IMATERIALINTERNAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// identifier was truncated to '255' characters in the debug information
|
||||
#pragma warning(disable: 4786)
|
||||
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
enum MaterialPrimitiveType_t;
|
||||
class IShader;
|
||||
class IMesh;
|
||||
class IVertexBuffer;
|
||||
class IIndexBuffer;
|
||||
struct Shader_VertexArrayData_t;
|
||||
struct ShaderRenderState_t;
|
||||
class KeyValues;
|
||||
|
||||
|
||||
struct tokencache_t
|
||||
{
|
||||
unsigned short symbol;
|
||||
unsigned char varIndex;
|
||||
unsigned char cached : 1;
|
||||
unsigned char subrect : 1;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface for materials used only within the material system
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IMaterialInternal : public IMaterial
|
||||
{
|
||||
public:
|
||||
// class factory methods
|
||||
static IMaterialInternal* CreateMaterial( char const* pMaterialName, const char *pTextureGroupName, KeyValues *pKeyValues = NULL );
|
||||
static void DestroyMaterial( IMaterialInternal* pMaterial );
|
||||
|
||||
// If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
|
||||
static IMaterialInternal* CreateMaterialSubRect( char const* pMaterialName, const char *pTextureGroupName,
|
||||
KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, bool bAssumeCreateFromFile = false );
|
||||
static void DestroyMaterialSubRect( IMaterialInternal* pMaterial );
|
||||
|
||||
// refcount
|
||||
virtual int GetReferenceCount( ) const = 0;
|
||||
|
||||
// enumeration id
|
||||
virtual void SetEnumerationID( int id ) = 0;
|
||||
|
||||
// White lightmap methods
|
||||
virtual void SetNeedsWhiteLightmap( bool val ) = 0;
|
||||
virtual bool GetNeedsWhiteLightmap( ) const = 0;
|
||||
|
||||
// load/unload
|
||||
virtual void Uncache( bool bPreserveVars = false ) = 0;
|
||||
virtual void Precache() = 0;
|
||||
// If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
|
||||
virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector<FileNameHandle_t> *pIncludes = NULL ) = 0;
|
||||
|
||||
// reload all textures used by this materals
|
||||
virtual void ReloadTextures() = 0;
|
||||
|
||||
// lightmap pages associated with this material
|
||||
virtual void SetMinLightmapPageID( int pageID ) = 0;
|
||||
virtual void SetMaxLightmapPageID( int pageID ) = 0;;
|
||||
virtual int GetMinLightmapPageID( ) const = 0;
|
||||
virtual int GetMaxLightmapPageID( ) const = 0;
|
||||
|
||||
virtual IShader *GetShader() const = 0;
|
||||
|
||||
// Can we use it?
|
||||
virtual bool IsPrecached( ) const = 0;
|
||||
virtual bool IsPrecachedVars() const = 0;
|
||||
|
||||
// main draw method
|
||||
virtual void DrawMesh( VertexCompressionType_t vertexCompression, bool bIsAlphaModulating, bool bUsingPreTessPatches ) = 0;
|
||||
|
||||
// Gets the vertex format
|
||||
virtual VertexFormat_t GetVertexFormat() const = 0;
|
||||
virtual VertexFormat_t GetVertexUsage() const = 0;
|
||||
|
||||
// Performs a debug trace on this material
|
||||
virtual bool PerformDebugTrace() const = 0;
|
||||
|
||||
// Can we override this material in debug?
|
||||
virtual bool NoDebugOverride() const = 0;
|
||||
|
||||
// Should we draw?
|
||||
virtual void ToggleSuppression() = 0;
|
||||
|
||||
// Are we suppressed?
|
||||
virtual bool IsSuppressed() const = 0;
|
||||
|
||||
// Should we debug?
|
||||
virtual void ToggleDebugTrace() = 0;
|
||||
|
||||
// Do we use fog?
|
||||
virtual bool UseFog() const = 0;
|
||||
|
||||
// Adds a material variable to the material
|
||||
virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) = 0;
|
||||
|
||||
// Gets the renderstate
|
||||
virtual ShaderRenderState_t *GetRenderState() = 0;
|
||||
|
||||
// Was this manually created (not read from a file?)
|
||||
virtual bool IsManuallyCreated() const = 0;
|
||||
|
||||
virtual bool NeedsFixedFunctionFlashlight() const = 0;
|
||||
|
||||
virtual bool IsUsingVertexID() const = 0;
|
||||
|
||||
// Identifies a material mounted through the preload path
|
||||
virtual void MarkAsPreloaded( bool bSet ) = 0;
|
||||
virtual bool IsPreloaded() const = 0;
|
||||
|
||||
// Conditonally increments the refcount
|
||||
virtual void ArtificialAddRef( void ) = 0;
|
||||
virtual void ArtificialRelease( void ) = 0;
|
||||
|
||||
virtual void ReportVarChanged( IMaterialVar *pVar ) = 0;
|
||||
virtual uint32 GetChangeID() const = 0;
|
||||
|
||||
virtual bool IsTranslucentInternal( float fAlphaModulation ) const = 0;
|
||||
|
||||
//Is this the queue friendly or realtime version of the material?
|
||||
virtual bool IsRealTimeVersion( void ) const = 0;
|
||||
|
||||
virtual void ClearContextData( void )
|
||||
{
|
||||
}
|
||||
|
||||
//easy swapping between the queue friendly and realtime versions of the material
|
||||
virtual IMaterialInternal *GetRealTimeVersion( void ) = 0;
|
||||
virtual IMaterialInternal *GetQueueFriendlyVersion( void ) = 0;
|
||||
|
||||
virtual void PrecacheMappingDimensions( void ) = 0;
|
||||
virtual void FindRepresentativeTexture( void ) = 0;
|
||||
|
||||
// These are used when a new whitelist is passed in. First materials to be reloaded are flagged, then they are reloaded.
|
||||
virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) = 0;
|
||||
virtual void ReloadFromWhitelistIfMarked() = 0;
|
||||
|
||||
virtual void CompactMaterialVars() = 0;
|
||||
};
|
||||
|
||||
extern void InsertKeyValues( KeyValues& dst, KeyValues& src, bool bCheckForExistence );
|
||||
extern void WriteKeyValuesToFile( const char *pFileName, KeyValues& keyValues );
|
||||
extern void ExpandPatchFile( KeyValues& keyValues, KeyValues &patchKeyValues );
|
||||
// patchKeyValues accumulates keys applied by VMT patch files (this is necessary to make $fallbackmaterial
|
||||
// work properly - the patch keys need to be reapplied when the fallback VMT is loaded). It may contain
|
||||
// previously accumulated patch keys on entry, and may contain more encountered patch keys on exit.
|
||||
extern bool LoadVMTFile( KeyValues &vmtKeyValues, KeyValues &patchKeyValues, const char *pMaterialName, bool bUsesUNCFilename, CUtlVector<FileNameHandle_t> *pIncludes );
|
||||
|
||||
extern void CompactMaterialVars( IMaterialVar **ppMaterialVars, int nVars );
|
||||
extern void CompactMaterialVarHeap();
|
||||
|
||||
#endif // IMATERIALINTERNAL_H
|
|
@ -0,0 +1,229 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IMATERIALSYSTEMINTERNAL_H
|
||||
#define IMATERIALSYSTEMINTERNAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "tier1/callqueue.h"
|
||||
#include "tier1/memstack.h"
|
||||
|
||||
class IMaterialInternal;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Special call queue that knows (a) single threaded access, and (b) all
|
||||
// functions called after last function added
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CMatCallQueue
|
||||
{
|
||||
public:
|
||||
CMatCallQueue()
|
||||
{
|
||||
MEM_ALLOC_CREDIT_( "CMatCallQueue.m_Allocator" );
|
||||
#ifdef SWDS
|
||||
m_Allocator.Init( 2*1024, 0, 0, 4 );
|
||||
#else
|
||||
m_Allocator.Init( IsX360() ? 2*1024*1024 : 8*1024*1024, 64*1024, 256*1024, 4 );
|
||||
#endif
|
||||
m_FunctorFactory.SetAllocator( &m_Allocator );
|
||||
m_pHead = m_pTail = NULL;
|
||||
}
|
||||
|
||||
size_t GetMemoryUsed()
|
||||
{
|
||||
return m_Allocator.GetUsed();
|
||||
}
|
||||
|
||||
int Count()
|
||||
{
|
||||
int i = 0;
|
||||
Elem_t *pCurrent = m_pHead;
|
||||
while ( pCurrent )
|
||||
{
|
||||
i++;
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void CallQueued()
|
||||
{
|
||||
if ( !m_pHead )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CFunctor *pFunctor;
|
||||
|
||||
Elem_t *pCurrent = m_pHead;
|
||||
while ( pCurrent )
|
||||
{
|
||||
pFunctor = pCurrent->pFunctor;
|
||||
#ifdef _DEBUG
|
||||
if ( pFunctor->m_nUserID == m_nBreakSerialNumber)
|
||||
{
|
||||
m_nBreakSerialNumber = (unsigned)-1;
|
||||
}
|
||||
#endif
|
||||
(*pFunctor)();
|
||||
pFunctor->Release();
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
#ifdef DEBUG_MATCALLQUEUE
|
||||
static int prevHigh = 0;
|
||||
if ( m_Allocator.GetUsed() > prevHigh )
|
||||
{
|
||||
Msg( "***%d\n", m_Allocator.GetUsed() );
|
||||
prevHigh = m_Allocator.GetUsed();
|
||||
}
|
||||
#endif
|
||||
m_Allocator.FreeAll( false );
|
||||
m_pHead = m_pTail = NULL;
|
||||
}
|
||||
|
||||
void QueueFunctor( CFunctor *pFunctor )
|
||||
{
|
||||
Assert( pFunctor );
|
||||
QueueFunctorInternal( RetAddRef( pFunctor ) );
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
if ( !m_pHead )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CFunctor *pFunctor;
|
||||
|
||||
Elem_t *pCurrent = m_pHead;
|
||||
while ( pCurrent )
|
||||
{
|
||||
pFunctor = pCurrent->pFunctor;
|
||||
pFunctor->Release();
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
|
||||
m_Allocator.FreeAll( false );
|
||||
m_pHead = m_pTail = NULL;
|
||||
}
|
||||
|
||||
#define DEFINE_MATCALLQUEUE_NONMEMBER_QUEUE_CALL(N) \
|
||||
template <typename FUNCTION_RETTYPE FUNC_TEMPLATE_FUNC_PARAMS_##N FUNC_TEMPLATE_ARG_PARAMS_##N> \
|
||||
void QueueCall(FUNCTION_RETTYPE (*pfnProxied)( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
#define DEFINE_MATCALLQUEUE_MEMBER_QUEUE_CALL(N) \
|
||||
template <typename OBJECT_TYPE_PTR, typename FUNCTION_CLASS, typename FUNCTION_RETTYPE FUNC_TEMPLATE_FUNC_PARAMS_##N FUNC_TEMPLATE_ARG_PARAMS_##N> \
|
||||
void QueueCall(OBJECT_TYPE_PTR pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
#define DEFINE_MATCALLQUEUE_CONST_MEMBER_QUEUE_CALL(N) \
|
||||
template <typename OBJECT_TYPE_PTR, typename FUNCTION_CLASS, typename FUNCTION_RETTYPE FUNC_TEMPLATE_FUNC_PARAMS_##N FUNC_TEMPLATE_ARG_PARAMS_##N> \
|
||||
void QueueCall(OBJECT_TYPE_PTR pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_NONMEMBER_QUEUE_CALL );
|
||||
FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_MEMBER_QUEUE_CALL );
|
||||
FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_CONST_MEMBER_QUEUE_CALL );
|
||||
|
||||
private:
|
||||
void QueueFunctorInternal( CFunctor *pFunctor )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
pFunctor->m_nUserID = m_nCurSerialNumber++;
|
||||
#endif
|
||||
MEM_ALLOC_CREDIT_( "CMatCallQueue.m_Allocator" );
|
||||
Elem_t *pNew = (Elem_t *)m_Allocator.Alloc( sizeof(Elem_t) );
|
||||
if ( m_pTail )
|
||||
{
|
||||
m_pTail->pNext = pNew;
|
||||
m_pTail = pNew;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pHead = m_pTail = pNew;
|
||||
}
|
||||
pNew->pNext = NULL;
|
||||
pNew->pFunctor = pFunctor;
|
||||
}
|
||||
|
||||
struct Elem_t
|
||||
{
|
||||
Elem_t *pNext;
|
||||
CFunctor *pFunctor;
|
||||
};
|
||||
|
||||
Elem_t *m_pHead;
|
||||
Elem_t *m_pTail;
|
||||
|
||||
CMemoryStack m_Allocator;
|
||||
CCustomizedFunctorFactory<CMemoryStack, CRefCounted1<CFunctor, CRefCountServiceDestruct< CRefST > > > m_FunctorFactory;
|
||||
unsigned m_nCurSerialNumber;
|
||||
unsigned m_nBreakSerialNumber;
|
||||
};
|
||||
|
||||
#define MATCONFIG_FLAGS_SUPPORT_EDITOR ( 1 << 0 )
|
||||
#define MATCONFIG_FLAGS_SUPPORT_GBUFFER ( 1 << 1 )
|
||||
//-----------------------------------------------------------------------------
|
||||
// Additional interfaces used internally to the library
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IMaterialSystemInternal : public IMaterialSystem
|
||||
{
|
||||
public:
|
||||
// Returns the current material
|
||||
virtual IMaterial* GetCurrentMaterial() = 0;
|
||||
|
||||
virtual int GetLightmapPage( void ) = 0;
|
||||
|
||||
// Gets the maximum lightmap page size...
|
||||
virtual int GetLightmapWidth( int lightmap ) const = 0;
|
||||
virtual int GetLightmapHeight( int lightmap ) const = 0;
|
||||
|
||||
virtual ITexture *GetLocalCubemap( void ) = 0;
|
||||
|
||||
// virtual bool RenderZOnlyWithHeightClipEnabled( void ) = 0;
|
||||
virtual void ForceDepthFuncEquals( bool bEnable ) = 0;
|
||||
virtual enum MaterialHeightClipMode_t GetHeightClipMode( void ) = 0;
|
||||
|
||||
// FIXME: Remove? Here for debugging shaders in CShaderSystem
|
||||
virtual void AddMaterialToMaterialList( IMaterialInternal *pMaterial ) = 0;
|
||||
virtual void RemoveMaterial( IMaterialInternal *pMaterial ) = 0;
|
||||
virtual void RemoveMaterialSubRect( IMaterialInternal *pMaterial ) = 0;
|
||||
virtual bool InFlashlightMode() const = 0;
|
||||
|
||||
// Can we use editor materials?
|
||||
virtual bool CanUseEditorMaterials() const = 0;
|
||||
virtual int GetConfigurationFlags( void ) const = 0;
|
||||
virtual const char *GetForcedTextureLoadPathID() = 0;
|
||||
|
||||
virtual CMatCallQueue *GetRenderCallQueue() = 0;
|
||||
|
||||
virtual void UnbindMaterial( IMaterial *pMaterial ) = 0;
|
||||
virtual uint GetRenderThreadId() const = 0 ;
|
||||
};
|
||||
|
||||
|
||||
#endif // IMATERIALSYSTEMINTERNAL_H
|
|
@ -0,0 +1,21 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=====================================================================================//
|
||||
|
||||
#include "materialsystem_global.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shadersystem.h"
|
||||
#include <malloc.h>
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
int g_FrameNum;
|
||||
IShaderAPI *g_pShaderAPI = 0;
|
||||
IShaderDeviceMgr* g_pShaderDeviceMgr = 0;
|
||||
IShaderDevice *g_pShaderDevice = 0;
|
||||
IShaderShadow* g_pShaderShadow = 0;
|
||||
IClientMaterialSystem *g_pClientMaterialSystem = 0;
|
|
@ -0,0 +1,112 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef MATERIALSYSTEM_GLOBAL_H
|
||||
#define MATERIALSYSTEM_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "imaterialsysteminternal.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class ITextureInternal;
|
||||
class IShaderAPI;
|
||||
class IHardwareConfigInternal;
|
||||
class IShaderUtil;
|
||||
class IShaderShadow;
|
||||
class IShaderDeviceMgr;
|
||||
class IShaderDevice;
|
||||
class IShaderSystemInternal;
|
||||
class IMaterialInternal;
|
||||
class IColorCorrectionSystem;
|
||||
class IMaterialVar;
|
||||
class IClientMaterialSystem;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constants used by the system
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define MATERIAL_MAX_PATH 256
|
||||
|
||||
// GR - limits for blured image (HDR stuff)
|
||||
#define MAX_BLUR_IMAGE_WIDTH 256
|
||||
#define MAX_BLUR_IMAGE_HEIGHT 192
|
||||
|
||||
#define CLAMP_BLUR_IMAGE_WIDTH( _w ) ( ( _w < MAX_BLUR_IMAGE_WIDTH ) ? _w : MAX_BLUR_IMAGE_WIDTH )
|
||||
#define CLAMP_BLUR_IMAGE_HEIGHT( _h ) ( ( _h < MAX_BLUR_IMAGE_HEIGHT ) ? _h : MAX_BLUR_IMAGE_HEIGHT )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global structures
|
||||
//-----------------------------------------------------------------------------
|
||||
extern MaterialSystem_Config_t g_config;
|
||||
extern uint32 g_nDebugVarsSignature;
|
||||
|
||||
//extern MaterialSystem_ErrorFunc_t Error;
|
||||
//extern MaterialSystem_WarningFunc_t Warning;
|
||||
|
||||
extern int g_FrameNum;
|
||||
|
||||
extern IShaderAPI* g_pShaderAPI;
|
||||
extern IShaderDeviceMgr* g_pShaderDeviceMgr;
|
||||
extern IShaderDevice* g_pShaderDevice;
|
||||
extern IShaderShadow* g_pShaderShadow;
|
||||
extern IClientMaterialSystem *g_pClientMaterialSystem;
|
||||
|
||||
extern IMaterialInternal *g_pErrorMaterial;
|
||||
|
||||
IShaderSystemInternal* ShaderSystem();
|
||||
inline IShaderSystemInternal* ShaderSystem()
|
||||
{
|
||||
extern IShaderSystemInternal *g_pShaderSystem;
|
||||
return g_pShaderSystem;
|
||||
}
|
||||
|
||||
inline IHardwareConfigInternal *HardwareConfig()
|
||||
{
|
||||
extern IHardwareConfigInternal* g_pHWConfig;
|
||||
return g_pHWConfig;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Accessor to get at the material system
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IMaterialSystemInternal* MaterialSystem()
|
||||
{
|
||||
extern IMaterialSystemInternal *g_pInternalMaterialSystem;
|
||||
return g_pInternalMaterialSystem;
|
||||
}
|
||||
|
||||
inline IShaderUtil* ShaderUtil()
|
||||
{
|
||||
extern IShaderUtil *g_pShaderUtil;
|
||||
return g_pShaderUtil;
|
||||
}
|
||||
|
||||
extern IColorCorrectionSystem *g_pColorCorrectionSystem;
|
||||
inline IColorCorrectionSystem *ColorCorrectionSystem()
|
||||
{
|
||||
return g_pColorCorrectionSystem;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global methods related to material vars
|
||||
//-----------------------------------------------------------------------------
|
||||
void EnableThreadedMaterialVarAccess( bool bEnable, IMaterialVar **ppParams, int nVarCount );
|
||||
|
||||
|
||||
#endif // MATERIALSYSTEM_GLOBAL_H
|
|
@ -0,0 +1,191 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef LOCALD3DTYPES_H
|
||||
#define LOCALD3DTYPES_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( DX10 ) && !defined( POSIX )
|
||||
|
||||
#include <d3d10.h>
|
||||
#include <d3dx10.h>
|
||||
|
||||
struct IDirect3D10BaseTexture
|
||||
{
|
||||
ID3D10Resource *m_pBaseTexture;
|
||||
ID3D10ShaderResourceView *m_pSRView;
|
||||
ID3D10RenderTargetView *m_pRTView;
|
||||
};
|
||||
|
||||
class CDx10Types
|
||||
{
|
||||
public:
|
||||
typedef struct IDirect3D10BaseTexture IDirect3DTexture;
|
||||
// FIXME: What is this called now ?
|
||||
// typedef ID3D10TextureCube IDirect3DCubeTexture;
|
||||
typedef ID3D10Texture3D IDirect3DVolumeTexture;
|
||||
typedef ID3D10Device IDirect3DDevice;
|
||||
typedef D3D10_VIEWPORT D3DVIEWPORT;
|
||||
typedef ID3D10Buffer IDirect3DIndexBuffer;
|
||||
typedef ID3D10Buffer IDirect3DVertexBuffer;
|
||||
typedef ID3D10VertexShader IDirect3DVertexShader;
|
||||
typedef ID3D10PixelShader IDirect3DPixelShader;
|
||||
typedef ID3D10ShaderResourceView IDirect3DSurface;
|
||||
typedef ID3DX10Font ID3DXFont;
|
||||
typedef ID3D10Query ID3DQuery;
|
||||
|
||||
typedef ID3D10Device *LPDIRECT3DDEVICE;
|
||||
typedef ID3D10Buffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef ID3D10Buffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
#endif // defined( DX10 ) && !defined( POSIX )
|
||||
|
||||
|
||||
#if !defined( _X360 ) && !defined( POSIX )
|
||||
#ifdef _DEBUG
|
||||
#define D3D_DEBUG_INFO 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct IDirect3DTexture9;
|
||||
struct IDirect3DBaseTexture9;
|
||||
struct IDirect3DCubeTexture9;
|
||||
struct IDirect3D9;
|
||||
struct IDirect3DDevice9;
|
||||
struct IDirect3DSurface9;
|
||||
struct IDirect3DIndexBuffer9;
|
||||
struct IDirect3DVertexBuffer9;
|
||||
struct IDirect3DVertexShader9;
|
||||
struct IDirect3DPixelShader9;
|
||||
struct IDirect3DVolumeTexture9;
|
||||
|
||||
typedef struct _D3DLIGHT9 D3DLIGHT9;
|
||||
typedef struct _D3DADAPTER_IDENTIFIER9 D3DADAPTER_IDENTIFIER9;
|
||||
typedef struct _D3DCAPS9 D3DCAPS9;
|
||||
typedef struct _D3DVIEWPORT9 D3DVIEWPORT9;
|
||||
typedef struct _D3DMATERIAL9 D3DMATERIAL9;
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
|
||||
class CDx9Types
|
||||
{
|
||||
public:
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
typedef void *HardwareShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The vertex and pixel shader type
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int VertexShader_t;
|
||||
typedef int PixelShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Bitpattern for an invalid shader
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INVALID_SHADER ( 0xFFFFFFFF )
|
||||
#define INVALID_HARDWARE_SHADER ( NULL )
|
||||
|
||||
#define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD
|
||||
#define D3DRS_NOTSUPPORTED D3DRS_FORCE_DWORD
|
||||
|
||||
//#include "dxabstract.h"
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
// not supported, keeping for port ease
|
||||
#define D3DSAMP_SRGBTEXTURE D3DSAMP_NOTSUPPORTED
|
||||
#define D3DRS_LIGHTING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DIFFUSEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SHADEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LASTPIXEL D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DITHERENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGCOLOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGTABLEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGSTART D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGDENSITY D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_RANGEFOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TEXTUREFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_CLIPPING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENT D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGVERTEXMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_COLORVERTEX D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LOCALVIEWER D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALIZENORMALS D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENTMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_EMISSIVEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_VERTEXBLEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_A D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_B D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_C D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_PATCHEDGESTYLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DEBUGMONITORTOKEN D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_INDEXEDVERTEXBLENDENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TWEENFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POSITIONDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ANTIALIASEDLINEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_X D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Y D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Z D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_W D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ENABLEADAPTIVETESSELLATION D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SRGBWRITEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DLOCK_DISCARD 0
|
||||
#define D3DUSAGE_DYNAMIC 0
|
||||
#define D3DUSAGE_AUTOGENMIPMAP 0
|
||||
#define D3DDEVTYPE_REF D3DDEVTYPE_HAL
|
||||
#define D3DENUM_WHQL_LEVEL 0
|
||||
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING D3DCREATE_HARDWARE_VERTEXPROCESSING
|
||||
#define D3DDMT_ENABLE 0
|
||||
|
||||
typedef enum D3DSHADEMODE
|
||||
{
|
||||
D3DSHADE_FLAT = 0,
|
||||
D3DSHADE_GOURAUD = 0,
|
||||
};
|
||||
|
||||
#endif // _X360
|
||||
|
||||
#endif // LOCALD3DTYPES_H
|
|
@ -0,0 +1,985 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "shaderlib/BaseShader.h"
|
||||
#include "shaderlib/ShaderDLL.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "shaderDLL_Global.h"
|
||||
#include "../IShaderSystem.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "materialsystem/itexture.h"
|
||||
#include "materialsystem/ishaderapi.h"
|
||||
#include "materialsystem/materialsystem_config.h"
|
||||
#include "shaderlib/cshader.h"
|
||||
#include "shaderlib/commandbuilder.h"
|
||||
#include "renderparm.h"
|
||||
#include "mathlib/vmatrix.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "convar.h"
|
||||
#include "tier0/vprof.h"
|
||||
|
||||
// NOTE: This must be the last include file in a .cpp file!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Storage buffer used for instance command buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPerInstanceContextData : public CBasePerInstanceContextData
|
||||
{
|
||||
public:
|
||||
CPerInstanceContextData() : m_pCommandBuffer( NULL ), m_nSize( 0 ) {}
|
||||
virtual ~CPerInstanceContextData()
|
||||
{
|
||||
if ( m_pCommandBuffer )
|
||||
{
|
||||
delete m_pCommandBuffer;
|
||||
}
|
||||
}
|
||||
unsigned char *m_pCommandBuffer;
|
||||
int m_nSize;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CBaseShader::s_pTextureGroupName = NULL;
|
||||
IMaterialVar **CBaseShader::s_ppParams;
|
||||
IShaderShadow *CBaseShader::s_pShaderShadow;
|
||||
IShaderDynamicAPI *CBaseShader::s_pShaderAPI;
|
||||
IShaderInit *CBaseShader::s_pShaderInit;
|
||||
int CBaseShader::s_nModulationFlags;
|
||||
int CBaseShader::s_nPassCount = 0;
|
||||
CPerInstanceContextData** CBaseShader::s_pInstanceDataPtr = NULL;
|
||||
static bool s_bBuildingInstanceCommandBuffer = false;
|
||||
static CInstanceCommandBufferBuilder< CFixedCommandStorageBuffer< 512 > > s_InstanceCommandBuffer;
|
||||
|
||||
bool g_shaderConfigDumpEnable = false; //true; //DO NOT CHECK IN ENABLED FIXME
|
||||
static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CBaseShader::CBaseShader()
|
||||
{
|
||||
GetShaderDLL()->InsertShader( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shader parameter info
|
||||
//-----------------------------------------------------------------------------
|
||||
// Look in BaseShader.h for the enumeration for these.
|
||||
// Update there if you update here.
|
||||
static ShaderParamInfo_t s_StandardParams[NUM_SHADER_MATERIAL_VARS] =
|
||||
{
|
||||
{ "$flags", "flags", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$flags_defined", "flags_defined", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$flags2", "flags2", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$flags_defined2", "flags2_defined", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$color", "color", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 },
|
||||
{ "$alpha", "alpha", SHADER_PARAM_TYPE_FLOAT, "1.0", 0 },
|
||||
{ "$basetexture", "Base Texture with lighting built in", SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", 0 },
|
||||
{ "$frame", "Animation Frame", SHADER_PARAM_TYPE_INTEGER, "0", 0 },
|
||||
{ "$basetexturetransform", "Base Texture Texcoord Transform",SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", 0 },
|
||||
{ "$flashlighttexture", "flashlight spotlight shape texture", SHADER_PARAM_TYPE_TEXTURE, "effects/flashlight001", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$flashlighttextureframe", "Animation Frame for $flashlight", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE },
|
||||
{ "$color2", "color2", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 },
|
||||
{ "$srgbtint", "tint value to be applied when running on new-style srgb parts", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 },
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the standard shader parameter names
|
||||
// FIXME: Turn this into one function?
|
||||
//-----------------------------------------------------------------------------
|
||||
int CBaseShader::GetParamCount( ) const
|
||||
{
|
||||
return NUM_SHADER_MATERIAL_VARS;
|
||||
}
|
||||
|
||||
const ShaderParamInfo_t &CBaseShader::GetParamInfo( int nParamIndex ) const
|
||||
{
|
||||
Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS );
|
||||
return s_StandardParams[nParamIndex];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Necessary to snag ahold of some important data for the helper methods
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::InitShaderParams( IMaterialVar** ppParams, const char *pMaterialName )
|
||||
{
|
||||
// Re-entrancy check
|
||||
Assert( !s_ppParams );
|
||||
|
||||
s_ppParams = ppParams;
|
||||
|
||||
OnInitShaderParams( ppParams, pMaterialName );
|
||||
|
||||
s_ppParams = NULL;
|
||||
}
|
||||
|
||||
void CBaseShader::InitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName, const char *pTextureGroupName )
|
||||
{
|
||||
// Re-entrancy check
|
||||
Assert( !s_ppParams );
|
||||
|
||||
s_ppParams = ppParams;
|
||||
s_pShaderInit = pShaderInit;
|
||||
s_pTextureGroupName = pTextureGroupName;
|
||||
|
||||
OnInitShaderInstance( ppParams, pShaderInit, pMaterialName );
|
||||
|
||||
s_pTextureGroupName = NULL;
|
||||
s_ppParams = NULL;
|
||||
s_pShaderInit = NULL;
|
||||
}
|
||||
|
||||
void CBaseShader::DrawElements( IMaterialVar **ppParams, int nModulationFlags,
|
||||
IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, CBasePerInstanceContextData** pInstanceDataPtr )
|
||||
{
|
||||
VPROF("CBaseShader::DrawElements");
|
||||
// Re-entrancy check
|
||||
Assert( !s_ppParams );
|
||||
|
||||
s_ppParams = ppParams;
|
||||
s_pShaderAPI = pShaderAPI;
|
||||
s_pShaderShadow = pShaderShadow;
|
||||
s_nModulationFlags = nModulationFlags;
|
||||
s_pInstanceDataPtr = (CPerInstanceContextData**)( pInstanceDataPtr );
|
||||
s_nPassCount = 0;
|
||||
|
||||
if ( IsSnapshotting() )
|
||||
{
|
||||
// Set up the shadow state
|
||||
SetInitialShadowState( );
|
||||
}
|
||||
|
||||
OnDrawElements( ppParams, pShaderShadow, pShaderAPI, vertexCompression, pContextDataPtr );
|
||||
|
||||
s_pInstanceDataPtr = NULL;
|
||||
s_nPassCount = 0;
|
||||
s_nModulationFlags = 0;
|
||||
s_ppParams = NULL;
|
||||
s_pShaderAPI = NULL;
|
||||
s_pShaderShadow = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the default shadow state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::SetInitialShadowState( )
|
||||
{
|
||||
// Set the default state
|
||||
s_pShaderShadow->SetDefaultState();
|
||||
|
||||
// Init the standard states...
|
||||
int flags = s_ppParams[FLAGS]->GetIntValue();
|
||||
if (flags & MATERIAL_VAR_IGNOREZ)
|
||||
{
|
||||
s_pShaderShadow->EnableDepthTest( false );
|
||||
s_pShaderShadow->EnableDepthWrites( false );
|
||||
}
|
||||
|
||||
if (flags & MATERIAL_VAR_DECAL)
|
||||
{
|
||||
s_pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
|
||||
s_pShaderShadow->EnableDepthWrites( false );
|
||||
}
|
||||
|
||||
if (flags & MATERIAL_VAR_NOCULL)
|
||||
{
|
||||
s_pShaderShadow->EnableCulling( false );
|
||||
}
|
||||
|
||||
if (flags & MATERIAL_VAR_ZNEARER)
|
||||
{
|
||||
s_pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEARER );
|
||||
}
|
||||
|
||||
if (flags & MATERIAL_VAR_WIREFRAME)
|
||||
{
|
||||
s_pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE );
|
||||
}
|
||||
|
||||
// Set alpha to coverage
|
||||
if (flags & MATERIAL_VAR_ALLOWALPHATOCOVERAGE)
|
||||
{
|
||||
// Force the bit on and then check against alpha blend and test states in CShaderShadowDX8::ComputeAggregateShadowState()
|
||||
s_pShaderShadow->EnableAlphaToCoverage( true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws a snapshot
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::Draw( bool bMakeActualDrawCall )
|
||||
{
|
||||
// You forgot to call PI_EndCommandBuffer
|
||||
Assert( !s_bBuildingInstanceCommandBuffer );
|
||||
|
||||
if ( IsSnapshotting() )
|
||||
{
|
||||
// Turn off transparency if we're asked to....
|
||||
if (g_pConfig->bNoTransparency &&
|
||||
((s_ppParams[FLAGS]->GetIntValue() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) == 0))
|
||||
{
|
||||
s_pShaderShadow->EnableDepthWrites( true );
|
||||
s_pShaderShadow->EnableBlending( false );
|
||||
}
|
||||
|
||||
GetShaderSystem()->TakeSnapshot();
|
||||
|
||||
// Automagically add skinning + vertex lighting
|
||||
if ( !s_pInstanceDataPtr[s_nPassCount] )
|
||||
{
|
||||
bool bIsSkinning = CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
|
||||
bool bIsVertexLit = CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
|
||||
if ( bIsSkinning || bIsVertexLit )
|
||||
{
|
||||
PI_BeginCommandBuffer();
|
||||
|
||||
// NOTE: EndCommandBuffer will insert the appropriate commands
|
||||
PI_EndCommandBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetShaderSystem()->DrawSnapshot( s_pInstanceDataPtr[s_nPassCount] ?
|
||||
s_pInstanceDataPtr[s_nPassCount]->m_pCommandBuffer : NULL, bMakeActualDrawCall );
|
||||
}
|
||||
|
||||
++s_nPassCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods related to building per-instance command buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::PI_BeginCommandBuffer()
|
||||
{
|
||||
// NOTE: This assertion is here because the memory allocation strategy
|
||||
// is perhaps not the best if this is used in dynamic states; we should
|
||||
// rethink in that case.
|
||||
Assert( IsSnapshotting() );
|
||||
|
||||
Assert( !s_bBuildingInstanceCommandBuffer );
|
||||
s_bBuildingInstanceCommandBuffer = true;
|
||||
s_InstanceCommandBuffer.Reset();
|
||||
}
|
||||
|
||||
void CBaseShader::PI_EndCommandBuffer()
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
|
||||
// Automagically add skinning
|
||||
if ( CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_SUPPORTS_HW_SKINNING ) )
|
||||
{
|
||||
PI_SetSkinningMatrices();
|
||||
}
|
||||
|
||||
if ( CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_LIGHTING_VERTEX_LIT ) )
|
||||
{
|
||||
PI_SetVertexShaderLocalLighting();
|
||||
}
|
||||
|
||||
s_bBuildingInstanceCommandBuffer = false;
|
||||
s_InstanceCommandBuffer.End();
|
||||
int nSize = s_InstanceCommandBuffer.Size();
|
||||
if ( nSize > 0 )
|
||||
{
|
||||
CPerInstanceContextData *pContextData = s_pInstanceDataPtr[ s_nPassCount ];
|
||||
if ( !pContextData )
|
||||
{
|
||||
pContextData = new CPerInstanceContextData;
|
||||
s_pInstanceDataPtr[ s_nPassCount ] = pContextData;
|
||||
}
|
||||
unsigned char *pBuf = pContextData->m_pCommandBuffer;
|
||||
if ( pContextData->m_nSize < nSize )
|
||||
{
|
||||
if ( pContextData->m_pCommandBuffer )
|
||||
{
|
||||
delete pContextData->m_pCommandBuffer;
|
||||
}
|
||||
pBuf = new unsigned char[nSize];
|
||||
pContextData->m_pCommandBuffer = pBuf;
|
||||
pContextData->m_nSize = nSize;
|
||||
}
|
||||
memcpy( pBuf, s_InstanceCommandBuffer.Base(), nSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Queues commands onto the instance command buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::PI_SetPixelShaderAmbientLightCube( int nFirstRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetPixelShaderAmbientLightCube( nFirstRegister );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetPixelShaderLocalLighting( int nFirstRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetPixelShaderLocalLighting( nFirstRegister );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetVertexShaderAmbientLightCube( /*int nFirstRegister*/ )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetVertexShaderAmbientLightCube( /*nFirstRegister*/ );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetVertexShaderLocalLighting()
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetVertexShaderLocalLighting( );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetSkinningMatrices()
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetSkinningMatrices();
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetPixelShaderAmbientLightCubeLuminance( int nFirstRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetPixelShaderAmbientLightCubeLuminance( nFirstRegister );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetPixelShaderGlintDamping( int nFirstRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetPixelShaderGlintDamping( nFirstRegister );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int nRegister, float scale )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( nRegister, color2, scale );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState_LinearScale( int nRegister, float scale )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState_LinearScale( nRegister, color2, scale );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState_LinearScale_ScaleInW( int nRegister, float scale )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState_LinearScale_ScaleInW( nRegister, color2, scale );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState_LinearColorSpace( int nRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState_LinearColorSpace( nRegister, color2 );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState( int nRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState( nRegister, color2 );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationVertexShaderDynamicState()
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationVertexShaderDynamicState( VERTEX_SHADER_MODULATION_COLOR, color2 );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationVertexShaderDynamicState_LinearScale( float flScale )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
Vector color2( 1.0f, 1.0f, 1.0f );
|
||||
ApplyColor2Factor( color2.Base() );
|
||||
s_InstanceCommandBuffer.SetModulationVertexShaderDynamicState_LinearScale( VERTEX_SHADER_MODULATION_COLOR, color2, flScale );
|
||||
}
|
||||
|
||||
void CBaseShader::PI_SetModulationPixelShaderDynamicState_Identity( int nRegister )
|
||||
{
|
||||
Assert( s_bBuildingInstanceCommandBuffer );
|
||||
s_InstanceCommandBuffer.SetModulationPixelShaderDynamicState_Identity( nRegister );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds a particular parameter (works because the lowest parameters match the shader)
|
||||
//-----------------------------------------------------------------------------
|
||||
int CBaseShader::FindParamIndex( const char *pName ) const
|
||||
{
|
||||
int numParams = GetParamCount();
|
||||
for( int i = 0; i < numParams; i++ )
|
||||
{
|
||||
if( Q_strnicmp( GetParamInfo( i ).m_pName, pName, 64 ) == 0 )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we using graphics?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::IsUsingGraphics()
|
||||
{
|
||||
return GetShaderSystem()->IsUsingGraphics();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we using graphics?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::CanUseEditorMaterials() const
|
||||
{
|
||||
return GetShaderSystem()->CanUseEditorMaterials();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads a texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::LoadTexture( int nTextureVar )
|
||||
{
|
||||
if ((!s_ppParams) || (nTextureVar == -1))
|
||||
return;
|
||||
|
||||
IMaterialVar* pNameVar = s_ppParams[nTextureVar];
|
||||
if( pNameVar && pNameVar->IsDefined() )
|
||||
{
|
||||
s_pShaderInit->LoadTexture( pNameVar, s_pTextureGroupName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads a bumpmap
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::LoadBumpMap( int nTextureVar )
|
||||
{
|
||||
if ((!s_ppParams) || (nTextureVar == -1))
|
||||
return;
|
||||
|
||||
IMaterialVar* pNameVar = s_ppParams[nTextureVar];
|
||||
if( pNameVar && pNameVar->IsDefined() )
|
||||
{
|
||||
s_pShaderInit->LoadBumpMap( pNameVar, s_pTextureGroupName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads a cubemap
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::LoadCubeMap( int nTextureVar )
|
||||
{
|
||||
if ((!s_ppParams) || (nTextureVar == -1))
|
||||
return;
|
||||
|
||||
IMaterialVar* pNameVar = s_ppParams[nTextureVar];
|
||||
if( pNameVar && pNameVar->IsDefined() )
|
||||
{
|
||||
s_pShaderInit->LoadCubeMap( s_ppParams, pNameVar );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( int nTextureVar, int nFrameVar, int nTextureChannel )
|
||||
{
|
||||
Assert( !IsSnapshotting() );
|
||||
Assert( nTextureVar != -1 );
|
||||
Assert ( s_ppParams );
|
||||
|
||||
IMaterialVar* pTextureVar = s_ppParams[nTextureVar];
|
||||
IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL;
|
||||
int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0;
|
||||
return GetShaderSystem()->GetShaderAPITextureBindHandle( pTextureVar->GetTextureValue(), nFrame, nTextureChannel );
|
||||
}
|
||||
|
||||
void CBaseShader::BindVertexTexture( VertexTextureSampler_t vtSampler, int nTextureVar, int nFrame /* = 0 */)
|
||||
{
|
||||
Assert( !IsSnapshotting() );
|
||||
|
||||
IMaterialVar* pTextureVar = s_ppParams[nTextureVar];
|
||||
if ( !pTextureVar )
|
||||
return;
|
||||
|
||||
GetShaderSystem()->BindVertexTexture( vtSampler, pTextureVar->GetTextureValue() );
|
||||
}
|
||||
|
||||
ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel )
|
||||
{
|
||||
return GetShaderSystem()->GetShaderAPITextureBindHandle( pTexture, nFrame, nTextureChannel );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Four different flavors of BindTexture(), handling the two-sampler
|
||||
// case as well as ITexture* versus textureVar forms
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CBaseShader::BindTexture( Sampler_t sampler1, int nTextureVar, int nFrameVar /* = -1 */ )
|
||||
{
|
||||
BindTexture( sampler1, (Sampler_t) -1, nTextureVar, nFrameVar );
|
||||
}
|
||||
|
||||
|
||||
void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, int nTextureVar, int nFrameVar /* = -1 */ )
|
||||
{
|
||||
Assert( !IsSnapshotting() );
|
||||
Assert( nTextureVar != -1 );
|
||||
Assert ( s_ppParams );
|
||||
|
||||
IMaterialVar* pTextureVar = s_ppParams[nTextureVar];
|
||||
IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL;
|
||||
if (pTextureVar)
|
||||
{
|
||||
int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0;
|
||||
|
||||
if ( sampler2 == -1 )
|
||||
{
|
||||
GetShaderSystem()->BindTexture( sampler1, pTextureVar->GetTextureValue(), nFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
GetShaderSystem()->BindTexture( sampler1, sampler2, pTextureVar->GetTextureValue(), nFrame );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CBaseShader::BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrame /* = 0 */ )
|
||||
{
|
||||
BindTexture( sampler1, (Sampler_t) -1, pTexture, nFrame );
|
||||
}
|
||||
|
||||
void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame /* = 0 */ )
|
||||
{
|
||||
Assert( !IsSnapshotting() );
|
||||
|
||||
if ( sampler2 == -1 )
|
||||
{
|
||||
GetShaderSystem()->BindTexture( sampler1, pTexture, nFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
GetShaderSystem()->BindTexture( sampler1, sampler2, pTexture, nFrame );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Does the texture store translucency in its alpha channel?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::TextureIsTranslucent( int textureVar, bool isBaseTexture )
|
||||
{
|
||||
if (textureVar < 0)
|
||||
return false;
|
||||
|
||||
IMaterialVar** params = s_ppParams;
|
||||
if (params[textureVar]->GetType() == MATERIAL_VAR_TYPE_TEXTURE)
|
||||
{
|
||||
if (!isBaseTexture)
|
||||
{
|
||||
return params[textureVar]->GetTextureValue()->IsTranslucent();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Override translucency settings if this flag is set.
|
||||
if (IS_FLAG_SET(MATERIAL_VAR_OPAQUETEXTURE))
|
||||
return false;
|
||||
|
||||
bool bHasSelfIllum = ( ( CurrentMaterialVarFlags() & MATERIAL_VAR_SELFILLUM ) != 0 );
|
||||
bool bHasSelfIllumMask = ( ( CurrentMaterialVarFlags2() & MATERIAL_VAR2_SELFILLUMMASK ) != 0 );
|
||||
bool bHasBaseAlphaEnvmapMask = ( ( CurrentMaterialVarFlags() & MATERIAL_VAR_BASEALPHAENVMAPMASK ) != 0 );
|
||||
bool bUsingBaseTextureAlphaForSelfIllum = bHasSelfIllum && !bHasSelfIllumMask;
|
||||
// Check if we are using base texture alpha for something other than translucency.
|
||||
if ( !bUsingBaseTextureAlphaForSelfIllum && !bHasBaseAlphaEnvmapMask )
|
||||
{
|
||||
// We aren't using base alpha for anything other than trancluceny.
|
||||
|
||||
// check if the material is marked as translucent or alpha test.
|
||||
if ((CurrentMaterialVarFlags() & MATERIAL_VAR_TRANSLUCENT) ||
|
||||
(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST))
|
||||
{
|
||||
// Make sure the texture has an alpha channel.
|
||||
return params[textureVar]->GetTextureValue()->IsTranslucent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Helper methods for color modulation
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we alpha or color modulating?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::IsAlphaModulating()
|
||||
{
|
||||
return (s_nModulationFlags & SHADER_USING_ALPHA_MODULATION) != 0;
|
||||
}
|
||||
// FIXME: Figure out a better way to do this?
|
||||
//-----------------------------------------------------------------------------
|
||||
int CBaseShader::ComputeModulationFlags( IMaterialVar** params, IShaderDynamicAPI* pShaderAPI )
|
||||
{
|
||||
s_pShaderAPI = pShaderAPI;
|
||||
|
||||
int mod = 0;
|
||||
if( UsingFlashlight(params) )
|
||||
{
|
||||
mod |= SHADER_USING_FLASHLIGHT;
|
||||
}
|
||||
|
||||
if ( UsingEditor(params) )
|
||||
{
|
||||
mod |= SHADER_USING_EDITOR;
|
||||
}
|
||||
|
||||
if( IS_FLAG2_SET( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ) )
|
||||
{
|
||||
AssertOnce( IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ) );
|
||||
if( IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ) )
|
||||
{
|
||||
mod |= SHADER_USING_FIXED_FUNCTION_BAKED_LIGHTING;
|
||||
}
|
||||
}
|
||||
|
||||
if ( IsSnapshotting() )
|
||||
{
|
||||
if ( IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) )
|
||||
mod |= SHADER_USING_GBUFFER0;
|
||||
if ( IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 ) )
|
||||
mod |= SHADER_USING_GBUFFER1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nFixedLightingMode = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_ENABLE_FIXED_LIGHTING );
|
||||
if ( nFixedLightingMode & 1 )
|
||||
mod |= SHADER_USING_GBUFFER0;
|
||||
if ( nFixedLightingMode & 2 )
|
||||
mod |= SHADER_USING_GBUFFER1;
|
||||
}
|
||||
s_pShaderAPI = NULL;
|
||||
return mod;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
|
||||
{
|
||||
return CShader_IsFlag2Set( params, MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::NeedsFullFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
|
||||
{
|
||||
return CShader_IsFlag2Set( params, MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBaseShader::IsTranslucent( IMaterialVar **params ) const
|
||||
{
|
||||
return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the translucency...
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::ApplyColor2Factor( float *pColorOut ) const // (*pColorOut) *= COLOR2
|
||||
{
|
||||
if ( !g_pConfig->bShowDiffuse )
|
||||
{
|
||||
pColorOut[0] = pColorOut[1] = pColorOut[2] = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
IMaterialVar* pColor2Var = s_ppParams[COLOR2];
|
||||
if ( pColor2Var->GetType() == MATERIAL_VAR_TYPE_VECTOR )
|
||||
{
|
||||
float flColor2[3];
|
||||
pColor2Var->GetVecValue( flColor2, 3 );
|
||||
|
||||
pColorOut[0] *= flColor2[0];
|
||||
pColorOut[1] *= flColor2[1];
|
||||
pColorOut[2] *= flColor2[2];
|
||||
}
|
||||
if ( g_pHardwareConfig->UsesSRGBCorrectBlending() )
|
||||
{
|
||||
IMaterialVar* pSRGBVar = s_ppParams[SRGBTINT];
|
||||
if (pSRGBVar->GetType() == MATERIAL_VAR_TYPE_VECTOR)
|
||||
{
|
||||
float flSRGB[3];
|
||||
pSRGBVar->GetVecValue( flSRGB, 3 );
|
||||
|
||||
pColorOut[0] *= flSRGB[0];
|
||||
pColorOut[1] *= flSRGB[1];
|
||||
pColorOut[2] *= flSRGB[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Helper methods for alpha blending....
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::EnableAlphaBlending( ShaderBlendFactor_t src, ShaderBlendFactor_t dst )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
s_pShaderShadow->EnableBlending( true );
|
||||
s_pShaderShadow->BlendFunc( src, dst );
|
||||
s_pShaderShadow->EnableDepthWrites(false);
|
||||
}
|
||||
|
||||
void CBaseShader::DisableAlphaBlending()
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
s_pShaderShadow->EnableBlending( false );
|
||||
}
|
||||
|
||||
void CBaseShader::SetNormalBlendingShadowState( int textureVar, bool isBaseTexture )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
|
||||
// Either we've got a constant modulation
|
||||
bool isTranslucent = IsAlphaModulating();
|
||||
|
||||
// Or we've got a vertex alpha
|
||||
isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA);
|
||||
|
||||
// Or we've got a texture alpha
|
||||
isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) &&
|
||||
!(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) );
|
||||
|
||||
if (isTranslucent)
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableAlphaBlending();
|
||||
}
|
||||
}
|
||||
|
||||
//ConVar mat_debug_flashlight_only( "mat_debug_flashlight_only", "0" );
|
||||
void CBaseShader::SetAdditiveBlendingShadowState( int textureVar, bool isBaseTexture )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
|
||||
// Either we've got a constant modulation
|
||||
bool isTranslucent = IsAlphaModulating();
|
||||
|
||||
// Or we've got a vertex alpha
|
||||
isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA);
|
||||
|
||||
// Or we've got a texture alpha
|
||||
isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) &&
|
||||
!(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) );
|
||||
|
||||
/*
|
||||
if ( mat_debug_flashlight_only.GetBool() )
|
||||
{
|
||||
if (isTranslucent)
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
//s_pShaderShadow->EnableAlphaTest( true );
|
||||
//s_pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.99f );
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ZERO);
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
if (isTranslucent)
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBaseShader::SetDefaultBlendingShadowState( int textureVar, bool isBaseTexture )
|
||||
{
|
||||
if ( CurrentMaterialVarFlags() & MATERIAL_VAR_ADDITIVE )
|
||||
{
|
||||
SetAdditiveBlendingShadowState( textureVar, isBaseTexture );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetNormalBlendingShadowState( textureVar, isBaseTexture );
|
||||
}
|
||||
}
|
||||
|
||||
void CBaseShader::SetBlendingShadowState( BlendType_t nMode )
|
||||
{
|
||||
switch ( nMode )
|
||||
{
|
||||
case BT_NONE:
|
||||
DisableAlphaBlending();
|
||||
break;
|
||||
|
||||
case BT_BLEND:
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
break;
|
||||
|
||||
case BT_ADD:
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
|
||||
break;
|
||||
|
||||
case BT_BLENDADD:
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets lightmap blending mode for single texturing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::SingleTextureLightmapBlendMode( )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
|
||||
s_pShaderShadow->EnableBlending( true );
|
||||
s_pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );
|
||||
}
|
||||
|
||||
FORCEINLINE void CBaseShader::SetFogMode( ShaderFogMode_t fogMode )
|
||||
{
|
||||
if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0)
|
||||
{
|
||||
bool bVertexFog = ( ( CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXFOG ) != 0 );
|
||||
s_pShaderShadow->FogMode( fogMode, bVertexFog );
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED, false );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Helper methods for fog
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseShader::FogToOOOverbright( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
SetFogMode( SHADER_FOGMODE_OO_OVERBRIGHT );
|
||||
}
|
||||
|
||||
void CBaseShader::FogToWhite( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
SetFogMode( SHADER_FOGMODE_WHITE );
|
||||
}
|
||||
void CBaseShader::FogToBlack( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
SetFogMode( SHADER_FOGMODE_BLACK );
|
||||
}
|
||||
|
||||
void CBaseShader::FogToGrey( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
SetFogMode( SHADER_FOGMODE_GREY );
|
||||
}
|
||||
|
||||
void CBaseShader::FogToFogColor( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
SetFogMode( SHADER_FOGMODE_FOGCOLOR );
|
||||
}
|
||||
|
||||
void CBaseShader::DisableFog( void )
|
||||
{
|
||||
Assert( IsSnapshotting() );
|
||||
s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED, false );
|
||||
}
|
||||
|
||||
void CBaseShader::DefaultFog( void )
|
||||
{
|
||||
if ( CurrentMaterialVarFlags() & MATERIAL_VAR_ADDITIVE )
|
||||
{
|
||||
FogToBlack();
|
||||
}
|
||||
else
|
||||
{
|
||||
FogToFogColor();
|
||||
}
|
||||
}
|
||||
|
||||
bool CBaseShader::UsingFlashlight( IMaterialVar **params ) const
|
||||
{
|
||||
if( IsSnapshotting() )
|
||||
{
|
||||
return CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT );
|
||||
}
|
||||
else
|
||||
{
|
||||
return s_pShaderAPI->InFlashlightMode();
|
||||
}
|
||||
}
|
||||
|
||||
bool CBaseShader::UsingEditor( IMaterialVar **params ) const
|
||||
{
|
||||
if( IsSnapshotting() )
|
||||
{
|
||||
return CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_EDITOR );
|
||||
}
|
||||
else
|
||||
{
|
||||
return s_pShaderAPI->InEditorMode();
|
||||
}
|
||||
}
|
||||
|
||||
bool CBaseShader::IsHDREnabled( void )
|
||||
{
|
||||
// HDRFIXME! Need to fix this for vgui materials
|
||||
HDRType_t hdr_mode = g_pHardwareConfig->GetHDRType();
|
||||
return ( hdr_mode == HDR_TYPE_INTEGER ) || ( hdr_mode == HDR_TYPE_FLOAT );
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "shaderlib/ShaderDLL.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "materialsystem/materialsystem_config.h"
|
||||
#include "IShaderSystem.h"
|
||||
#include "materialsystem/ishaderapi.h"
|
||||
#include "shaderlib_cvar.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The standard implementation of CShaderDLL
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDLL : public IShaderDLLInternal, public IShaderDLL
|
||||
{
|
||||
public:
|
||||
CShaderDLL();
|
||||
|
||||
// methods of IShaderDLL
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual int ShaderCount() const;
|
||||
virtual IShader *GetShader( int nShader );
|
||||
|
||||
// methods of IShaderDLLInternal
|
||||
virtual bool Connect( CreateInterfaceFn factory, bool bIsMaterialSystem );
|
||||
virtual void Disconnect( bool bIsMaterialSystem );
|
||||
virtual void InsertShader( IShader *pShader );
|
||||
|
||||
private:
|
||||
CUtlVector< IShader * > m_ShaderList;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces/structures
|
||||
//-----------------------------------------------------------------------------
|
||||
IMaterialSystemHardwareConfig* g_pHardwareConfig;
|
||||
const MaterialSystem_Config_t *g_pConfig;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interfaces/structures local to shaderlib
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderSystem* g_pSLShaderSystem;
|
||||
|
||||
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
static CShaderDLL *s_pShaderDLL;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderDLL *GetShaderDLL()
|
||||
{
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
if ( !s_pShaderDLL )
|
||||
{
|
||||
s_pShaderDLL = new CShaderDLL;
|
||||
}
|
||||
|
||||
return s_pShaderDLL;
|
||||
}
|
||||
|
||||
IShaderDLLInternal *GetShaderDLLInternal()
|
||||
{
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
if ( !s_pShaderDLL )
|
||||
{
|
||||
s_pShaderDLL = new CShaderDLL;
|
||||
}
|
||||
|
||||
return static_cast<IShaderDLLInternal*>( s_pShaderDLL );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface
|
||||
//-----------------------------------------------------------------------------
|
||||
EXPOSE_INTERFACE_FN( (InstantiateInterfaceFn)GetShaderDLLInternal, IShaderDLLInternal, SHADER_DLL_INTERFACE_VERSION );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderDLL::CShaderDLL()
|
||||
{
|
||||
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CShaderDLL::Connect( CreateInterfaceFn factory, bool bIsMaterialSystem )
|
||||
{
|
||||
g_pHardwareConfig = (IMaterialSystemHardwareConfig*)factory( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, NULL );
|
||||
g_pConfig = (const MaterialSystem_Config_t*)factory( MATERIALSYSTEM_CONFIG_VERSION, NULL );
|
||||
g_pSLShaderSystem = (IShaderSystem*)factory( SHADERSYSTEM_INTERFACE_VERSION, NULL );
|
||||
|
||||
if ( !bIsMaterialSystem )
|
||||
{
|
||||
ConnectTier1Libraries( &factory, 1 );
|
||||
InitShaderLibCVars( factory );
|
||||
}
|
||||
|
||||
return ( g_pConfig != NULL ) && (g_pHardwareConfig != NULL) && ( g_pSLShaderSystem != NULL );
|
||||
}
|
||||
|
||||
void CShaderDLL::Disconnect( bool bIsMaterialSystem )
|
||||
{
|
||||
if ( !bIsMaterialSystem )
|
||||
{
|
||||
ConVar_Unregister();
|
||||
DisconnectTier1Libraries();
|
||||
}
|
||||
|
||||
g_pHardwareConfig = NULL;
|
||||
g_pConfig = NULL;
|
||||
g_pSLShaderSystem = NULL;
|
||||
}
|
||||
|
||||
bool CShaderDLL::Connect( CreateInterfaceFn factory )
|
||||
{
|
||||
return Connect( factory, false );
|
||||
}
|
||||
|
||||
void CShaderDLL::Disconnect()
|
||||
{
|
||||
Disconnect( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iterates over all shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
int CShaderDLL::ShaderCount() const
|
||||
{
|
||||
return m_ShaderList.Count();
|
||||
}
|
||||
|
||||
IShader *CShaderDLL::GetShader( int nShader )
|
||||
{
|
||||
if ( ( nShader < 0 ) || ( nShader >= m_ShaderList.Count() ) )
|
||||
return NULL;
|
||||
|
||||
return m_ShaderList[nShader];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds to the shader lists
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderDLL::InsertShader( IShader *pShader )
|
||||
{
|
||||
Assert( pShader );
|
||||
m_ShaderList.AddToTail( pShader );
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERDLL_GLOBAL_H
|
||||
#define SHADERDLL_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderSystem;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IShaderSystem *GetShaderSystem()
|
||||
{
|
||||
extern IShaderSystem* g_pSLShaderSystem;
|
||||
return g_pSLShaderSystem;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDLL_GLOBAL_H
|
|
@ -0,0 +1,42 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "icvar.h"
|
||||
#include "tier1/tier1.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
// ConVar stuff.
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
class CShaderLibConVarAccessor : public IConCommandBaseAccessor
|
||||
{
|
||||
public:
|
||||
virtual bool RegisterConCommandBase( ConCommandBase *pCommand )
|
||||
{
|
||||
// Link to engine's list instead
|
||||
g_pCVar->RegisterConCommand( pCommand );
|
||||
|
||||
char const *pValue = g_pCVar->GetCommandLineValue( pCommand->GetName() );
|
||||
if( pValue && !pCommand->IsCommand() )
|
||||
{
|
||||
( ( ConVar * )pCommand )->SetValue( pValue );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CShaderLibConVarAccessor g_ConVarAccessor;
|
||||
|
||||
|
||||
void InitShaderLibCVars( CreateInterfaceFn cvarFactory )
|
||||
{
|
||||
if ( g_pCVar )
|
||||
{
|
||||
ConVar_Register( FCVAR_MATERIAL_SYSTEM_THREAD, &g_ConVarAccessor );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERLIB_CVAR_H
|
||||
#define SHADERLIB_CVAR_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
|
||||
void InitShaderLibCVars( CreateInterfaceFn cvarFactory );
|
||||
|
||||
|
||||
#endif // SHADERLIB_CVAR_H
|
|
@ -0,0 +1,423 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="shaderlib"
|
||||
ProjectGUID="{1A1149D9-CB1B-BF85-19CA-C9C2996BFDE8}"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug\."
|
||||
IntermediateDirectory=".\Debug\."
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
AdditionalOptions="/MP"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\"
|
||||
PreprocessorDefinitions="WIN32;_WIN32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;COMPILER_MSVC32;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;COMPILER_MSVC;_DLL_EXT=.dll;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;LIBNAME=shaderlib;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;FAST_MATERIALVAR_ACCESS;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
ExceptionHandling="0"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
BufferSecurityCheck="false"
|
||||
EnableEnhancedInstructionSet="2"
|
||||
FloatingPointModel="2"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
OpenMP="false"
|
||||
UsePrecompiledHeader="0"
|
||||
ExpandAttributedSource="false"
|
||||
AssemblerOutput="0"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
GenerateXMLDocumentationFiles="false"
|
||||
BrowseInformation="0"
|
||||
BrowseInformationFile="$(IntDir)/"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="2"
|
||||
ErrorReporting="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
CommandLine="if exist ..\..\lib\public\shaderlib.lib attrib -r ..\..\lib\public\shaderlib.lib"
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
OutputFile="..\..\lib\public\.\shaderlib.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="$(OutDir)/shaderlib.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release\."
|
||||
IntermediateDirectory=".\Release\."
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
AdditionalOptions="/MP"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
AdditionalIncludeDirectories="..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\"
|
||||
PreprocessorDefinitions="WIN32;_WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;COMPILER_MSVC32;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;COMPILER_MSVC;_DLL_EXT=.dll;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;LIBNAME=shaderlib;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll;FAST_MATERIALVAR_ACCESS;VPCGAME=swarm;VPCGAMECAPS=SWARM;_DLL_EXT=.dll"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="false"
|
||||
EnableFunctionLevelLinking="true"
|
||||
EnableEnhancedInstructionSet="2"
|
||||
FloatingPointModel="2"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
OpenMP="false"
|
||||
UsePrecompiledHeader="0"
|
||||
ExpandAttributedSource="false"
|
||||
AssemblerOutput="0"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
GenerateXMLDocumentationFiles="false"
|
||||
BrowseInformation="0"
|
||||
BrowseInformationFile="$(IntDir)/"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="1"
|
||||
CompileAs="2"
|
||||
ErrorReporting="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
CommandLine="if exist ..\..\lib\public\shaderlib.lib attrib -r ..\..\lib\public\shaderlib.lib"
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
OutputFile="..\..\lib\public\.\shaderlib.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="$(OutDir)/shaderlib.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
ExcludedFromBuild="false"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="VPC Scripts"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\shaderlib.vpc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\vpc_scripts\source_lib_base.vpc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\vpc_scripts\source_lib_win32_base.vpc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\vpc_scripts\source_lib_win32_debug.vpc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\vpc_scripts\source_lib_win32_release.vpc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\vpc_scripts\version.vpc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\BaseShader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ShaderDLL.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\shaderlib_cvar.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="External Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\basetypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\commonmacros.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\dbg.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\fasttimer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\appframework\IAppSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\icommandline.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\icvar.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\ImageLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\imaterial.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\imaterialsystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\imaterialsystemhardwareconfig.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\imaterialvar.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\imesh.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\IShader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\ishaderapi.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\IShaderSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\itexture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\materialsystem\materialsystem_config.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\MATHLIB.H"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\memdbgoff.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\memdbgon.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier0\platform.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\protected_things.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\string_t.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier1\strtools.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier1\utlmemory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\tier1\utlvector.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vector.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vector2d.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vector4d.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vmatrix.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vplane.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\vstdlib\vstdlib.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\public\shaderlib\BaseShader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\shaderlib\commandbuilder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\shaderlib\cshader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\shaderlib\ShaderDLL.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\shaderDLL_Global.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\shaderlib_cvar.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,372 @@
|
|||
//===== Copyright © 1996-2005, 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 "cpp_shader_constant_register_map.h"
|
||||
#include "shaderlib/cshader.h"
|
||||
#include "shaderlib/baseshader.h"
|
||||
#include "ConVar.h"
|
||||
#include <renderparm.h>
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 vertex shader texture transforms
|
||||
void SetVertexShaderTextureTranslation( int vertexReg, int translationVar );
|
||||
void SetVertexShaderTextureScale( int vertexReg, int scaleVar );
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar );
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Set pixel shader texture transforms
|
||||
void SetPixelShaderTextureTranslation( int pixelReg, int translationVar );
|
||||
void SetPixelShaderTextureScale( int pixelReg, int scaleVar );
|
||||
void SetPixelShaderTextureTransform( int pixelReg, int transformVar );
|
||||
void SetPixelShaderTextureScaledTransform( int pixelReg,
|
||||
int transformVar, int scaleVar );
|
||||
|
||||
// Moves a matrix into vertex shader constants
|
||||
void SetVertexShaderMatrix3x4( int vertexReg, int matrixVar );
|
||||
void SetVertexShaderMatrix4x4( int vertexReg, int matrixVar );
|
||||
|
||||
// Loads the view matrix into vertex shader constants
|
||||
void LoadViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the projection matrix into vertex shader constants
|
||||
void LoadProjectionMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// Loads the model->view matrix into vertex shader constants
|
||||
void LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg );
|
||||
|
||||
// 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 );
|
||||
|
||||
// Sets up hw morphing state for the vertex shader
|
||||
void SetHWMorphVertexShaderState( int nDimConst, int nSubrectConst, VertexTextureSampler_t morphSampler );
|
||||
|
||||
BlendType_t EvaluateBlendRequirements( int textureVar, bool isBaseTexture, int detailTextureVar = -1 );
|
||||
|
||||
// Helper for setting up flashlight constants
|
||||
void SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms );
|
||||
|
||||
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 );
|
||||
|
||||
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:
|
||||
// Converts a color + alpha into a vector4
|
||||
void ColorVarsToVector( int colorVar, int alphaVar, Vector4D &color );
|
||||
};
|
||||
|
||||
FORCEINLINE char * GetFlashlightTextureFilename()
|
||||
{
|
||||
//if ( !IsX360() && ( g_pHardwareConfig->SupportsBorderColor() ) )
|
||||
//{
|
||||
// return "effects/flashlight001_border";
|
||||
//}
|
||||
//else
|
||||
{
|
||||
return "effects/flashlight001";
|
||||
}
|
||||
}
|
||||
|
||||
extern ConVar r_flashlightbrightness;
|
||||
|
||||
FORCEINLINE void SetFlashLightColorFromState( FlashlightState_t const &state, IShaderDynamicAPI *pShaderAPI, bool bSinglePassFlashlight, 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;
|
||||
|
||||
float flFlashlightScale = r_flashlightbrightness.GetFloat();
|
||||
|
||||
if ( !g_pHardwareConfig->GetHDREnabled() )
|
||||
{
|
||||
// Non-HDR path requires 2.0 flashlight
|
||||
flFlashlightScale = 2.0f;
|
||||
}
|
||||
|
||||
// DX10 hardware and single pass flashlight require a hack scalar since the flashlight is added in linear space
|
||||
if ( ( g_pHardwareConfig->UsesSRGBCorrectBlending() ) || ( bSinglePassFlashlight ) )
|
||||
{
|
||||
flFlashlightScale *= 2.5f; // Magic number that works well on the 360 and NVIDIA 8800
|
||||
}
|
||||
|
||||
flFlashlightScale *= state.m_fBrightnessScale;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void SetupUberlightFromState( IShaderDynamicAPI *pShaderAPI, FlashlightState_t const &state )
|
||||
{
|
||||
// Bail if we can't do ps30 or we don't even want an uberlight
|
||||
if ( !g_pHardwareConfig->HasFastVertexTextures() || !state.m_bUberlight || !pShaderAPI )
|
||||
return;
|
||||
|
||||
UberlightState_t u = state.m_uberlightState;
|
||||
|
||||
// Set uberlight shader parameters as function of user controls from UberlightState_t
|
||||
Vector4D vSmoothEdge0 = Vector4D( 0.0f, u.m_fCutOn - u.m_fNearEdge, u.m_fCutOff, 0.0f );
|
||||
Vector4D vSmoothEdge1 = Vector4D( 0.0f, u.m_fCutOn, u.m_fCutOff + u.m_fFarEdge, 0.0f );
|
||||
Vector4D vSmoothOneOverW = Vector4D( 0.0f, 1.0f / u.m_fNearEdge, 1.0f / u.m_fFarEdge, 0.0f );
|
||||
Vector4D vShearRound = Vector4D( u.m_fShearx, u.m_fSheary, 2.0f / u.m_fRoundness, -u.m_fRoundness / 2.0f );
|
||||
Vector4D vaAbB = Vector4D( u.m_fWidth, u.m_fWidth + u.m_fWedge, u.m_fHeight, u.m_fHeight + u.m_fHedge );
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_SMOOTH_EDGE_0, vSmoothEdge0.Base(), 1 );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_SMOOTH_EDGE_1, vSmoothEdge1.Base(), 1 );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_SMOOTH_EDGE_OOW, vSmoothOneOverW.Base(), 1 );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_SHEAR_ROUND, vShearRound.Base(), 1 );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_AABB, vaAbB.Base(), 1 );
|
||||
|
||||
QAngle angles;
|
||||
QuaternionAngles( state.m_quatOrientation, angles );
|
||||
|
||||
// World to Light's View matrix
|
||||
matrix3x4_t viewMatrix, viewMatrixInverse;
|
||||
AngleMatrix( angles, state.m_vecLightOrigin, viewMatrixInverse );
|
||||
MatrixInvert( viewMatrixInverse, viewMatrix );
|
||||
pShaderAPI->SetPixelShaderConstant( PSREG_UBERLIGHT_WORLD_TO_LIGHT, viewMatrix.Base(), 4 );
|
||||
}
|
||||
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void InitVecParam( int nIndex, IMaterialVar **params, float x, float y )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetVecValue( x, y );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void InitVecParam( int nIndex, IMaterialVar **params, float x, float y, float z )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetVecValue( x, y, z );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void InitVecParam( int nIndex, IMaterialVar **params, float x, float y, float z, float w )
|
||||
{
|
||||
if ( (nIndex != -1) && !params[nIndex]->IsDefined() )
|
||||
{
|
||||
params[nIndex]->SetVecValue( x, y, z, w );
|
||||
}
|
||||
}
|
||||
|
||||
// Did we launch with -tools
|
||||
bool ToolsEnabled();
|
||||
|
||||
class ConVar;
|
||||
|
||||
#ifdef _DEBUG
|
||||
extern ConVar mat_envmaptintoverride;
|
||||
extern ConVar mat_envmaptintscale;
|
||||
#endif
|
||||
|
||||
|
||||
extern ConVar r_emulategl;
|
||||
|
||||
FORCEINLINE bool IsOpenGL( void )
|
||||
{
|
||||
return IsPosix() || r_emulategl.GetBool();
|
||||
}
|
||||
|
||||
#endif // BASEVSSHADER_H
|
|
@ -0,0 +1,88 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "screenspaceeffect_vs20.inc"
|
||||
#include "bloom_ps20.inc"
|
||||
#include "bloom_ps20b.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
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
|
|
@ -0,0 +1,19 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#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 );
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
//===== Copyright © 1996-2005, 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
|
||||
SHADER_PARAM( KERNEL, SHADER_PARAM_TYPE_INTEGER, "0", "Kernel type" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
|
||||
if ( !( params[ KERNEL ]->IsDefined() ) )
|
||||
{
|
||||
params[ KERNEL ]->SetIntValue( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
pShaderShadow->EnableAlphaWrites( true );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
|
||||
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( blurfilter_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() ? 1 : 0 );
|
||||
SET_STATIC_VERTEX_SHADER( blurfilter_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CLEAR_COLOR, false );
|
||||
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CLEAR_COLOR, false );
|
||||
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;
|
||||
v[2] = 0;
|
||||
v[3] = 0;
|
||||
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 );
|
||||
|
||||
v[0] = v[1] = v[2] = v[3] = 0.0;
|
||||
v[0] = dX;
|
||||
pShaderAPI->SetPixelShaderConstant( 4, v, 1 );
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
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
|
|
@ -0,0 +1,154 @@
|
|||
//===== Copyright © 1996-2005, 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", "" )
|
||||
SHADER_PARAM( KERNEL, SHADER_PARAM_TYPE_INTEGER, "0", "Kernel type" )
|
||||
SHADER_PARAM( ENABLECLEARCOLOR, SHADER_PARAM_TYPE_BOOL, "0", "clear RGB channels to a solid color" )
|
||||
SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "clear color" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if ( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
if ( !( params[BLOOMAMOUNT]->IsDefined() ) )
|
||||
{
|
||||
params[BLOOMAMOUNT]->SetFloatValue(1.0);
|
||||
}
|
||||
|
||||
if ( !( params[ KERNEL ]->IsDefined() ) )
|
||||
{
|
||||
params[ KERNEL ]->SetIntValue( 0 );
|
||||
}
|
||||
|
||||
if ( !( params[ ENABLECLEARCOLOR ]->IsDefined() ) )
|
||||
{
|
||||
params[ ENABLECLEARCOLOR ]->SetIntValue( 0 );
|
||||
}
|
||||
|
||||
if ( !( params[ CLEARCOLOR ]->IsDefined() ) )
|
||||
{
|
||||
params[ CLEARCOLOR ]->SetVecValue( 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
pShaderShadow->EnableAlphaWrites( true );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
|
||||
|
||||
//avoid srgb conversions to alleviate some of the srgb texture lookup problems
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( blurfilter_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() ? 1 : 0 );
|
||||
SET_STATIC_VERTEX_SHADER( blurfilter_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CLEAR_COLOR, params[ ENABLECLEARCOLOR ]->GetIntValue() );
|
||||
SET_STATIC_PIXEL_SHADER( blurfilter_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( KERNEL, params[ KERNEL ]->GetIntValue() );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( CLEAR_COLOR, params[ ENABLECLEARCOLOR ]->GetIntValue() );
|
||||
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->GetActualHeight();
|
||||
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 );
|
||||
|
||||
v[0] = v[1] = v[2] = v[3] = 0.0;
|
||||
v[1] = dY;
|
||||
pShaderAPI->SetPixelShaderConstant( 4, v, 1 );
|
||||
|
||||
params[CLEARCOLOR]->GetVecValue( v, 3 );
|
||||
v[3] = 0.0f;
|
||||
pShaderAPI->SetPixelShaderConstant( 5, v, 1 );
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
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
|
|
@ -0,0 +1,128 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "KERNEL" "0..4"
|
||||
// STATIC: "CLEAR_COLOR" "0..1"
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
sampler TexSampler : register( s0 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 coordTap0 : TEXCOORD0;
|
||||
#if ( KERNEL == 0 ) // Original kernel that has a '+' plus shape
|
||||
float2 coordTap1 : TEXCOORD1;
|
||||
float2 coordTap2 : TEXCOORD2;
|
||||
float2 coordTap3 : TEXCOORD3;
|
||||
float2 coordTap1Neg : TEXCOORD4;
|
||||
float2 coordTap2Neg : TEXCOORD5;
|
||||
float2 coordTap3Neg : TEXCOORD6;
|
||||
#endif
|
||||
};
|
||||
|
||||
float2 g_vPsTapOffset[3] : register( c0 );
|
||||
float3 g_vScaleFactor : register( c3 );
|
||||
|
||||
float2 g_vUvOffsetToNeighborPixel : register( c4 );
|
||||
float3 g_vClearColor : register( c5 );
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
#if ( KERNEL == 0 ) // Original kernel that has a '+' plus shape (used for bloom?)
|
||||
{
|
||||
float4 s0, s1, s2, s3, s4, s5, s6, color;
|
||||
|
||||
// Sample taps with coordinates from VS
|
||||
s0 = saturate( tex2D( TexSampler, i.coordTap0 ) );
|
||||
s1 = saturate( tex2D( TexSampler, i.coordTap1 ) );
|
||||
s2 = saturate( tex2D( TexSampler, i.coordTap2 ) );
|
||||
s3 = saturate( tex2D( TexSampler, i.coordTap3 ) );
|
||||
s4 = saturate( tex2D( TexSampler, i.coordTap1Neg ) );
|
||||
s5 = saturate( tex2D( TexSampler, i.coordTap2Neg ) );
|
||||
s6 = saturate( tex2D( 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 + g_vPsTapOffset[0];
|
||||
float2 coordTap5 = i.coordTap0 + g_vPsTapOffset[1];
|
||||
float2 coordTap6 = i.coordTap0 + g_vPsTapOffset[2];
|
||||
float2 coordTap4Neg = i.coordTap0 - g_vPsTapOffset[0];
|
||||
float2 coordTap5Neg = i.coordTap0 - g_vPsTapOffset[1];
|
||||
float2 coordTap6Neg = i.coordTap0 - g_vPsTapOffset[2];
|
||||
|
||||
// Sample the taps
|
||||
s1 = saturate( tex2D( TexSampler, coordTap4 ) );
|
||||
s2 = saturate( tex2D( TexSampler, coordTap5 ) );
|
||||
s3 = saturate( tex2D( TexSampler, coordTap6 ) );
|
||||
s4 = saturate( tex2D( TexSampler, coordTap4Neg ) );
|
||||
s5 = saturate( tex2D( TexSampler, coordTap5Neg ) );
|
||||
s6 = saturate( tex2D( TexSampler, coordTap6Neg ) );
|
||||
|
||||
color += ( s1 + s4 ) * 0.0262f;
|
||||
color += ( s2 + s5 ) * 0.0162f;
|
||||
color += ( s3 + s6 ) * 0.0102f;
|
||||
#if CLEAR_COLOR == 1
|
||||
{
|
||||
color.rgb = g_vClearColor.rgb;
|
||||
}
|
||||
#else
|
||||
{
|
||||
color.xyz *= g_vScaleFactor.xyz;
|
||||
}
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
#else // Gaussian kernel
|
||||
{
|
||||
#if ( KERNEL == 1 )
|
||||
// Gaussian kernel 7 pixels wide
|
||||
int kNumSamples = 5;
|
||||
float vKernel[5] = { 0.004433f, 0.296042f, 0.399050f, 0.296042f, 0.004433f };
|
||||
float vUvOffset[5] = { -3.000000f, -1.182425f, 0.000000f, 1.182425f, 3.000000f };
|
||||
#elif ( KERNEL == 2 )
|
||||
// Gaussian kernel 9 pixels wide
|
||||
int kNumSamples = 5;
|
||||
float vKernel[5] = { 0.019827f, 0.320561f, 0.319224f, 0.320561f, 0.019827f };
|
||||
float vUvOffset[5] = { -3.096215f, -1.276878f, 0.000000f, 1.276878f, 3.096215f };
|
||||
#elif ( KERNEL == 3 )
|
||||
// Gaussian kernel 13 pixels wide
|
||||
int kNumSamples = 7;
|
||||
float vKernel[7] = { 0.004487f, 0.069185f, 0.312325f, 0.228005f, 0.312325f, 0.069185f, 0.004487f };
|
||||
float vUvOffset[7] = { -5.142349f, -3.241796f, -1.379942f, 0.000000f, 1.379942f, 3.241796f, 5.142349f };
|
||||
#elif ( KERNEL == 4 )
|
||||
// Gaussian kernel 25 pixels wide
|
||||
int kNumSamples = 13;
|
||||
float vKernel[13] = { 0.000534f, 0.003733f, 0.018004f, 0.059928f, 0.137740f, 0.218677f, 0.122765f, 0.218677f, 0.137740f, 0.059928f, 0.018004f, 0.003733f, 0.000534f };
|
||||
float vUvOffset[13] = { -11.251852f, -9.289172f, -7.329586f, -5.372686f, -3.417910f, -1.464557f, 0.000000f, 1.464557f, 3.417910f, 5.372686f, 7.329586f, 9.289172f, 11.251852f };
|
||||
#endif
|
||||
|
||||
float2 vStartUv = i.coordTap0.xy;
|
||||
|
||||
float4 cColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
for ( int j = 0; j < kNumSamples; j++ )
|
||||
{
|
||||
// Calculate uv
|
||||
float2 vUvTmp = vStartUv.xy + ( vUvOffset[j].xx * g_vUvOffsetToNeighborPixel.xy );
|
||||
|
||||
// Sample pixel
|
||||
cColor.rgba += vKernel[j] * tex2D( TexSampler, vUvTmp.xy );
|
||||
}
|
||||
|
||||
#if CLEAR_COLOR == 1
|
||||
{
|
||||
cColor.rgb = g_vClearColor.rgb;
|
||||
}
|
||||
#else
|
||||
{
|
||||
cColor.rgb = cColor.rgb * g_vScaleFactor.rgb;
|
||||
}
|
||||
#endif
|
||||
return cColor.rgba;
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#include "common_vs_fxc.h"
|
||||
|
||||
// STATIC: "KERNEL" "0..1"
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float3 vPos : POSITION;
|
||||
float2 vBaseTexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 projPos : POSITION;
|
||||
float2 coordTap0 : TEXCOORD0;
|
||||
#if ( KERNEL == 0 ) // Original kernel that has a '+' plus shape
|
||||
float2 coordTap1 : TEXCOORD1;
|
||||
float2 coordTap2 : TEXCOORD2;
|
||||
float2 coordTap3 : TEXCOORD3;
|
||||
float2 coordTap1Neg : TEXCOORD4;
|
||||
float2 coordTap2Neg : TEXCOORD5;
|
||||
float2 coordTap3Neg : TEXCOORD6;
|
||||
#endif
|
||||
};
|
||||
|
||||
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.xy = v.vBaseTexCoord.xy;
|
||||
#if ( KERNEL == 0 ) // Original kernel
|
||||
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];
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
//========= Copyright © 1996-2005, 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
|
||||
{
|
||||
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 );
|
||||
SET_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
|
||||
|
||||
//avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
|
||||
if( bUsesColor )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
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
|
|
@ -0,0 +1,21 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#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 );
|
||||
}
|
|
@ -0,0 +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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
//===== Copyright © 1996-2005, 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
|
||||
{
|
||||
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
|
|
@ -0,0 +1,24 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// DYNAMIC: "SHOWALPHA" "0..1"
|
||||
|
||||
#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 );
|
||||
}
|
|
@ -0,0 +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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
//========= Copyright © 1996-2007, Valve Corporation, All rights reserved. ============//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "shaderlib/CShader.h"
|
||||
|
||||
#include "debugtextureview_vs20.inc"
|
||||
#include "debugtextureview_ps20.inc"
|
||||
#include "debugtextureview_ps20b.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
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
|
|
@ -0,0 +1,80 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "SHOWALPHA" "0..1"
|
||||
// DYNAMIC: "ISCUBEMAP" "0..1"
|
||||
|
||||
#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 );
|
||||
}
|
|
@ -0,0 +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;
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "cpp_shader_constant_register_map.h"
|
||||
|
||||
#include "decalmodulate_vs20.inc"
|
||||
#include "decalmodulate_ps20.inc"
|
||||
#include "decalmodulate_ps20b.inc"
|
||||
|
||||
#ifndef _X360
|
||||
#include "decalmodulate_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 )
|
||||
|
||||
BEGIN_VS_SHADER( DecalModulate_dx9,
|
||||
"Help for DecalModulate_dx9" )
|
||||
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( FOGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "0.4", "exponent to tweak fog fade" )
|
||||
SHADER_PARAM( FOGSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale to tweak fog fade" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
if( !params[ FOGEXPONENT ]->IsDefined() )
|
||||
{
|
||||
params[ FOGEXPONENT ]->SetFloatValue( 0.4f );
|
||||
}
|
||||
|
||||
if( !params[ FOGSCALE ]->IsDefined() )
|
||||
{
|
||||
params[ FOGSCALE ]->SetFloatValue( 1.0f );
|
||||
}
|
||||
|
||||
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 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();
|
||||
|
||||
int nLightingPreviewMode = IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) + 2 * IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 );
|
||||
|
||||
bool bHasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) && IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
|
||||
|
||||
#ifndef _X360
|
||||
if ( !g_pHardwareConfig->HasFastVertexTextures() )
|
||||
#endif
|
||||
{
|
||||
DECLARE_STATIC_VERTEX_SHADER( decalmodulate_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexAlpha );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode != 0 );
|
||||
SET_STATIC_VERTEX_SHADER( decalmodulate_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( VERTEXALPHA, bHasVertexAlpha );
|
||||
SET_STATIC_PIXEL_SHADER( decalmodulate_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( VERTEXALPHA, bHasVertexAlpha );
|
||||
SET_STATIC_PIXEL_SHADER( decalmodulate_ps20 );
|
||||
}
|
||||
}
|
||||
#ifndef _X360
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_VERTEX_SHADER( decalmodulate_vs30 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexAlpha );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode != 0 );
|
||||
SET_STATIC_VERTEX_SHADER( decalmodulate_vs30 );
|
||||
|
||||
DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps30 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( VERTEXALPHA, bHasVertexAlpha );
|
||||
SET_STATIC_PIXEL_SHADER( decalmodulate_ps30 );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set stream format (note that this shader supports compression)
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
|
||||
|
||||
if ( bHasVertexAlpha )
|
||||
{
|
||||
flags |= VERTEX_COLOR;
|
||||
}
|
||||
|
||||
#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() )
|
||||
{
|
||||
// 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 );
|
||||
|
||||
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 );
|
||||
|
||||
// fog tweaks
|
||||
float fConsts[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
fConsts[0] = params[ FOGEXPONENT ]->GetFloatValue();
|
||||
fConsts[1] = params[ FOGSCALE ]->GetFloatValue();
|
||||
pShaderAPI->SetPixelShaderConstant( 0, fConsts );
|
||||
|
||||
#ifndef _X360
|
||||
if ( !g_pHardwareConfig->HasFastVertexTextures() )
|
||||
#endif
|
||||
{
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( decalmodulate_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
// SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, 0 ); // JasonM TODO: set this appropriately when we care about decals on subds
|
||||
SET_DYNAMIC_VERTEX_SHADER( decalmodulate_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20 );
|
||||
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( decalmodulate_vs30 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
// SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, 0 ); // JasonM TODO: set this appropriately when we care about decals on subds
|
||||
SET_DYNAMIC_VERTEX_SHADER( decalmodulate_vs30 );
|
||||
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 );
|
||||
SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 );
|
||||
|
||||
bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() };
|
||||
pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Draw( );
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,280 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: Depth of field material
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "depth_of_field_vs20.inc"
|
||||
#include "depth_of_field_ps20b.inc"
|
||||
#include "convar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
ConVar mat_dof_max_blur_radius( "mat_dof_max_blur_radius", "10" );
|
||||
ConVar mat_dof_quality( "mat_dof_quality", "0" );
|
||||
|
||||
// 8 samples
|
||||
static const float s_flPoissonConstsQuality0[16] = {
|
||||
0.0, 0.0,
|
||||
0.527837, -0.085868,
|
||||
-0.040088, 0.536087,
|
||||
-0.670445, -0.179949,
|
||||
-0.419418, -0.616039,
|
||||
0.440453, -0.639399,
|
||||
-0.757088, 0.349334,
|
||||
0.574619, 0.685879
|
||||
};
|
||||
|
||||
// 16 samples
|
||||
static const float s_flPoissonConstsQuality1[32] = {
|
||||
0.0747, -0.8341,
|
||||
-0.9138, 0.3251,
|
||||
0.8667, -0.3029,
|
||||
-0.4642, 0.2187,
|
||||
-0.1505, 0.7320,
|
||||
0.7310, -0.6786,
|
||||
0.2859, -0.3254,
|
||||
-0.1311, -0.2292,
|
||||
0.3518, 0.6470,
|
||||
-0.7485, -0.6307,
|
||||
0.1687, 0.1873,
|
||||
-0.3604, -0.7483,
|
||||
-0.5658, -0.1521,
|
||||
0.7102, 0.0536,
|
||||
-0.6056, 0.7747,
|
||||
0.7793, 0.6194
|
||||
};
|
||||
|
||||
// 32 samples
|
||||
static const float s_flPoissonConstsQuality2[64] = {
|
||||
0.0854f, -0.0644f,
|
||||
0.8744f, 0.1665f,
|
||||
0.2329f, 0.3995f,
|
||||
-0.7804f, 0.5482f,
|
||||
-0.4577f, 0.7647f,
|
||||
-0.1936f, 0.5564f,
|
||||
0.4205f, -0.5768f,
|
||||
-0.0304f, -0.9050f,
|
||||
-0.5215f, 0.1854f,
|
||||
0.3161f, -0.2954f,
|
||||
0.0666f, -0.5564f,
|
||||
-0.2137f, -0.0072f,
|
||||
-0.4112f, -0.3311f,
|
||||
0.6438f, -0.2484f,
|
||||
-0.9055f, -0.0360f,
|
||||
0.8323f, 0.5268f,
|
||||
0.5592f, 0.3459f,
|
||||
-0.6797f, -0.5201f,
|
||||
-0.4325f, -0.8857f,
|
||||
0.8768f, -0.4197f,
|
||||
0.3090f, -0.8646f,
|
||||
0.5034f, 0.8603f,
|
||||
0.3752f, 0.0627f,
|
||||
-0.0161f, 0.2627f,
|
||||
0.0969f, 0.7054f,
|
||||
-0.2291f, -0.6595f,
|
||||
-0.5887f, -0.1100f,
|
||||
0.7048f, -0.6528f,
|
||||
-0.8438f, 0.2706f,
|
||||
-0.5061f, 0.4653f,
|
||||
-0.1245f, -0.3302f,
|
||||
-0.1801f, 0.8486f
|
||||
};
|
||||
|
||||
DEFINE_FALLBACK_SHADER( DepthOfField, DepthOfField_dx9 )
|
||||
BEGIN_VS_SHADER_FLAGS( DepthOfField_dx9, "Depth of Field", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( SMALLFB, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallFB1", "Downsampled backbuffer" )
|
||||
SHADER_PARAM( NEARPLANE, SHADER_PARAM_TYPE_FLOAT, "0", "Near plane depth" )
|
||||
SHADER_PARAM( FARPLANE, SHADER_PARAM_TYPE_FLOAT, "0", "Far plane depth" )
|
||||
SHADER_PARAM( NEARBLURDEPTH, SHADER_PARAM_TYPE_FLOAT, "0", "Near blur plane depth" )
|
||||
SHADER_PARAM( NEARFOCUSDEPTH, SHADER_PARAM_TYPE_FLOAT, "0", "Near focus plane depth" )
|
||||
SHADER_PARAM( FARFOCUSDEPTH, SHADER_PARAM_TYPE_FLOAT, "0", "Far focus plane depth" )
|
||||
SHADER_PARAM( FARBLURDEPTH, SHADER_PARAM_TYPE_FLOAT, "0", "Far blur plane depth" )
|
||||
SHADER_PARAM( NEARBLURRADIUS, SHADER_PARAM_TYPE_FLOAT, "0", "Max near blur radius" )
|
||||
SHADER_PARAM( FARBLURRADIUS, SHADER_PARAM_TYPE_FLOAT, "0", "Max far blur radius" )
|
||||
SHADER_PARAM( QUALITY, SHADER_PARAM_TYPE_INTEGER, "0", "Quality level. Selects different algorithms." )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
SET_PARAM_STRING_IF_NOT_DEFINED( SMALLFB, "_rt_SmallFB1" );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( NEARPLANE, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( FARPLANE, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( NEARBLURDEPTH, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( NEARFOCUSDEPTH, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( FARFOCUSDEPTH, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( FARBLURDEPTH, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( NEARBLURRADIUS, 0.0f );
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( FARBLURRADIUS, 0.0f );
|
||||
SET_PARAM_INT_IF_NOT_DEFINED( QUALITY, 0 );
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
if ( g_pHardwareConfig->GetDXSupportLevel() < 92 )
|
||||
{
|
||||
return "Wireframe";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if ( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
if ( params[SMALLFB]->IsDefined() )
|
||||
{
|
||||
LoadTexture( SMALLFB );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
|
||||
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false );
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( depth_of_field_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( depth_of_field_vs20 );
|
||||
|
||||
if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( depth_of_field_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER( depth_of_field_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( !"No ps_2_b. This shouldn't be happening" );
|
||||
}
|
||||
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
pShaderShadow->EnableAlphaWrites( false );
|
||||
}
|
||||
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( depth_of_field_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( depth_of_field_vs20 );
|
||||
|
||||
// Bind textures
|
||||
BindTexture( SHADER_SAMPLER0, BASETEXTURE );
|
||||
BindTexture( SHADER_SAMPLER1, SMALLFB );
|
||||
|
||||
// near blur = blur of stuff in front of focus range
|
||||
// far blur = blur of stuff behind focus range
|
||||
|
||||
// C0: set near/far blur and focus distances
|
||||
// x = near blur distance
|
||||
// y = near focus distance
|
||||
// z = far focus distance
|
||||
// w = far blur distance
|
||||
// C1:
|
||||
// x = blur radius for near blur (in pixels)
|
||||
// y = blur radius for far blur (in pixels)
|
||||
// TODO: Specifying this stuff in pixels makes blurs look smaller on high backbuffer resolutions.
|
||||
// This might be a problem for tweaking these values.
|
||||
float vConst[16] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
vConst[0] = params[NEARBLURDEPTH]->GetFloatValue();
|
||||
vConst[1] = params[NEARFOCUSDEPTH]->GetFloatValue();
|
||||
vConst[2] = params[FARFOCUSDEPTH]->GetFloatValue();
|
||||
vConst[3] = params[FARBLURDEPTH]->GetFloatValue();;
|
||||
// max blur radius will need to be set based on qulity level and screen res
|
||||
vConst[4] = mat_dof_max_blur_radius.GetFloat();
|
||||
vConst[5] = MIN( params[NEARBLURRADIUS]->GetFloatValue(), vConst[4] ) / vConst[4]; // near and far blur radius as fraction of max radius
|
||||
vConst[6] = MIN( params[FARBLURRADIUS]->GetFloatValue(), vConst[4] ) / vConst[4];
|
||||
|
||||
vConst[8] = params[NEARPLANE]->GetFloatValue();
|
||||
vConst[9] = params[FARPLANE]->GetFloatValue();
|
||||
|
||||
// 8192 is the magic number for HDR mode 3 (see FLOAT_RENDERPARM_DEST_ALPHA_DEPTH_SCALE in shaderapidx8.cpp)
|
||||
vConst[10] = 8192.0f * ( vConst[9] - vConst[8] ) / vConst[9];
|
||||
|
||||
vConst[12] = vConst[10] / ( vConst[0] - vConst[1] );
|
||||
vConst[13] = ( vConst[8] - vConst[1] ) / ( vConst[0] - vConst[1] );
|
||||
vConst[14] = vConst[10] / ( vConst[3] - vConst[2] );
|
||||
vConst[15] = ( vConst[8] - vConst[2] ) / ( vConst[3] - vConst[2] );
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 0, vConst, 4 );
|
||||
|
||||
// set up poisson sample location constants pre-divided by screen res
|
||||
int nNumPoissonSamples = 0;
|
||||
const float *pPoissonSrc = NULL;
|
||||
switch ( params[QUALITY]->GetIntValue() )
|
||||
{
|
||||
case 0:
|
||||
// NOTE: These must match the shader
|
||||
nNumPoissonSamples = 8;
|
||||
pPoissonSrc = s_flPoissonConstsQuality0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
nNumPoissonSamples = 16;
|
||||
pPoissonSrc = s_flPoissonConstsQuality1;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
nNumPoissonSamples = 32;
|
||||
pPoissonSrc = s_flPoissonConstsQuality2;
|
||||
break;
|
||||
|
||||
default:
|
||||
Warning( "Invalid mat_dof_quality value. Resetting to 0.\n" );
|
||||
mat_dof_quality.SetValue( 0 );
|
||||
nNumPoissonSamples = 8;
|
||||
pPoissonSrc = s_flPoissonConstsQuality0;
|
||||
break;
|
||||
}
|
||||
|
||||
float vPoissonConst[64]; // temp table
|
||||
|
||||
// Get texture dimensions
|
||||
ITexture *pTex = params[BASETEXTURE]->GetTextureValue();
|
||||
Assert( pTex );
|
||||
float flInvTexWidth = 1.0f / static_cast<float>( pTex->GetActualWidth() );
|
||||
float flInvTexHeight = 1.0f / static_cast<float>( pTex->GetActualHeight() );
|
||||
|
||||
for ( int i = 0; i < nNumPoissonSamples; i++ )
|
||||
{
|
||||
vPoissonConst[ 2*i ] = pPoissonSrc[ 2*i ] * flInvTexWidth;
|
||||
vPoissonConst[ 2*i+1 ] = pPoissonSrc[ 2*i+1 ] * flInvTexHeight;
|
||||
}
|
||||
|
||||
// swizzle every other 2-tuple so that I can use the free .wz swizzle in the shader
|
||||
for ( int i = 1; i < nNumPoissonSamples; i += 2)
|
||||
{
|
||||
float t = vPoissonConst[ 2*i ];
|
||||
vPoissonConst[ 2*i ] = vPoissonConst[ 2*i+1 ];
|
||||
vPoissonConst[ 2*i+1 ] = t;
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 4, vPoissonConst, nNumPoissonSamples / 2 );
|
||||
|
||||
if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( depth_of_field_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( QUALITY, params[QUALITY]->GetIntValue() );
|
||||
SET_DYNAMIC_PIXEL_SHADER( depth_of_field_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( !"No ps_2_b. This shouldn't be happening" );
|
||||
}
|
||||
}
|
||||
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,105 @@
|
|||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "common_hlsl_cpp_consts.h"
|
||||
|
||||
#include "downsample_ps20.inc"
|
||||
#include "downsample_ps20b.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
BEGIN_VS_SHADER_FLAGS( Downsample, "Help for Downsample", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableDepthWrites( false );
|
||||
pShaderShadow->EnableAlphaWrites( true );
|
||||
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
|
||||
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
|
|
@ -0,0 +1,78 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "BLOOMTYPE" "0..1"
|
||||
// DYNAMIC: "FLOAT_BACK_BUFFER" "0..1" [ps20b] [ps30] [PC]
|
||||
// DYNAMIC: "FLOAT_BACK_BUFFER" "0..0" [ps20b] [XBOX]
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
sampler TexSampler : register( s0 );
|
||||
float4 params : register( c0 );
|
||||
float4 params2 : register( c1 );
|
||||
#define g_flBloomExp params2.x
|
||||
#define g_flBloomSaturation params2.y
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 coordTap0 : TEXCOORD0;
|
||||
float2 coordTap1 : TEXCOORD1;
|
||||
float2 coordTap2 : TEXCOORD2;
|
||||
float2 coordTap3 : TEXCOORD3;
|
||||
};
|
||||
|
||||
float4 Shape( float4 cColor )
|
||||
{
|
||||
#if ( BLOOMTYPE == 0 )
|
||||
{
|
||||
float flLum = dot( cColor.xyz, params.xyz );
|
||||
cColor.rgb = pow( cColor.xyz, params.w ) * flLum;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( BLOOMTYPE == 1 )
|
||||
{
|
||||
float flScale = 1.55f; // Color scale
|
||||
float flBias = -0.09f; // Color bias
|
||||
float flBrightnessClamp = 0.59f; // After scale and bias, clamp RGB values brighter than this
|
||||
float flExp = g_flBloomExp;
|
||||
cColor.rgb = pow( saturate( min( flBrightnessClamp, ( cColor.rgb * flScale ) + flBias ) ), flExp );
|
||||
}
|
||||
#endif
|
||||
|
||||
return cColor;
|
||||
}
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 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 );
|
||||
|
||||
#if ( FLOAT_BACK_BUFFER == 1 )
|
||||
{
|
||||
// for float HDR mode, match the color space of the int render pass, to get identical bloom results
|
||||
s0.rgb = SrgbLinearToGamma( saturate( s0.rgb ) );
|
||||
s1.rgb = SrgbLinearToGamma( saturate( s1.rgb ) );
|
||||
s2.rgb = SrgbLinearToGamma( saturate( s2.rgb ) );
|
||||
s3.rgb = SrgbLinearToGamma( saturate( s3.rgb ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f;
|
||||
float fAvgLuminance = dot( avgColor.rgb, float3( 0.299, 0.587, 0.114 ) );
|
||||
avgColor = Shape( avgColor );
|
||||
|
||||
// Saturation
|
||||
#if ( BLOOMTYPE == 1 )
|
||||
{
|
||||
avgColor.rgb = lerp( dot( params.rgb, avgColor.rgb ), avgColor.rgb, g_flBloomSaturation );
|
||||
}
|
||||
#endif
|
||||
|
||||
avgColor.a = fAvgLuminance;
|
||||
return FinalOutput( avgColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#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
|
||||
{
|
||||
float4 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 );
|
||||
|
||||
// store grayscale version of buffer in alpha
|
||||
float4 vResult = ( s0 + s1 + s2 + s3 ) * 0.25f;
|
||||
vResult.a = dot( float3( 0.3f, 0.59f, 0.11f ), vResult.rgb );
|
||||
|
||||
return vResult;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,658 @@
|
|||
//========= Copyright © 1996-2007, Valve LLC, 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"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
ConVar mat_screen_blur_override( "mat_screen_blur_override", "-1.0" );
|
||||
ConVar mat_depth_blur_focal_distance_override( "mat_depth_blur_focal_distance_override", "-1.0" );
|
||||
ConVar mat_depth_blur_strength_override( "mat_depth_blur_strength_override", "-1.0" );
|
||||
ConVar mat_grain_scale_override( "mat_grain_scale_override", "-1.0" );
|
||||
ConVar mat_local_contrast_scale_override( "mat_local_contrast_scale_override", "0.0" );
|
||||
ConVar mat_local_contrast_midtone_mask_override( "mat_local_contrast_midtone_mask_override", "-1.0" );
|
||||
ConVar mat_local_contrast_vignette_start_override( "mat_local_contrast_vignette_start_override", "-1.0" );
|
||||
ConVar mat_local_contrast_vignette_end_override( "mat_local_contrast_vignette_end_override", "-1.0" );
|
||||
ConVar mat_local_contrast_edge_scale_override( "mat_local_contrast_edge_scale_override", "-1000.0" );
|
||||
|
||||
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" )
|
||||
SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "Bloom scale factor" )
|
||||
SHADER_PARAM( SCREENEFFECTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "used for paint or vomit screen effect" )
|
||||
SHADER_PARAM( DEPTHBLURENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Inexpensive depth-of-field substitute" )
|
||||
|
||||
SHADER_PARAM( ALLOWVIGNETTE, SHADER_PARAM_TYPE_BOOL, "0", "Allow vignette" )
|
||||
SHADER_PARAM( VIGNETTEENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable vignette" )
|
||||
SHADER_PARAM( INTERNAL_VIGNETTETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "dev/vignette", "" )
|
||||
|
||||
SHADER_PARAM( ALLOWNOISE, SHADER_PARAM_TYPE_BOOL, "0", "Allow noise" )
|
||||
SHADER_PARAM( NOISEENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable noise" )
|
||||
SHADER_PARAM( NOISESCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Noise scale" )
|
||||
SHADER_PARAM( NOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Noise texture" )
|
||||
|
||||
SHADER_PARAM( ALLOWLOCALCONTRAST, SHADER_PARAM_TYPE_BOOL, "0", "Enable local contrast enhancement" )
|
||||
SHADER_PARAM( LOCALCONTRASTENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable local contrast enhancement" )
|
||||
SHADER_PARAM( LOCALCONTRASTSCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Local contrast scale" )
|
||||
SHADER_PARAM( LOCALCONTRASTMIDTONEMASK, SHADER_PARAM_TYPE_FLOAT, "0", "Local contrast midtone mask" )
|
||||
SHADER_PARAM( LOCALCONTRASTVIGNETTESTART, SHADER_PARAM_TYPE_BOOL, "0", "Enable local contrast enhancement" )
|
||||
SHADER_PARAM( LOCALCONTRASTVIGNETTEEND, SHADER_PARAM_TYPE_FLOAT, "0", "Local contrast scale" )
|
||||
SHADER_PARAM( LOCALCONTRASTEDGESCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Local contrast midtone mask" )
|
||||
|
||||
SHADER_PARAM( BLURREDVIGNETTEENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable blurred vignette" )
|
||||
SHADER_PARAM( BLURREDVIGNETTESCALE, SHADER_PARAM_TYPE_FLOAT, "0", "blurred vignette strength" )
|
||||
SHADER_PARAM( FADETOBLACKSCALE, SHADER_PARAM_TYPE_FLOAT, "0", "fade strength" )
|
||||
|
||||
SHADER_PARAM( DEPTHBLURFOCALDISTANCE, SHADER_PARAM_TYPE_FLOAT, "0", "Distance in dest-alpha space [0,1] of focal plane." )
|
||||
SHADER_PARAM( DEPTHBLURSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "0", "Strength of depth-blur effect" )
|
||||
SHADER_PARAM( SCREENBLURSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "0", "Full-screen blur factor" )
|
||||
|
||||
SHADER_PARAM( VOMITCOLOR1, SHADER_PARAM_TYPE_VEC3, "[0 0 0 0]", "1st vomit blend color" )
|
||||
SHADER_PARAM( VOMITCOLOR2, SHADER_PARAM_TYPE_VEC3, "[0 0 0 0]", "2st vomit blend color" )
|
||||
SHADER_PARAM( VOMITREFRACTSCALE, SHADER_PARAM_TYPE_FLOAT, "0.15", "vomit refract strength" )
|
||||
SHADER_PARAM( VOMITENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable vomit refract" )
|
||||
|
||||
SHADER_PARAM( FADECOLOR, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "viewfade color" )
|
||||
SHADER_PARAM( FADE, SHADER_PARAM_TYPE_INTEGER, "0", "fade type. 0 = off, 1 = lerp, 2 = modulate" )
|
||||
|
||||
SHADER_PARAM( TV_GAMMA, SHADER_PARAM_TYPE_INTEGER, "0", "0 default, 1 used for laying off 360 movies" )
|
||||
SHADER_PARAM( DESATURATEENABLE, SHADER_PARAM_TYPE_INTEGER, "0", "Desaturate with math, turns off color correction" )
|
||||
SHADER_PARAM( DESATURATION, SHADER_PARAM_TYPE_FLOAT, "0", "Desaturation Amount" )
|
||||
|
||||
// Tool color correction setup
|
||||
SHADER_PARAM( TOOLMODE, SHADER_PARAM_TYPE_BOOL, "1", "tool mode" )
|
||||
SHADER_PARAM( TOOLCOLORCORRECTION, SHADER_PARAM_TYPE_FLOAT, "1", "tool color correction override" )
|
||||
SHADER_PARAM( WEIGHT_DEFAULT, SHADER_PARAM_TYPE_FLOAT, "1", "weight default" )
|
||||
SHADER_PARAM( WEIGHT0, SHADER_PARAM_TYPE_FLOAT, "1", "weight0" )
|
||||
SHADER_PARAM( WEIGHT1, SHADER_PARAM_TYPE_FLOAT, "1", "weight1" )
|
||||
SHADER_PARAM( WEIGHT2, SHADER_PARAM_TYPE_FLOAT, "1", "weight2" )
|
||||
SHADER_PARAM( WEIGHT3, SHADER_PARAM_TYPE_FLOAT, "1", "weight3" )
|
||||
SHADER_PARAM( NUM_LOOKUPS, SHADER_PARAM_TYPE_FLOAT, "0", "num_lookups" )
|
||||
SHADER_PARAM( TOOLTIME, SHADER_PARAM_TYPE_FLOAT, "0", "tooltime" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
if ( !params[ INTERNAL_VIGNETTETEXTURE ]->IsDefined() )
|
||||
{
|
||||
params[ INTERNAL_VIGNETTETEXTURE ]->SetStringValue( "dev/vignette" );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
if ( !params[ BLOOMAMOUNT ]->IsDefined() )
|
||||
{
|
||||
params[ BLOOMAMOUNT ]->SetFloatValue( 1.0f );
|
||||
}
|
||||
if ( !params[ DEPTHBLURENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ DEPTHBLURENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ ALLOWNOISE ]->IsDefined() )
|
||||
{
|
||||
params[ ALLOWNOISE ]->SetIntValue( 1 );
|
||||
}
|
||||
if ( !params[ NOISESCALE ]->IsDefined() )
|
||||
{
|
||||
params[ NOISESCALE ]->SetFloatValue( 1.0f );
|
||||
}
|
||||
if ( !params[ NOISEENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ NOISEENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ ALLOWVIGNETTE ]->IsDefined() )
|
||||
{
|
||||
params[ ALLOWVIGNETTE ]->SetIntValue( 1 );
|
||||
}
|
||||
if ( !params[ VIGNETTEENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ VIGNETTEENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ ALLOWLOCALCONTRAST ]->IsDefined() )
|
||||
{
|
||||
params[ ALLOWLOCALCONTRAST ]->SetIntValue( 1 );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTSCALE ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTSCALE ]->SetFloatValue( 1.0f );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTMIDTONEMASK ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTMIDTONEMASK ]->SetFloatValue( 1000.0f );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTVIGNETTESTART ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTVIGNETTESTART ]->SetFloatValue( 0.7f );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTVIGNETTEEND ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTVIGNETTEEND ]->SetFloatValue( 1.0f );
|
||||
}
|
||||
if ( !params[ LOCALCONTRASTEDGESCALE ]->IsDefined() )
|
||||
{
|
||||
params[ LOCALCONTRASTEDGESCALE ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ BLURREDVIGNETTEENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ BLURREDVIGNETTEENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ BLURREDVIGNETTESCALE ]->IsDefined() )
|
||||
{
|
||||
params[ BLURREDVIGNETTESCALE ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ FADETOBLACKSCALE ]->IsDefined() )
|
||||
{
|
||||
params[ FADETOBLACKSCALE ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ DEPTHBLURFOCALDISTANCE ]->IsDefined() )
|
||||
{
|
||||
params[ DEPTHBLURFOCALDISTANCE ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ DEPTHBLURSTRENGTH ]->IsDefined() )
|
||||
{
|
||||
params[ DEPTHBLURSTRENGTH ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ SCREENBLURSTRENGTH ]->IsDefined() )
|
||||
{
|
||||
params[ SCREENBLURSTRENGTH ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ TOOLMODE ]->IsDefined() )
|
||||
{
|
||||
params[ TOOLMODE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ TOOLCOLORCORRECTION ]->IsDefined() )
|
||||
{
|
||||
params[ TOOLCOLORCORRECTION ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if ( !params[ VOMITENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ VOMITENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ VOMITREFRACTSCALE ]->IsDefined() )
|
||||
{
|
||||
params[ VOMITREFRACTSCALE ]->SetFloatValue( 0.15f );
|
||||
}
|
||||
if ( !params[ VOMITCOLOR1 ]->IsDefined() )
|
||||
{
|
||||
params[ VOMITCOLOR1 ]->SetVecValue( 1.0, 1.0, 0.0 );
|
||||
}
|
||||
if ( !params[ VOMITCOLOR2 ]->IsDefined() )
|
||||
{
|
||||
params[ VOMITCOLOR2 ]->SetVecValue( 0.0, 1.0, 0.0 );
|
||||
}
|
||||
if ( !params[ FADE ]->IsDefined() )
|
||||
{
|
||||
params[ FADE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ FADECOLOR ]->IsDefined() )
|
||||
{
|
||||
params[ FADECOLOR ]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
if ( !params[ TV_GAMMA ]->IsDefined() )
|
||||
{
|
||||
params[ TV_GAMMA ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ DESATURATEENABLE ]->IsDefined() )
|
||||
{
|
||||
params[ DESATURATEENABLE ]->SetIntValue( 0 );
|
||||
}
|
||||
if ( !params[ DESATURATION ]->IsDefined() )
|
||||
{
|
||||
params[ DESATURATION ]->SetFloatValue( 0.0f );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
if ( params[SCREENEFFECTTEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( SCREENEFFECTTEXTURE );
|
||||
}
|
||||
|
||||
if ( params[NOISETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( NOISETEXTURE );
|
||||
}
|
||||
|
||||
if ( params[INTERNAL_VIGNETTETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( INTERNAL_VIGNETTETEXTURE );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
bool bToolMode = params[TOOLMODE]->GetIntValue() != 0;
|
||||
bool bDepthBlurEnable = params[ DEPTHBLURENABLE ]->GetIntValue() != 0;
|
||||
|
||||
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).
|
||||
|
||||
pShaderShadow->EnableBlending( false );
|
||||
|
||||
// The (sRGB) bloom texture is bound to sampler 0
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false );
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
|
||||
// The (sRGB) full framebuffer texture is bound to sampler 1:
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false );
|
||||
|
||||
// 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 );
|
||||
|
||||
// Noise
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER6, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, false );
|
||||
|
||||
// Vignette
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, false );
|
||||
|
||||
// Screen effect texture
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER8, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER8, false );
|
||||
|
||||
pShaderShadow->EnableSRGBWrite( 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() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( TOOL_MODE, bToolMode );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_BLUR_ENABLE, bDepthBlurEnable );
|
||||
SET_STATIC_PIXEL_SHADER( engine_post_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( TOOL_MODE, bToolMode );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_BLUR_ENABLE, false );
|
||||
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 = { false, 0, 1.0f, { 1.0f, 1.0f, 1.0f, 1.0f } };
|
||||
|
||||
float flTime;
|
||||
if ( bToolMode )
|
||||
{
|
||||
flTime = params[TOOLTIME]->GetFloatValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
flTime = pShaderAPI->CurrentTime();
|
||||
}
|
||||
|
||||
// PC, ps20b has a desaturation control that overrides color correction
|
||||
bool bDesaturateEnable = bToolMode && ( params[DESATURATEENABLE]->GetIntValue() != 0 ) && g_pHardwareConfig->SupportsPixelShaders_2_b() && IsPC();
|
||||
|
||||
float vPsConst16[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPsConst16[0] = params[ DESATURATION ]->GetFloatValue();
|
||||
vPsConst16[1] = ( params[FADE]->GetIntValue() == 2 ) ? 1.0f : 0.0f; // Enable lerping to ( color * fadecolor ) for FADE_COLOR=2
|
||||
pShaderAPI->SetPixelShaderConstant( 16, vPsConst16, 1 );
|
||||
|
||||
if ( params[FADE]->GetIntValue() == 0 )
|
||||
{
|
||||
// Not fading, so set the constant to cause nothing to change about the pixel color
|
||||
float vConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
pShaderAPI->SetPixelShaderConstant( 15, vConst );
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderAPI->SetPixelShaderConstant( 15, params[ FADECOLOR ]->GetVecValue(), 1 );
|
||||
}
|
||||
|
||||
if ( !bDesaturateEnable ) // set up color correction
|
||||
{
|
||||
bool bToolColorCorrection = params[TOOLCOLORCORRECTION]->GetIntValue() != 0;
|
||||
if ( bToolColorCorrection )
|
||||
{
|
||||
ccInfo.m_bIsEnabled = true;
|
||||
|
||||
ccInfo.m_nLookupCount = (int) params[NUM_LOOKUPS]->GetFloatValue();
|
||||
ccInfo.m_flDefaultWeight = params[WEIGHT_DEFAULT]->GetFloatValue();
|
||||
ccInfo.m_pLookupWeights[0] = params[WEIGHT0]->GetFloatValue();
|
||||
ccInfo.m_pLookupWeights[1] = params[WEIGHT1]->GetFloatValue();
|
||||
ccInfo.m_pLookupWeights[2] = params[WEIGHT2]->GetFloatValue();
|
||||
ccInfo.m_pLookupWeights[3] = params[WEIGHT3]->GetFloatValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
pShaderAPI->GetCurrentColorCorrection( &ccInfo );
|
||||
}
|
||||
}
|
||||
|
||||
int colCorrectNumLookups = MIN( ccInfo.m_nLookupCount, 3 );
|
||||
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 = ( IsX360() && ( params[ AAINTERNAL1 ]->GetVecValue()[0] != 0.0f ) ) ? 1 : 0;
|
||||
int bloomEnabled = ( params[ BLOOMENABLE ]->GetIntValue() == 0 ) ? 0 : 1;
|
||||
int colCorrectEnabled = ccInfo.m_bIsEnabled;
|
||||
|
||||
float flBloomFactor = bloomEnabled ? 1.0f : 0.0f;
|
||||
flBloomFactor *= params[BLOOMAMOUNT]->GetFloatValue();
|
||||
float bloomConstant[4] =
|
||||
{
|
||||
flBloomFactor,
|
||||
params[ SCREENBLURSTRENGTH ]->GetFloatValue(),
|
||||
params[ DEPTHBLURFOCALDISTANCE ]->GetFloatValue(),
|
||||
params[ DEPTHBLURSTRENGTH ]->GetFloatValue()
|
||||
};
|
||||
|
||||
if ( mat_screen_blur_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
bloomConstant[1] = mat_screen_blur_override.GetFloat();
|
||||
}
|
||||
if ( mat_depth_blur_focal_distance_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
bloomConstant[2] = mat_depth_blur_focal_distance_override.GetFloat();
|
||||
}
|
||||
#ifdef _X360
|
||||
bloomConstant[3] = 0.0f; // Depth blur is currently broken on X360 because we're not writing out the depth scale properly
|
||||
#else // !_X360
|
||||
if ( mat_depth_blur_strength_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
bloomConstant[3] = mat_depth_blur_strength_override.GetFloat();
|
||||
}
|
||||
#endif // _X360
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 5, bloomConstant );
|
||||
|
||||
// Vignette
|
||||
bool bVignetteEnable = ( params[ VIGNETTEENABLE ]->GetIntValue() != 0 ) && ( params[ ALLOWVIGNETTE ]->GetIntValue() != 0 );
|
||||
if ( bVignetteEnable )
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER7, INTERNAL_VIGNETTETEXTURE );
|
||||
}
|
||||
|
||||
// Noise
|
||||
bool bNoiseEnable = ( params[ NOISEENABLE ]->GetIntValue() != 0 ) && ( params[ ALLOWNOISE ]->GetIntValue() != 0 );
|
||||
|
||||
int nFbTextureHeight = params[FBTEXTURE]->GetTextureValue()->GetActualHeight();
|
||||
if ( nFbTextureHeight < 720 )
|
||||
{
|
||||
// Disable noise at low resolutions
|
||||
bNoiseEnable = false;
|
||||
}
|
||||
|
||||
if ( bNoiseEnable )
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER6, NOISETEXTURE );
|
||||
|
||||
// Noise scale
|
||||
float vPsConst6[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPsConst6[0] = params[ NOISESCALE ]->GetFloatValue();
|
||||
if ( mat_grain_scale_override.GetFloat() != -1.0f )
|
||||
{
|
||||
vPsConst6[0] = mat_grain_scale_override.GetFloat();
|
||||
}
|
||||
|
||||
if ( IsX360() )
|
||||
{
|
||||
vPsConst6[0] *= 0.15f;
|
||||
}
|
||||
|
||||
if ( vPsConst6[0] <= 0.0f )
|
||||
{
|
||||
bNoiseEnable = false;
|
||||
}
|
||||
|
||||
pShaderAPI->SetPixelShaderConstant( 6, vPsConst6 );
|
||||
|
||||
// Time % 1000 for scrolling
|
||||
float vPsConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPsConst[0] = flTime;
|
||||
vPsConst[0] -= (float)( (int)( vPsConst[0] / 1000.0f ) ) * 1000.0f;
|
||||
pShaderAPI->SetPixelShaderConstant( 7, vPsConst, 1 );
|
||||
}
|
||||
|
||||
// Local Contrast
|
||||
bool bLocalContrastEnable = ( params[ LOCALCONTRASTENABLE ]->GetIntValue() != 0 ) && ( params[ ALLOWLOCALCONTRAST ]->GetIntValue() != 0 );
|
||||
bool bBlurredVignetteEnable = ( bLocalContrastEnable ) && ( params[ BLURREDVIGNETTEENABLE ]->GetIntValue() != 0 );
|
||||
|
||||
if ( bLocalContrastEnable )
|
||||
{
|
||||
// Contrast scale
|
||||
float vPsConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPsConst[0] = params[ LOCALCONTRASTSCALE ]->GetFloatValue();
|
||||
if ( mat_local_contrast_scale_override.GetFloat() != 0.0f )
|
||||
{
|
||||
vPsConst[0] = mat_local_contrast_scale_override.GetFloat();
|
||||
}
|
||||
vPsConst[1] = params[ LOCALCONTRASTMIDTONEMASK ]->GetFloatValue();
|
||||
if ( mat_local_contrast_midtone_mask_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
vPsConst[1] = mat_local_contrast_midtone_mask_override.GetFloat();
|
||||
}
|
||||
vPsConst[2] = params[ BLURREDVIGNETTESCALE ]->GetFloatValue();
|
||||
pShaderAPI->SetPixelShaderConstant( 8, vPsConst, 1 );
|
||||
|
||||
vPsConst[0] = params[ LOCALCONTRASTVIGNETTESTART ]->GetFloatValue();
|
||||
if ( mat_local_contrast_vignette_start_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
vPsConst[0] = mat_local_contrast_vignette_start_override.GetFloat();
|
||||
}
|
||||
vPsConst[1] = params[ LOCALCONTRASTVIGNETTEEND ]->GetFloatValue();
|
||||
if ( mat_local_contrast_vignette_end_override.GetFloat() >= 0.0f )
|
||||
{
|
||||
vPsConst[1] = mat_local_contrast_vignette_end_override.GetFloat();
|
||||
}
|
||||
vPsConst[2] = params[ LOCALCONTRASTEDGESCALE ]->GetFloatValue();
|
||||
if ( mat_local_contrast_edge_scale_override.GetFloat() >= -1.0f )
|
||||
{
|
||||
vPsConst[2] = mat_local_contrast_edge_scale_override.GetFloat();
|
||||
}
|
||||
pShaderAPI->SetPixelShaderConstant( 9, vPsConst, 1 );
|
||||
}
|
||||
|
||||
// fade to black
|
||||
float vPsConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPsConst[0] = params[ FADETOBLACKSCALE ]->GetFloatValue();
|
||||
pShaderAPI->SetPixelShaderConstant( 10, vPsConst, 1 );
|
||||
|
||||
bool bVomitEnable = ( params[ VOMITENABLE ]->GetIntValue() != 0 );
|
||||
if ( bVomitEnable )
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER8, SCREENEFFECTTEXTURE );
|
||||
|
||||
params[ VOMITCOLOR1 ]->GetVecValue( vPsConst, 3 );
|
||||
vPsConst[3] = params[ VOMITREFRACTSCALE ]->GetFloatValue();
|
||||
pShaderAPI->SetPixelShaderConstant( 11, vPsConst, 1 );
|
||||
params[ VOMITCOLOR2 ]->GetVecValue( vPsConst, 3 );
|
||||
vPsConst[3] = 0.0f;
|
||||
pShaderAPI->SetPixelShaderConstant( 12, vPsConst, 1 );
|
||||
|
||||
// Get viewport and render target dimensions and set shader constant to do a 2D mad
|
||||
int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
|
||||
pShaderAPI->GetCurrentViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
|
||||
|
||||
int nRtWidth, nRtHeight;
|
||||
pShaderAPI->GetCurrentRenderTargetDimensions( nRtWidth, nRtHeight );
|
||||
|
||||
float vViewportMad[4];
|
||||
|
||||
// screen->viewport transform
|
||||
vViewportMad[0] = ( float )nRtWidth / ( float )nViewportWidth;
|
||||
vViewportMad[1] = ( float )nRtHeight / ( float )nViewportHeight;
|
||||
vViewportMad[2] = -( float )nViewportX / ( float )nViewportWidth;
|
||||
vViewportMad[3] = -( float )nViewportY / ( float )nViewportHeight;
|
||||
pShaderAPI->SetPixelShaderConstant( 13, vViewportMad, 1 );
|
||||
|
||||
// viewport->screen transform
|
||||
vViewportMad[0] = ( float )nViewportWidth / ( float )nRtWidth;
|
||||
vViewportMad[1] = ( float )nViewportHeight / ( float )nRtHeight;
|
||||
vViewportMad[2] = ( float )nViewportX / ( float )nRtWidth;
|
||||
vViewportMad[3] = ( float )nViewportY / ( float )nRtHeight;
|
||||
pShaderAPI->SetPixelShaderConstant( 14, vViewportMad, 1 );
|
||||
}
|
||||
|
||||
if ( !colCorrectEnabled )
|
||||
{
|
||||
colCorrectNumLookups = 0;
|
||||
}
|
||||
|
||||
bool bConvertFromLinear = ( g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT );
|
||||
|
||||
// JasonM - double check this if the SFM needs to use the engine post FX clip in main
|
||||
bool bConvertToLinear = bToolMode && bConvertFromLinear && ( g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT );
|
||||
|
||||
if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( engine_post_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_ENABLE, aaEnabled );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( CONVERT_FROM_LINEAR, bConvertFromLinear );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( CONVERT_TO_LINEAR, bConvertToLinear );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( NOISE_ENABLE, bNoiseEnable );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( VIGNETTE_ENABLE, bVignetteEnable );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( LOCAL_CONTRAST_ENABLE, bLocalContrastEnable );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( BLURRED_VIGNETTE_ENABLE, bBlurredVignetteEnable );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( VOMIT_ENABLE, bVomitEnable );
|
||||
#ifndef _X360
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( TV_GAMMA, params[TV_GAMMA]->GetIntValue() && bToolMode ? 1 : 0 );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( DESATURATEENABLE, bDesaturateEnable );
|
||||
#endif
|
||||
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( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( VOMIT_ENABLE, bVomitEnable );
|
||||
SET_DYNAMIC_PIXEL_SHADER( engine_post_ps20 );
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,440 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// FIXMEL4DTOMAINMERGE
|
||||
// Need to re-enable bloom and disable other L4D-only features in here and the cpp file.
|
||||
|
||||
// STATIC: "TOOL_MODE" "0..1"
|
||||
// STATIC: "DEPTH_BLUR_ENABLE" "0..1"
|
||||
|
||||
// DYNAMIC: "AA_ENABLE" "0..0" [PC]
|
||||
// DYNAMIC: "AA_ENABLE" "0..1" [XBOX]
|
||||
|
||||
// DYNAMIC: "COL_CORRECT_NUM_LOOKUPS" "0..3"
|
||||
|
||||
// DYNAMIC: "CONVERT_FROM_LINEAR" "0..1" [ps20b] [ps30] [PC]
|
||||
// DYNAMIC: "CONVERT_TO_LINEAR" "0..1" [ps20b] [ps30] [PC]
|
||||
// DYNAMIC: "CONVERT_FROM_LINEAR" "0..0" [ps20b] [XBOX]
|
||||
// DYNAMIC: "CONVERT_TO_LINEAR" "0..0" [ps20b] [XBOX]
|
||||
// SKIP: ( $CONVERT_FROM_LINEAR == 0 ) && ( $CONVERT_TO_LINEAR == 1 )
|
||||
// SKIP: ( $TOOL_MODE == 0 ) && ( $CONVERT_TO_LINEAR == 1 )
|
||||
|
||||
// DYNAMIC: "NOISE_ENABLE" "0..1" [ps20b] [ps30]
|
||||
// DYNAMIC: "VIGNETTE_ENABLE" "0..1" [ps20b] [ps30]
|
||||
// DYNAMIC: "LOCAL_CONTRAST_ENABLE" "0..1" [ps20b] [ps30]
|
||||
// DYNAMIC: "BLURRED_VIGNETTE_ENABLE" "0..1" [ps20b] [ps30]
|
||||
// DYNAMIC: "VOMIT_ENABLE" "0..1"
|
||||
// SKIP: ( $LOCAL_CONTRAST_ENABLE == 0 ) && ( $BLURRED_VIGNETTE_ENABLE == 1 )
|
||||
|
||||
// DYNAMIC: "TV_GAMMA" "0..1" [ps20b] [PC]
|
||||
// DYNAMIC: "DESATURATEENABLE" "0..1" [ps20b] [PC]
|
||||
// SKIP: ( $TOOL_MODE == 0 ) && $TV_GAMMA
|
||||
// SKIP: ( $TOOL_MODE == 0 ) && $DESATURATEENABLE
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
sampler BaseTextureSampler : register( s0 );
|
||||
sampler FBTextureSampler : register( s1 );
|
||||
sampler ColorCorrectionVolumeTexture0 : register( s2 );
|
||||
sampler ColorCorrectionVolumeTexture1 : register( s3 );
|
||||
sampler ColorCorrectionVolumeTexture2 : register( s4 );
|
||||
sampler ColorCorrectionVolumeTexture3 : register( s5 );
|
||||
sampler NoiseSampler : register( s6 );
|
||||
sampler VignetteSampler : register( s7 );
|
||||
sampler ScreenEffectSampler : register( s8 ); // used for vomit/paint screen particle effects
|
||||
|
||||
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 );
|
||||
|
||||
// Bloom & Depth Blur parameters
|
||||
// x: bloom amount; multiply bloom downscale buffer by this value and add to base color
|
||||
// y: bloom lerp amount; lerp between base color and blurred bloom buffer with this factor (allows for color bleeding in dark areas)
|
||||
// z: depth blur focal plane distance. Value is in dest alpha space [0,1], not world units.
|
||||
// w: depth blur scale value; scale distance from focal plane by this amount
|
||||
float4 BloomParameters : register( c5 );
|
||||
#define g_flBloomAmount ( BloomParameters.x )
|
||||
#define g_flBloomLerpFactor ( BloomParameters.y )
|
||||
#define g_flDepthBlurFocalDistance ( BloomParameters.z )
|
||||
#define g_flDepthBlurScale ( BloomParameters.w )
|
||||
|
||||
float g_flNoiseScalar : register( c6 );
|
||||
float g_flTime : register( c7 );
|
||||
float4 g_vLocalContrastParams : register( c8 );
|
||||
#define g_flLocalContrastStrength g_vLocalContrastParams.x
|
||||
#define g_flLocalContrastMidToneMask g_vLocalContrastParams.y
|
||||
#define g_flBlurredVignetteStrength g_vLocalContrastParams.z
|
||||
|
||||
float4 g_vLocalContrastVignetteParams : register( c9 );
|
||||
#define g_flLocalContrastVignetteStart g_vLocalContrastVignetteParams.x
|
||||
#define g_flLocalContrastVignetteEnd g_vLocalContrastVignetteParams.y
|
||||
#define g_flLocalContrastEdgeStrength g_vLocalContrastVignetteParams.z
|
||||
|
||||
float g_flFadeToBlackStrength : register( c10 );
|
||||
|
||||
float4 g_vVomitColor[2] : register( c11 );
|
||||
#define g_flVomitRefractStrength g_vVomitColor[0].a
|
||||
|
||||
float4 g_vViewportTransform : register( c13 );
|
||||
float4 g_vInvViewportTransform : register( c14 );
|
||||
|
||||
float4 g_vViewFadeColor : register( c15 );
|
||||
|
||||
float2 g_c16 : register( c16 );
|
||||
#define g_flDesaturation g_c16.x
|
||||
#define g_flFadeMode2 g_c16.y
|
||||
|
||||
float Luminance( float3 cColor )
|
||||
{
|
||||
float3 tmpv = { 0.2125, 0.7154, 0.0721 };
|
||||
float flLuminance = dot( cColor.rgb, tmpv.rgb );
|
||||
return flLuminance;
|
||||
}
|
||||
|
||||
float4 GetBloomColor( float2 bloomUV )
|
||||
{
|
||||
return tex2D( BaseTextureSampler, bloomUV );
|
||||
}
|
||||
|
||||
float4 PerformColorCorrection( float4 outColor )
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
float3 PerformVomitBlend( float3 vRefractParams, float3 vFullResColor, float3 vBlurredColor )
|
||||
{
|
||||
float3 vVomitColor = lerp( g_vVomitColor[0].rgb, g_vVomitColor[1].rgb, vRefractParams.z ); // vomit tint
|
||||
|
||||
vFullResColor.rgb *= lerp( float3( 1, 1, 1 ), vVomitColor, vRefractParams.z ); // vomit tint full-res buffer
|
||||
vFullResColor.rgb = lerp ( vFullResColor.rgb, vVomitColor.rgb * vBlurredColor.rgb, vRefractParams.z );
|
||||
return vFullResColor.rgb;
|
||||
}
|
||||
|
||||
float2 PerformUVTransform( float2 bloomUVs )
|
||||
{
|
||||
// NOTE: 'wz' is used since 'zw' is not a valid swizzle for ps20 shaders
|
||||
return bloomUVs*uvTransform.wz + uvTransform.xy;
|
||||
}
|
||||
|
||||
// Apply TV Gamma for movie layoff specific to 360 TV movie playback path
|
||||
float3 SrgbGammaToTvGamma( float3 cInput )
|
||||
{
|
||||
float3 cLinear = SrgbGammaToLinear( cInput );
|
||||
return pow( cLinear, 1.0f / 2.5f );
|
||||
}
|
||||
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 baseTexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 fbTexCoord = 0;
|
||||
#if !defined( SHADER_MODEL_PS_2_0 )
|
||||
{
|
||||
fbTexCoord.xy = PerformUVTransform( i.baseTexCoord );
|
||||
fbTexCoord.zw = i.baseTexCoord;
|
||||
}
|
||||
#else
|
||||
{
|
||||
fbTexCoord.xy = PerformUVTransform( i.baseTexCoord );
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 cBloomBlurredLum = GetBloomColor( i.baseTexCoord ); // bloom color and blurred luminance in alpha
|
||||
float4 vVomitRefractParams;
|
||||
#if ( VOMIT_ENABLE == 1 )
|
||||
{
|
||||
// perturb texture coordinate
|
||||
vVomitRefractParams = tex2D( ScreenEffectSampler, i.baseTexCoord );
|
||||
fbTexCoord = fbTexCoord + g_flVomitRefractStrength * ( vVomitRefractParams.xyxy - 0.5 );
|
||||
|
||||
#if !defined( SHADER_MODEL_PS_2_0 )
|
||||
{
|
||||
// screen coords -> viewport coords
|
||||
float4 vNormalizedTexCoord = g_vViewportTransform.xyxy * fbTexCoord + g_vViewportTransform.zwzw;
|
||||
// mirrored repeat texcoord math doesn't fit into 2.0
|
||||
vNormalizedTexCoord = min( 2.0 - vNormalizedTexCoord, abs( vNormalizedTexCoord ) );
|
||||
// viewport coords -> screen coords
|
||||
fbTexCoord = g_vInvViewportTransform.xyxy * vNormalizedTexCoord + g_vInvViewportTransform.zwzw;
|
||||
|
||||
cBloomBlurredLum = GetBloomColor( fbTexCoord.zw ); // fetch again with perturbed texcoords
|
||||
}
|
||||
#else
|
||||
{
|
||||
cBloomBlurredLum = GetBloomColor( fbTexCoord.xy ); // fetch again with perturbed texcoords
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 rawColor = tex2D( FBTextureSampler, fbTexCoord.xy ).rgba;
|
||||
float3 baseColor = rawColor.rgb;
|
||||
float depthValue = rawColor.a;
|
||||
|
||||
#if ( CONVERT_FROM_LINEAR == 1 )
|
||||
{
|
||||
baseColor.rgb = SrgbLinearToGamma( baseColor.rgb );
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 outColor = float4( baseColor, 1 );
|
||||
|
||||
#if ( AA_ENABLE == 1 )
|
||||
{
|
||||
float3 up;
|
||||
float3 dn;
|
||||
float3 lf;
|
||||
float3 rt;
|
||||
float3 uplf;
|
||||
float3 uprt;
|
||||
float3 dnlf;
|
||||
float3 dnrt;
|
||||
|
||||
#if defined( _X360 )
|
||||
asm
|
||||
{
|
||||
tfetch2D up.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = 0.0, OffsetY = -1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D dn.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = 0.0, OffsetY = 1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D lf.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = -1.0, OffsetY = 0.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D rt.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = 1.0, OffsetY = 0.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
|
||||
tfetch2D uplf.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = -1.0, OffsetY = -1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D uprt.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = 1.0, OffsetY = -1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D dnlf.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = -1.0, OffsetY = 1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
tfetch2D dnrt.xyz, fbTexCoord.xy, FBTextureSampler, OffsetX = 1.0, OffsetY = 1.0, MagFilter = point, MinFilter = point, MipFilter = point
|
||||
};
|
||||
#else
|
||||
{
|
||||
// psTapOffs_packed contains 1-pixel offsets: ( +dX, 0, +dY, -dX )
|
||||
float4 texelDelta = psTapOffs_Packed.xyzw;
|
||||
dn = tex2D( FBTextureSampler, fbTexCoord.xy + texelDelta.yz ).rgb; // ( 0,+1)
|
||||
rt = tex2D( FBTextureSampler, fbTexCoord.xy + texelDelta.xy ).rgb; // (+1, 0)
|
||||
up = tex2D( FBTextureSampler, fbTexCoord.xy - texelDelta.yz ).rgb; // ( 0,-1)
|
||||
lf = tex2D( FBTextureSampler, fbTexCoord.xy - texelDelta.xy ).rgb; // (-1, 0)
|
||||
dnlf = tex2D( FBTextureSampler, fbTexCoord.xy + texelDelta.wz ).rgb; // (-1,+1)
|
||||
uprt = tex2D( FBTextureSampler, fbTexCoord.xy - 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!
|
||||
uplf = tex2D( FBTextureSampler, fbTexCoord.xy + texelDelta.xy ).rgb; // (+1,+1)
|
||||
dnrt = tex2D( FBTextureSampler, fbTexCoord.xy - texelDelta.xy ).rgb; // (-1,-1)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Generate the edge mask
|
||||
float flBaseLum = Luminance( baseColor.rgb );
|
||||
float flEdge = saturate( abs( Luminance( dn.rgb ) - flBaseLum ) - 0.1 );
|
||||
flEdge += saturate( abs( Luminance( up.rgb ) - flBaseLum ) - 0.1 );
|
||||
flEdge += saturate( abs( Luminance( lf.rgb ) - flBaseLum ) - 0.1 );
|
||||
flEdge += saturate( abs( Luminance( rt.rgb ) - flBaseLum ) - 0.1 );
|
||||
flEdge *= 5.0;
|
||||
#if defined( _X360 )
|
||||
flEdge *= 4.0; // Magic number to compensate for 360 gamma space
|
||||
#endif
|
||||
|
||||
// Average full 3x3 neighborhood of pixels giving more weight to the center sample
|
||||
float3 vBlurColor = ( baseColor.rgb * 4.0f ) + up.rgb + dn.rgb + lf.rgb + rt.rgb + dnrt.rgb + uprt.rgb + dnlf.rgb + uplf.rgb;
|
||||
vBlurColor.rgb *= 0.0833333; // 1.0 / 12.0
|
||||
|
||||
// Lerp between crisp and blurry pixel based on edge mask
|
||||
outColor.rgb = lerp( baseColor.rgb, vBlurColor.rgb, saturate( flEdge ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( VOMIT_ENABLE == 1 )
|
||||
{
|
||||
outColor.rgb = PerformVomitBlend( vVomitRefractParams.xyz, outColor.rgb, cBloomBlurredLum.aaa );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( LOCAL_CONTRAST_ENABLE == 1 )
|
||||
{
|
||||
float fMask = 1.0;
|
||||
|
||||
// Extract midtones and limit contrast enhancement there
|
||||
// TODO: This can probably go away for perf.
|
||||
//float fBrightness = dot( outColor.rgb, float3( 0.3, 0.59, 0.11 ) );
|
||||
// bell-shaped mask
|
||||
//fMask = smoothstep( 0.5 - g_flLocalContrastMidToneMask, 0.5, fBrightness );
|
||||
//fMask *= smoothstep( 0.5 + g_flLocalContrastMidToneMask, 0.5, fBrightness );
|
||||
|
||||
//fMask = smoothstep( 1.0, 0.5, fBrightness );
|
||||
|
||||
/*
|
||||
// unsharp mask on luminance only
|
||||
// This is the technically correct way, going to YUV, applying contrast to Y, and converting back to RGB
|
||||
float3 outColorYUV;
|
||||
outColorYUV.x = dot( outColor.rgb, float3( 0.299, 0.587, 0.114 ) );
|
||||
outColorYUV.y = dot( outColor.rgb, float3( -0.14713, -0.28886, 0.436 ) );
|
||||
outColorYUV.z = dot( outColor.rgb, float3( 0.615, -0.51499, -0.10001 ) );
|
||||
outColorYUV.x = outColorYUV.x + g_flLocalContrastStrength * fMask * ( outColorYUV.x - cBloomBlurredLum.aaa );
|
||||
outColor.r = dot( outColorYUV.xyz, float3( 1.0, 0.0, 1.13983 ) );
|
||||
outColor.g = dot( outColorYUV.xyz, float3( 1.0, -0.39465, -0.58060 ) );
|
||||
outColor.b = dot( outColorYUV.xyz, float3( 1.0, 2.03211, 0.0 ) );
|
||||
*/
|
||||
|
||||
// This applies the delta contrast derived from the luminance to all color channels. The difference to the
|
||||
// correct way is imperceptible.
|
||||
float fLuminance = dot( outColor.rgb, float3( 0.299, 0.587, 0.114 ) );
|
||||
float fContrastLum = fLuminance + g_flLocalContrastStrength * ( fLuminance - cBloomBlurredLum.a );
|
||||
|
||||
// Mask off pixels that got very bright, to control super-contrast
|
||||
//fMask = 1.0 - smoothstep( 0.3, 1.0, fContrastLum );
|
||||
|
||||
float2 vCenterDir = ( 2.0 * i.baseTexCoord.xy ) - 1.0;
|
||||
float fMyVignette = smoothstep( g_flLocalContrastVignetteStart, g_flLocalContrastVignetteEnd, length( vCenterDir ) );
|
||||
float fMyVignette2 = fMyVignette;
|
||||
fMyVignette = lerp( g_flLocalContrastStrength, g_flLocalContrastEdgeStrength, fMyVignette );
|
||||
|
||||
fMask = fMyVignette;
|
||||
|
||||
// If the mask is positive, only brighten pixels. If the mask is negative, don't let it get less than -1.0.
|
||||
//outColor.rgb += fMask * ( fLuminance - cBloomBlurredLum.aaa );
|
||||
outColor.rgb += max( fMask * ( fLuminance - cBloomBlurredLum.aaa ), -1.0 + step( 0.0, fMask ) ); // Selective clamp to positive adds 4 instructions
|
||||
|
||||
#if ( BLURRED_VIGNETTE_ENABLE == 1 )
|
||||
outColor.rgb = lerp( outColor.rgb, cBloomBlurredLum.aaa, fMyVignette2 * g_flBlurredVignetteStrength );
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Composite bloom and full-screen + depth blur effects
|
||||
#if ( DEPTH_BLUR_ENABLE )
|
||||
{
|
||||
float blurFactor = g_flBloomLerpFactor + abs( depthValue - g_flDepthBlurFocalDistance ) * g_flDepthBlurScale;
|
||||
blurFactor = clamp( blurFactor, 0, 1 );
|
||||
outColor.rgb = lerp( outColor.rgb, cBloomBlurredLum.rgb, blurFactor );
|
||||
outColor.rgb += g_flBloomAmount * cBloomBlurredLum.rgb;
|
||||
}
|
||||
#else
|
||||
{
|
||||
outColor.rgb += g_flBloomAmount * cBloomBlurredLum.rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Used to be FADE_TYPE 0..2 combo
|
||||
float3 vFadeDestColor = lerp( g_vViewFadeColor.rgb, g_vViewFadeColor.rgb * outColor.rgb, g_flFadeMode2 );
|
||||
outColor.rgb = lerp( outColor.rgb, vFadeDestColor.rgb, g_vViewFadeColor.a );
|
||||
|
||||
#if ( DESATURATEENABLE )
|
||||
{
|
||||
float flLum = saturate( dot( outColor.rgb, float3( 0.3f, 0.59f, 0.11f) ) );
|
||||
outColor.rgb = lerp( saturate( outColor.rgb ), flLum.xxx, saturate( g_flDesaturation ) );
|
||||
}
|
||||
#else
|
||||
{
|
||||
outColor = PerformColorCorrection( outColor ); // Color correction
|
||||
}
|
||||
#endif
|
||||
|
||||
// Vignette
|
||||
#if ( VIGNETTE_ENABLE == 1 )
|
||||
{
|
||||
// Vignette
|
||||
float2 vUv = i.baseTexCoord.xy;
|
||||
//float2 vTmp = ( vUv.xy * 2.0 ) - 1.0;
|
||||
float flVignette;
|
||||
|
||||
#if defined( _X360 )
|
||||
{
|
||||
// Make title safe and deal with different gamma space
|
||||
//flVignette = 1.0 - pow( abs( vTmp.x ), 4.0f );
|
||||
//flVignette *= 1.0 - pow( abs( vTmp.y ), 4.0f );
|
||||
//flVignette = 1.0 - ( 1.0 - flVignette ) * ( ( saturate( ( 1.0 - vUv.y ) - 0.1 ) / 0.9 ) );
|
||||
|
||||
// This tex2D solves the 3 lines of math above
|
||||
flVignette = tex2D( VignetteSampler, vUv.xy ).g; // Green is for the 360
|
||||
flVignette = saturate( flVignette * 0.75 + 0.26 );
|
||||
}
|
||||
#else
|
||||
{
|
||||
//flVignette = 1.0 - pow( abs( vTmp.x ), 6.0f );
|
||||
//flVignette *= 1.0 - pow( abs( vTmp.y ), 6.0f );
|
||||
//flVignette = 1.0 - ( 1.0 - flVignette ) * ( ( saturate( ( 1.0 - vUv.y ) - 0.3 ) / 0.7 ) );
|
||||
|
||||
// This tex2D solves the 3 lines of math above
|
||||
flVignette = tex2D( VignetteSampler, vUv.xy ).r; // Red is for the PC
|
||||
flVignette = saturate( flVignette * 0.55 + 0.46 );
|
||||
}
|
||||
#endif
|
||||
|
||||
outColor.rgb *= flVignette;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Noise
|
||||
#if ( NOISE_ENABLE == 1 )
|
||||
{
|
||||
// Additive Noise
|
||||
float2 vUv0 = i.baseTexCoord.xy * 10.0 + g_flTime;
|
||||
float2 vUv1 = i.baseTexCoord.yx * 20.0 - g_flTime;
|
||||
float2 vNoiseTexelUv;
|
||||
vNoiseTexelUv.x = tex2D( NoiseSampler, vUv0.xy ).g;
|
||||
vNoiseTexelUv.y = tex2D( NoiseSampler, vUv1.xy ).g;
|
||||
float flNoiseTexel = tex2D( NoiseSampler, vNoiseTexelUv.xy ).g;
|
||||
|
||||
float3 vTmp = { 0.2125f, 0.7154f, 0.0721f };
|
||||
float flLuminance = saturate( dot( outColor.rgb, vTmp.rgb ) );
|
||||
|
||||
#if defined( _X360 )
|
||||
{
|
||||
// 360
|
||||
float flNoiseScalar = 0.2f + 1.0f * ( saturate( pow( 1.0 - flLuminance, 64.0 ) ) );
|
||||
outColor.rgb += ( ( flNoiseTexel * 0.3f ) - 0.15f ) * g_flNoiseScalar * flNoiseScalar;
|
||||
}
|
||||
#else
|
||||
{
|
||||
// PC
|
||||
float flNoiseScalar = 0.2f + 0.8f * ( saturate( pow( 1.0 - flLuminance, 12.0 ) ) );
|
||||
outColor.rgb += ( ( flNoiseTexel * 0.3f ) - 0.15f ) * g_flNoiseScalar * flNoiseScalar;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Fade to black
|
||||
outColor.rgb = lerp( outColor.rgb, 0.0, g_flFadeToBlackStrength );
|
||||
|
||||
#if TV_GAMMA
|
||||
{
|
||||
// Used for SFM to record movies in native TV gamma space
|
||||
outColor.rgb = SrgbGammaToTvGamma( outColor.rgb );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( CONVERT_TO_LINEAR == 1 )
|
||||
{
|
||||
// If we have a float back buffer, we want to remain in linear space after this shader
|
||||
outColor.rgb = SrgbGammaToLinear( outColor.rgb );
|
||||
}
|
||||
#endif
|
||||
|
||||
return FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
//========== Copyright (c) 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"
|
||||
|
||||
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
|
||||
// DYNAMIC: "SKINNING" "0..1"
|
||||
#include "common_fog_vs_fxc.h"
|
||||
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
|
||||
// DYNAMIC: "STATIC_LIGHT" "0..1"
|
||||
|
||||
// DYNAMIC: "MORPHING" "0..1" [vs30] [ = pShaderAPI->IsHWMorphingEnabled() ]
|
||||
|
||||
#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 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
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 = (VS_OUTPUT)0;
|
||||
|
||||
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
|
||||
o.projPos = mul( float4( worldPos, 1 ), cViewProj );
|
||||
o.worldPos_projPosZ = float4( worldPos.xyz, o.projPos.z );
|
||||
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
o.fog = CalcFixedFunctionFog( worldPos, 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);
|
||||
|
||||
// Compute vertex lighting
|
||||
o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert );
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//========= Copyright © 1996-2004, Valve LLC, 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"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.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
|
||||
{
|
||||
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
|
|
@ -0,0 +1,23 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#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 );
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
//========= Copyright © 1996-2004, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "common_hlsl_cpp_consts.h"
|
||||
|
||||
#include "hdrselectrange_ps20.inc"
|
||||
#include "hdrselectrange_ps20b.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
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
|
|
@ -0,0 +1,42 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "unlittwotexture_vs20.inc"
|
||||
#include "monitorscreen_ps20.inc"
|
||||
#include "monitorscreen_ps20b.inc"
|
||||
#include "cpp_shader_constant_register_map.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
DEFINE_FALLBACK_SHADER( MonitorScreen, MonitorScreen_DX9 )
|
||||
|
||||
BEGIN_VS_SHADER( MonitorScreen_DX9,
|
||||
"This is a shader that does a contrast/saturation version of base times lightmap." )
|
||||
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( CONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
|
||||
SHADER_PARAM( SATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
|
||||
SHADER_PARAM( TINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "monitor tint" )
|
||||
SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "second texture" )
|
||||
SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" )
|
||||
SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
// Set up anything that is necessary to make decisions in SHADER_FALLBACK.
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
|
||||
if( !params[CONTRAST]->IsDefined() )
|
||||
{
|
||||
params[CONTRAST]->SetFloatValue( 0.0f );
|
||||
}
|
||||
if( !params[SATURATION]->IsDefined() )
|
||||
{
|
||||
params[SATURATION]->SetFloatValue( 1.0f );
|
||||
}
|
||||
if( !params[TINT]->IsDefined() )
|
||||
{
|
||||
params[TINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
|
||||
}
|
||||
if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ))
|
||||
{
|
||||
CLEAR_FLAGS( MATERIAL_VAR_MODEL );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
if( params && !params[BASETEXTURE]->IsDefined() )
|
||||
return "LightmappedGeneric";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
if (params[BASETEXTURE]->IsDefined())
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
if (params[TEXTURE2]->IsDefined())
|
||||
{
|
||||
LoadTexture( TEXTURE2 );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
bool bHasTexture2 = params[TEXTURE2]->IsTexture();
|
||||
BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
|
||||
bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
|
||||
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
|
||||
if ( bHasTexture2 )
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
|
||||
}
|
||||
|
||||
pShaderShadow->EnableSRGBWrite( true );
|
||||
|
||||
// Either we've got a constant modulation
|
||||
bool isTranslucent = IsAlphaModulating();
|
||||
|
||||
// Or we've got a texture alpha on either texture
|
||||
isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) ||
|
||||
TextureIsTranslucent( TEXTURE2, true );
|
||||
|
||||
if ( isTranslucent )
|
||||
{
|
||||
if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
|
||||
else
|
||||
EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
|
||||
EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
|
||||
else
|
||||
DisableAlphaBlending( );
|
||||
}
|
||||
|
||||
// Set stream format (note that this shader supports compression)
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
|
||||
int nTexCoordCount = 1;
|
||||
int userDataSize = 0;
|
||||
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( unlittwotexture_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( unlittwotexture_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) );
|
||||
SET_STATIC_PIXEL_SHADER( monitorscreen_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) );
|
||||
SET_STATIC_PIXEL_SHADER( monitorscreen_ps20 );
|
||||
}
|
||||
|
||||
DefaultFog();
|
||||
|
||||
pShaderShadow->EnableAlphaWrites( bFullyOpaque );
|
||||
PI_BeginCommandBuffer();
|
||||
PI_SetModulationVertexShaderDynamicState();
|
||||
PI_EndCommandBuffer();
|
||||
}
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
|
||||
if( bHasTexture2 )
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 );
|
||||
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM );
|
||||
}
|
||||
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
|
||||
SetPixelShaderConstant( 1, CONTRAST );
|
||||
SetPixelShaderConstant( 2, SATURATION );
|
||||
SetPixelShaderConstant( 3, TINT );
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( WORLD_NORMAL, 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
|
||||
SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 );
|
||||
SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 );
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,143 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
// STATIC: "MODEL" "0..1"
|
||||
// STATIC: "COLORMODULATE" "0..1"
|
||||
|
||||
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
|
||||
// DYNAMIC: "SKINNING" "0..1"
|
||||
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
static const bool g_bSkinning = SKINNING ? true : false;
|
||||
static const bool g_bModel = MODEL ? true : false;
|
||||
|
||||
const float4 cBumpTexCoordTransform[4] : register( SHADER_SPECIFIC_CONST_1 );
|
||||
|
||||
const float g_flTime : register( SHADER_SPECIFIC_CONST_5 );
|
||||
|
||||
const float4 g_vViewportMad : register( SHADER_SPECIFIC_CONST_6 );
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 vPos : POSITION;
|
||||
float4 vBoneWeights : BLENDWEIGHT;
|
||||
float4 vBoneIndices : BLENDINDICES;
|
||||
float4 vNormal : NORMAL;
|
||||
float4 vBaseTexCoord : TEXCOORD0;
|
||||
#if !MODEL
|
||||
float3 vTangentS : TANGENT;
|
||||
float3 vTangentT : BINORMAL0;
|
||||
#else
|
||||
float4 vUserData : TANGENT;
|
||||
#endif
|
||||
#if COLORMODULATE
|
||||
float4 vColor : COLOR0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 vProjPos_POSITION : POSITION;
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
float fog : FOG;
|
||||
#endif
|
||||
float4 vBumpTexCoord : TEXCOORD0;
|
||||
float3 vTangentEyeVect : TEXCOORD1;
|
||||
float3 vWorldNormal : TEXCOORD2;
|
||||
float3 vWorldTangent : TEXCOORD3;
|
||||
float3 vWorldBinormal : TEXCOORD4;
|
||||
float3 vRefractXYW : TEXCOORD5;
|
||||
float3 vWorldViewVector : TEXCOORD6;
|
||||
#if COLORMODULATE
|
||||
float4 vColor : COLOR0;
|
||||
#endif
|
||||
|
||||
float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
|
||||
};
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o = ( VS_OUTPUT )0;
|
||||
|
||||
#if COLORMODULATE
|
||||
o.vColor = v.vColor;
|
||||
#endif
|
||||
|
||||
float3 worldNormal, worldPos, worldTangentS, worldTangentT;
|
||||
|
||||
float3 vObjNormal;
|
||||
#if MODEL
|
||||
float4 vObjTangent;
|
||||
DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vObjNormal, vObjTangent );
|
||||
|
||||
SkinPositionNormalAndTangentSpace(
|
||||
g_bSkinning,
|
||||
v.vPos, vObjNormal, vObjTangent,
|
||||
v.vBoneWeights, v.vBoneIndices,
|
||||
worldPos, worldNormal, worldTangentS, worldTangentT );
|
||||
#else
|
||||
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
||||
|
||||
worldPos = mul( v.vPos, cModel[0] );
|
||||
worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] );
|
||||
worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] );
|
||||
worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
|
||||
#endif
|
||||
|
||||
// World normal
|
||||
o.vWorldNormal.xyz = normalize( worldNormal.xyz );
|
||||
|
||||
// Projected position
|
||||
float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
|
||||
o.vProjPos_POSITION = vProjPos;
|
||||
o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
|
||||
//o.projNormal.xyz = mul( worldNormal, cViewProj );
|
||||
|
||||
// Map projected position to the refraction texture
|
||||
float2 vRefractPos;
|
||||
vRefractPos.x = vProjPos.x;
|
||||
vRefractPos.y = -vProjPos.y; // invert Y
|
||||
vRefractPos = (vRefractPos + vProjPos.w) * 0.5f;
|
||||
|
||||
// Adjust for current viewport
|
||||
vRefractPos.xy = ( ( ( vRefractPos.xy / vProjPos.w ) * g_vViewportMad.xy ) + g_vViewportMad.zw ) * vProjPos.w;
|
||||
|
||||
// Refraction transform
|
||||
o.vRefractXYW = float3(vRefractPos.x, vRefractPos.y, vProjPos.w);
|
||||
|
||||
// Compute fog based on the position
|
||||
float3 vWorldPos = mul( v.vPos, cModel[0] );
|
||||
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
o.fog = CalcFixedFunctionFog( vWorldPos, FOGTYPE_RANGE );
|
||||
#endif
|
||||
|
||||
// Eye vector
|
||||
float3 vWorldEyeVect = normalize( cEyePos - vWorldPos );
|
||||
o.vWorldViewVector.xyz = -vWorldEyeVect.xyz;
|
||||
|
||||
// Transform to the tangent space
|
||||
o.vTangentEyeVect.x = dot( vWorldEyeVect, worldTangentS );
|
||||
o.vTangentEyeVect.y = dot( vWorldEyeVect, worldTangentT );
|
||||
o.vTangentEyeVect.z = dot( vWorldEyeVect, worldNormal );
|
||||
|
||||
// Tranform bump coordinates
|
||||
o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
|
||||
o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
|
||||
|
||||
// Tranform bump coordinates (note wz, not zw)
|
||||
o.vBumpTexCoord.w = dot( v.vBaseTexCoord, cBumpTexCoordTransform[2] );
|
||||
o.vBumpTexCoord.z = dot( v.vBaseTexCoord, cBumpTexCoordTransform[3] );
|
||||
|
||||
|
||||
// Tangent space transform
|
||||
o.vWorldNormal.xyz = normalize( worldNormal.xyz );
|
||||
o.vWorldTangent.xyz = worldTangentS.xyz;
|
||||
o.vWorldBinormal.xyz = worldTangentT.xyz;
|
||||
|
||||
return o;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
vs.1.1
|
||||
|
||||
# DYNAMIC: "DOWATERFOG" "0..1"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Constants specified by the app
|
||||
; c0 = (0, 1, 2, 0.5)
|
||||
; c1 = (1/2.2, 3, 255, overbright factor)
|
||||
; c2 = camera position *in world space*
|
||||
; c4-c7 = modelViewProj matrix (transpose)
|
||||
; c8-c11 = ViewProj matrix (transpose)
|
||||
; c12-c15 = model->view matrix (transpose)
|
||||
; c16 = [fogStart, fogEnd, fogRange, 1.0/fogRange]
|
||||
; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform
|
||||
; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include "macros.vsh"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; No vertex blending required. Input vertex data is in screen space
|
||||
;------------------------------------------------------------------------------
|
||||
mov oPos.xyz, $vPos.xyz
|
||||
mov oPos.w, $cOne
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Pass any and all texture coordinates through
|
||||
;------------------------------------------------------------------------------
|
||||
mov oT0, $vTexCoord0
|
|
@ -0,0 +1,43 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Naively sets the depth buffer values without testing the old values and without writing to alpha or color
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "shaderlib/CShader.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
DEFINE_FALLBACK_SHADER( SetZ, SetZ_DX6 )
|
||||
|
||||
BEGIN_SHADER_FLAGS( SetZ_DX6, "Help for SetZ_DX6", SHADER_NOT_EDITABLE )
|
||||
BEGIN_SHADER_PARAMS
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableColorWrites( false );
|
||||
pShaderShadow->EnableAlphaWrites( false );
|
||||
pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS );
|
||||
|
||||
pShaderShadow->DrawFlags( SHADER_DRAW_POSITION );
|
||||
}
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
END_SHADER
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
ps.1.1
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Draw a texture . . woo hoo!
|
||||
; t0 - texture
|
||||
;
|
||||
; The texture coordinates need to be defined as follows:
|
||||
; tc0 - texcoords
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
def c0,1.0f, 1.0f, 1.0f, 1.0f
|
||||
|
||||
tex t0 ; shadow color
|
||||
texkill t1 ; Clip
|
||||
texkill t2
|
||||
texkill t3 ; backface cull
|
||||
|
||||
; Darkening equation, compute a color = (shadow color * shadow alpha + 1- shadow alpha)
|
||||
;sub r1, t0, v0.a ; r1 = shadow alpha
|
||||
lrp r0.rgb, t0.a, v0, c0 + ; r0.rgb = (shadow color * shadow alpha + 1 - shadow alpha)
|
||||
mov r0.a, c0.a ; r0.a = 1
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
vs.1.1
|
||||
|
||||
# DYNAMIC: "DOWATERFOG" "0..1"
|
||||
# DYNAMIC: "SKINNING" "0..1"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Constants specified by the app
|
||||
; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_2 = Shadow texture matrix
|
||||
; $SHADER_SPECIFIC_CONST_3 = Tex origin
|
||||
; $SHADER_SPECIFIC_CONST_4 = Tex Scale
|
||||
; $SHADER_SPECIFIC_CONST_5 = [Shadow falloff offset, 1/Shadow distance, Shadow scale, 0 ]
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include "macros.vsh"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vertex blending (whacks r1-r7, positions in r7, normals in r8)
|
||||
;------------------------------------------------------------------------------
|
||||
&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 );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Transform position into texture space (from 0 to 1)
|
||||
;------------------------------------------------------------------------------
|
||||
&AllocateRegister( \$texturePos );
|
||||
dp4 $texturePos.x, $worldPos, $SHADER_SPECIFIC_CONST_0
|
||||
dp4 $texturePos.y, $worldPos, $SHADER_SPECIFIC_CONST_1
|
||||
dp4 $texturePos.z, $worldPos, $SHADER_SPECIFIC_CONST_2
|
||||
&FreeRegister( \$worldPos );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Figure out the shadow fade amount
|
||||
;------------------------------------------------------------------------------
|
||||
&AllocateRegister( \$shadowFade );
|
||||
sub $shadowFade, $texturePos.z, $SHADER_SPECIFIC_CONST_5.x
|
||||
mul $shadowFade, $shadowFade, $SHADER_SPECIFIC_CONST_5.y
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Offset it into the texture
|
||||
;------------------------------------------------------------------------------
|
||||
&AllocateRegister( \$actualTextureCoord );
|
||||
mul $actualTextureCoord.xyz, $SHADER_SPECIFIC_CONST_4, $texturePos
|
||||
add oT0.xyz, $actualTextureCoord, $SHADER_SPECIFIC_CONST_3
|
||||
;mov oT0.xyz, $texturePos
|
||||
&FreeRegister( \$actualTextureCoord );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; We're doing clipping by using texkill
|
||||
;------------------------------------------------------------------------------
|
||||
mov oT1.xyz, $texturePos ; also clips when shadow z < 0 !
|
||||
sub oT2.xyz, $cOne, $texturePos
|
||||
sub oT2.z, $cOne, $shadowFade.z ; clips when shadow z > shadow distance
|
||||
&FreeRegister( \$texturePos );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; We're doing backface culling by using texkill also (wow yucky)
|
||||
;------------------------------------------------------------------------------
|
||||
; Transform z component of normal in texture space
|
||||
; If it's negative, then don't draw the pixel
|
||||
dp3 oT3, $worldNormal, -$SHADER_SPECIFIC_CONST_2
|
||||
&FreeRegister( \$worldNormal );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Shadow color, falloff
|
||||
;------------------------------------------------------------------------------
|
||||
mov oD0, $cModulationColor
|
||||
mul oD0.w, $shadowFade.x, $SHADER_SPECIFIC_CONST_5.z
|
||||
&FreeRegister( \$shadowFade );
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "CUBEMAP" "0..1"
|
||||
// STATIC: "VERTEXCOLOR" "0..1"
|
||||
// STATIC: "ENVMAPMASK" "0..1"
|
||||
// STATIC: "BASEALPHAENVMAPMASK" "0..1"
|
||||
// STATIC: "HDRTYPE" "0..2"
|
||||
|
||||
#include "common_fog_ps_fxc.h"
|
||||
|
||||
// HDRFIXME: Need to make this work.
|
||||
|
||||
#define USE_32BIT_LIGHTMAPS_ON_360 //uncomment to use 32bit lightmaps, be sure to keep this in sync with the same #define in materialsystem/cmatlightmaps.cpp
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
#include "common_lightmappedgeneric_fxc.h"
|
||||
|
||||
const HALF4 g_EnvmapTint : register( c0 );
|
||||
const HALF3 g_DiffuseModulation : register( c1 );
|
||||
const HALF3 g_EnvmapContrast : register( c2 );
|
||||
const HALF3 g_EnvmapSaturation : register( c3 );
|
||||
const HALF4 g_FresnelReflection : register( c4 );
|
||||
const HALF3 g_EyePos : register( c5 );
|
||||
const HALF3 g_OverbrightFactor : register( c6 );
|
||||
|
||||
const HALF4 g_FogParams : register( c12 );
|
||||
|
||||
// CENTROID: TEXCOORD2
|
||||
|
||||
sampler BaseTextureSampler : register( s0 );
|
||||
sampler LightmapSampler : register( s1 );
|
||||
sampler EnvmapSampler : register( s2 );
|
||||
sampler DetailSampler : register( s3 );
|
||||
sampler EnvmapMaskSampler : register( s5 );
|
||||
|
||||
sampler NormalizeSampler : register( s6 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
HALF2 baseTexCoord : TEXCOORD0;
|
||||
HALF2 detailTexCoord : TEXCOORD1;
|
||||
HALF2 lightmapTexCoord : TEXCOORD2;
|
||||
HALF2 envmapMaskTexCoord : TEXCOORD3;
|
||||
HALF4 worldPos_projPosZ : TEXCOORD4;
|
||||
HALF3 worldSpaceNormal : TEXCOORD5;
|
||||
HALF4 vertexColor : COLOR;
|
||||
};
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
bool bCubemap = CUBEMAP ? true : false;
|
||||
bool bVertexColor = VERTEXCOLOR ? true : false;
|
||||
bool bEnvmapMask = ENVMAPMASK ? true : false;
|
||||
bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false;
|
||||
|
||||
HALF4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord );
|
||||
HALF4 detailColor = tex2D( DetailSampler, i.detailTexCoord );
|
||||
|
||||
HALF2 lightmapCoordinates = i.lightmapTexCoord;
|
||||
HALF3 lightmapColor = LightMapSample( LightmapSampler, lightmapCoordinates );
|
||||
|
||||
HALF3 specularFactor = 1.0f;
|
||||
if( bEnvmapMask )
|
||||
{
|
||||
specularFactor = tex2D( EnvmapMaskSampler, i.detailTexCoord ).xyz;
|
||||
}
|
||||
|
||||
if( bBaseAlphaEnvmapMask )
|
||||
{
|
||||
specularFactor *= 1.0 - baseColor.a; // this blows!
|
||||
}
|
||||
|
||||
HALF3 diffuseLighting = lightmapColor;
|
||||
diffuseLighting *= g_DiffuseModulation;
|
||||
diffuseLighting *= LIGHT_MAP_SCALE;
|
||||
|
||||
HALF3 albedo = baseColor;
|
||||
HALF alpha = 1.0f;
|
||||
|
||||
if( !bBaseAlphaEnvmapMask )
|
||||
{
|
||||
alpha *= baseColor.a;
|
||||
}
|
||||
|
||||
albedo *= detailColor;
|
||||
alpha *= detailColor.a;
|
||||
|
||||
// FIXME: seperate vertexcolor and vertexalpha?
|
||||
// vertex alpha is ignored if vertexcolor isn't set. . need to check other version.
|
||||
if( bVertexColor )
|
||||
{
|
||||
albedo *= i.vertexColor;
|
||||
alpha *= i.vertexColor.a; // not sure about this one
|
||||
}
|
||||
|
||||
HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f );
|
||||
if( bCubemap )
|
||||
{
|
||||
float3 worldVertToEyeVector = g_EyePos - i.worldPos_projPosZ.xyz;
|
||||
worldVertToEyeVector = NormalizeWithCubemap( NormalizeSampler, worldVertToEyeVector );
|
||||
HALF3 reflectVect = CalcReflectionVectorUnnormalized( i.worldSpaceNormal, worldVertToEyeVector );
|
||||
|
||||
// Calc Fresnel factor
|
||||
HALF3 worldSpaceNormal = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceNormal );
|
||||
HALF fresnel = 1.0 - dot( worldSpaceNormal, worldVertToEyeVector );
|
||||
fresnel = pow( fresnel, 5.0 );
|
||||
fresnel = fresnel * g_FresnelReflection.b + g_FresnelReflection.a;
|
||||
|
||||
specularLighting = texCUBE( EnvmapSampler, reflectVect );
|
||||
specularLighting *= specularFactor;
|
||||
|
||||
specularLighting *= g_EnvmapTint;
|
||||
#if HDRTYPE == HDR_TYPE_NONE
|
||||
HALF3 specularLightingSquared = specularLighting * specularLighting;
|
||||
specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast );
|
||||
HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) );
|
||||
specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation );
|
||||
#endif
|
||||
specularLighting *= fresnel;
|
||||
}
|
||||
|
||||
// Do it somewhat unlit
|
||||
HALF3 result = albedo*(g_OverbrightFactor.z*diffuseLighting + g_OverbrightFactor.y) + specularLighting;
|
||||
|
||||
float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
|
||||
return FinalOutput( HALF4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#include "common_fog_vs_fxc.h"
|
||||
// STATIC: "ENVMAP_MASK" "0..1"
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
static const int g_FogType = DOWATERFOG;
|
||||
static const bool g_UseSeparateEnvmapMask = ENVMAP_MASK;
|
||||
|
||||
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
|
||||
const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 );
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float3 vPos : POSITION;
|
||||
float4 vNormal : NORMAL;
|
||||
float2 vBaseTexCoord : TEXCOORD0;
|
||||
float2 vLightmapTexCoord : TEXCOORD1;
|
||||
float2 vDetailTexCoord : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 projPos : POSITION;
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
float fog : FOG;
|
||||
#endif
|
||||
float2 baseTexCoord : TEXCOORD0;
|
||||
float2 detailTexCoord : TEXCOORD1;
|
||||
float2 lightmapTexCoord : TEXCOORD2;
|
||||
float2 envmapMaskTexCoord : TEXCOORD3;
|
||||
float4 worldPos_projPosZ : TEXCOORD4;
|
||||
float3 worldNormal : TEXCOORD5;
|
||||
float4 vertexColor : COLOR;
|
||||
};
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o = ( VS_OUTPUT )0;
|
||||
|
||||
float3 vObjNormal;
|
||||
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
||||
|
||||
float4 projPos;
|
||||
projPos = mul( float4( v.vPos, 1 ), cModelViewProj );
|
||||
o.projPos = projPos;
|
||||
|
||||
o.worldPos_projPosZ.w = projPos.z;
|
||||
o.worldPos_projPosZ.xyz = mul( float4( v.vPos, 1 ), cModel[0] );
|
||||
o.worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
|
||||
o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w;
|
||||
o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w;
|
||||
o.detailTexCoord.x = dot( v.vDetailTexCoord, cDetailTexCoordTransform[0] ) + cDetailTexCoordTransform[0].w;
|
||||
o.detailTexCoord.y = dot( v.vDetailTexCoord, cDetailTexCoordTransform[1] ) + cDetailTexCoordTransform[1].w;
|
||||
o.envmapMaskTexCoord.x = dot( v.vDetailTexCoord, cDetailTexCoordTransform[0] ) + cDetailTexCoordTransform[0].w;
|
||||
o.envmapMaskTexCoord.y = dot( v.vDetailTexCoord, cDetailTexCoordTransform[1] ) + cDetailTexCoordTransform[1].w;
|
||||
o.lightmapTexCoord = v.vLightmapTexCoord;
|
||||
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
o.fog = CalcFixedFunctionFog( o.worldPos_projPosZ.xyz, g_FogType );
|
||||
#endif
|
||||
|
||||
o.vertexColor = cModulationColor;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
|
||||
#include "treeleaf_ps20.inc"
|
||||
#include "treeleaf_ps20b.inc"
|
||||
#include "treeleaf_vs20.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
BEGIN_VS_SHADER_FLAGS( TreeLeaf, "Help for TreeLeaf", SHADER_NOT_EDITABLE )
|
||||
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( LEAFCENTER, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "Center of leaf cluster for lighting" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
|
||||
|
||||
if ( params[BASETEXTURE]->IsDefined() )
|
||||
{
|
||||
LoadTexture( BASETEXTURE );
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
SHADOW_STATE
|
||||
{
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
|
||||
|
||||
pShaderShadow->EnableAlphaTest( true );
|
||||
pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f );
|
||||
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
|
||||
int numTexCoords = 1;
|
||||
pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
|
||||
|
||||
DECLARE_STATIC_VERTEX_SHADER( treeleaf_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, true );
|
||||
SET_STATIC_VERTEX_SHADER( treeleaf_vs20 );
|
||||
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER( treeleaf_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER( treeleaf_ps20 );
|
||||
}
|
||||
|
||||
// we are writing linear values from this shader.
|
||||
// This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
|
||||
// The COLOR really decides if we are gamma or linear.
|
||||
pShaderShadow->EnableSRGBWrite( false );
|
||||
}
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
|
||||
|
||||
// We need the view matrix
|
||||
LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL );
|
||||
|
||||
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[ LEAFCENTER ]->GetVecValue() );
|
||||
|
||||
LightState_t lightState;
|
||||
pShaderAPI->GetDX9LightState( &lightState );
|
||||
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
|
||||
}
|
||||
Draw( );
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,19 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#define HDRTYPE HDR_TYPE_NONE
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 texCoord0 : TEXCOORD0;
|
||||
float3 color : COLOR;
|
||||
};
|
||||
|
||||
sampler BaseTextureSampler : register( s0 );
|
||||
|
||||
HALF4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 baseTex = tex2D( BaseTextureSampler, i.texCoord0 );
|
||||
return FinalOutput( baseTex * float4( i.color, 1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// STATIC: "HALFLAMBERT" "0..1"
|
||||
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
|
||||
// DYNAMIC: "STATIC_LIGHT" "0..1"
|
||||
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
|
||||
|
||||
const float3 cLeafCenter : register(SHADER_SPECIFIC_CONST_0);
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
// This is all of the stuff that we ever use.
|
||||
float4 vPos : POSITION;
|
||||
float4 vNormal : NORMAL;
|
||||
float2 vTexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 projPos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float3 color : COLOR;
|
||||
};
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o = ( VS_OUTPUT )0;
|
||||
|
||||
bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
|
||||
bool bStaticLight = STATIC_LIGHT ? true : false;
|
||||
|
||||
float3 worldPos;
|
||||
worldPos = mul( v.vPos, cModel[0] );
|
||||
|
||||
float3 normal = v.vPos.xyz - cLeafCenter.xyz;
|
||||
normal = normalize( normal );
|
||||
|
||||
float3 worldNormal = mul( float4( normal, 0.0f ), cModel[0] );
|
||||
float3 lighting = DoLighting( worldPos, worldNormal, float3(0,0,0), bStaticLight, bDynamicLight, g_bHalfLambert );
|
||||
|
||||
float3 xAxis = float3( cViewModel[0].x, cViewModel[1].x, cViewModel[2].x );
|
||||
float3 yAxis = float3( cViewModel[0].y, cViewModel[1].y, cViewModel[2].y );
|
||||
|
||||
worldPos += xAxis * v.vTexCoord.x;
|
||||
worldPos += yAxis * (1.0f-v.vTexCoord.y);
|
||||
|
||||
float4 projPos = mul( float4(worldPos, 1.0f), cViewProj );
|
||||
|
||||
float3 light_vec = float3( 1.0f, 0.0, 1.0 );
|
||||
light_vec = normalize( light_vec );
|
||||
|
||||
o.projPos = projPos;
|
||||
// FIXME: if this shader gets put back into use, be sure this usage of normals jives with compressed verts
|
||||
o.texCoord = v.vNormal.xy;
|
||||
o.color = lighting;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
ps.1.1
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Draw a texture . . woo hoo!
|
||||
; t0 - texture
|
||||
;
|
||||
; The texture coordinates need to be defined as follows:
|
||||
; tc0 - texcoords
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
tex t0 ; base color
|
||||
|
||||
mul r0, t0, v0
|
|
@ -0,0 +1,297 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "MULTITEXTURE" "0..1"
|
||||
// STATIC: "FRESNEL" "0..1"
|
||||
// STATIC: "BLEND" "0..1"
|
||||
// STATIC: "REFRACTALPHA" "0..1"
|
||||
// STATIC: "HDRTYPE" "0..2"
|
||||
// STATIC: "FLOWMAP" "0..1"
|
||||
// STATIC: "FLOW_DEBUG" "0..1"
|
||||
|
||||
// DYNAMIC: "HDRENABLED" "0..1"
|
||||
|
||||
#include "common_fog_ps_fxc.h"
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
#include "shader_constant_register_map.h"
|
||||
|
||||
// Constants
|
||||
const float3 g_WaterFogColor : register( c0 );
|
||||
|
||||
const float4 g_CheapWaterParams : register( c1 );
|
||||
#define g_CheapWaterStart g_CheapWaterParams.x
|
||||
#define g_CheapWaterEnd g_CheapWaterParams.y
|
||||
#define g_CheapWaterDeltaRecip g_CheapWaterParams.z
|
||||
#define g_CheapWaterStartDivDelta g_CheapWaterParams.w
|
||||
|
||||
const float4 g_ReflectTint : register( c2 );
|
||||
const float g_flTime : register( c10 );
|
||||
|
||||
const float4 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT ); // c11
|
||||
const float4 g_PixelFogParams : register( PSREG_FOG_PARAMS ); // c12
|
||||
|
||||
const float4 g_vFlowParams1 : register( c13 );
|
||||
#define g_flWorldUvScale ( g_vFlowParams1.x ) // 1.0f / 10.0f
|
||||
#define g_flNormalUvScale ( g_vFlowParams1.y ) // 1.0f / 1.15f
|
||||
#define g_flBumpStrength ( g_vFlowParams1.z ) // 3.0f
|
||||
#define g_flTimeScale ( g_vFlowParams1.w ) // 1.0f
|
||||
|
||||
const float3 g_vFlowParams2 : register( c14 );
|
||||
#define g_flFlowTimeIntervalInSeconds ( g_vFlowParams2.x ) // 0.4f // Number of seconds to lerp from texture 1 to texture 2
|
||||
#define g_flFlowUvScrollDistance ( g_vFlowParams2.y ) // 0.25f // Distance in uv space to fetch
|
||||
#define g_flNoiseScale ( g_vFlowParams2.z )
|
||||
|
||||
// Textures
|
||||
sampler EnvmapSampler : register( s0 );
|
||||
sampler NormalMapSampler : register( s1 );
|
||||
|
||||
#if REFRACTALPHA
|
||||
sampler RefractSampler : register( s2 );
|
||||
#endif
|
||||
|
||||
sampler FlowSampler : register( s3 );
|
||||
|
||||
sampler FlowNoiseSampler : register( s4 );
|
||||
|
||||
sampler NormalizeSampler : register( s6 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 worldSpaceEyeVect_normalMapX : TEXCOORD1;
|
||||
float3x3 tangentSpaceTranspose : TEXCOORD2;
|
||||
float4 vRefract_W_ProjZ : TEXCOORD5;
|
||||
|
||||
#if MULTITEXTURE
|
||||
float4 vExtraBumpTexCoord : TEXCOORD6;
|
||||
#endif
|
||||
|
||||
float4 worldPos_normalMapY : TEXCOORD7;
|
||||
};
|
||||
|
||||
float2 UnpackNormal2D( float2 vNormal )
|
||||
{
|
||||
return ( ( vNormal.xy * 2.0 ) - 1.0 );
|
||||
}
|
||||
|
||||
float3 UnpackNormal3D( float3 vNormal )
|
||||
{
|
||||
return ( ( vNormal.xyz * 2.0 ) - 1.0 );
|
||||
}
|
||||
|
||||
float3 ComputeNormalFromXY( float2 vXY )
|
||||
{
|
||||
float3 vNormalTs;
|
||||
|
||||
vNormalTs.xy = vXY.xy;
|
||||
vNormalTs.z = sqrt( saturate( 1.0 - dot( vNormalTs.xy, vNormalTs.xy ) ) );
|
||||
|
||||
return vNormalTs.xyz;
|
||||
}
|
||||
|
||||
float3 ComputeNormalFromRGTexture( float2 vRGPixel )
|
||||
{
|
||||
float3 vNormalTs;
|
||||
|
||||
vNormalTs.xy = UnpackNormal2D( vRGPixel.rg );
|
||||
vNormalTs.z = sqrt( saturate( 1.0 - dot( vNormalTs.xy, vNormalTs.xy ) ) );
|
||||
|
||||
return vNormalTs.xyz;
|
||||
}
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float2 normalMapTexCoord = float2( i.worldSpaceEyeVect_normalMapX.w, i.worldPos_normalMapY.w );
|
||||
|
||||
float3 vNormal;
|
||||
#if ( FLOWMAP )
|
||||
{
|
||||
//*
|
||||
float flWorldUvScale = g_flWorldUvScale;
|
||||
float flNormalUvScale = g_flNormalUvScale;
|
||||
float flFlowTimeIntervalInSeconds = g_flFlowTimeIntervalInSeconds;
|
||||
float flFlowUvScrollDistance = g_flFlowUvScrollDistance;
|
||||
float flBumpStrength = g_flBumpStrength;
|
||||
float flTimeScale = g_flTimeScale;
|
||||
float flNoiseScale = g_flNoiseScale;
|
||||
//*/
|
||||
|
||||
/* River
|
||||
float flWorldUvScale = 1.0f / 6.0f;
|
||||
float flNormalUvScale = 1.0f / 0.5f;
|
||||
float flFlowTimeIntervalInSeconds = 0.4f; // Number of seconds to lerp from texture 1 to texture 2
|
||||
float flFlowUvScrollDistance = 0.2f; // Distance in uv space to fetch
|
||||
float flBumpStrength = 1.0f;
|
||||
float flTimeScale = 0.75f;
|
||||
//*/
|
||||
|
||||
/* Swamp - Heavy churn
|
||||
float flWorldUvScale = 1.0f / 10.0f;
|
||||
float flNormalUvScale = 1.0f / 1.15f;
|
||||
float flFlowTimeIntervalInSeconds = 0.4f; // Number of seconds to lerp from texture 1 to texture 2
|
||||
float flFlowUvScrollDistance = 0.25f; // Distance in uv space to fetch
|
||||
float flBumpStrength = 3.0f;
|
||||
float flTimeScale = 1.0f;
|
||||
//*/
|
||||
|
||||
/* Swamp - Calmer
|
||||
float flWorldUvScale = 1.0f / 10.0f;
|
||||
float flNormalUvScale = 1.0f / 1.15f;
|
||||
float flFlowTimeIntervalInSeconds = 0.25f; // Number of seconds to lerp from texture 1 to texture 2
|
||||
float flFlowUvScrollDistance = 0.15f; // Distance in uv space to fetch
|
||||
float flBumpStrength = 1.05f;
|
||||
float flTimeScale = 0.35f;
|
||||
//*/
|
||||
|
||||
// Input uv
|
||||
float2 vWorldUv = normalMapTexCoord.xy * flWorldUvScale;
|
||||
float2 vUv1 = float2( i.worldPos_normalMapY.x, -i.worldPos_normalMapY.y ) * flNormalUvScale;
|
||||
float2 vUv2 = vUv1.xy;
|
||||
|
||||
// Noise texture is used to offset the time interval different spatially so we don't see pulsing
|
||||
float flNoise = tex2D( FlowNoiseSampler, float2( i.worldPos_normalMapY.x, -i.worldPos_normalMapY.y ) * flNoiseScale ).g;
|
||||
|
||||
// Flow texel has a 2D flow vector in the rg channels of the texture
|
||||
float4 vFlowTexel = tex2D( FlowSampler, vWorldUv.xy );
|
||||
#if FLOW_DEBUG
|
||||
{
|
||||
return float4( vFlowTexel.rgb, 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Unpack world flow vector from texture
|
||||
float2 vFlowVectorTs = ( vFlowTexel.rg * 2.0f ) - 1.0f;
|
||||
|
||||
float flTimeInIntervals = ( ( g_flTime * flTimeScale ) + flNoise ) / ( flFlowTimeIntervalInSeconds * 2.0f );
|
||||
float flScrollTime1 = frac( flTimeInIntervals );
|
||||
float flScrollTime2 = frac( flTimeInIntervals + 0.5f ); // Half an interval off from texture 1
|
||||
|
||||
// Every interval has a unique offset so we don't see the same bump texels repeating continuously
|
||||
float flOffset1 = floor( flTimeInIntervals ) * 0.311f;
|
||||
float flOffset2 = floor( flTimeInIntervals + 0.5f ) * 0.311f + 0.5f; // The +0.5 is to match the phase offset
|
||||
|
||||
// Final flow uv is originalUv + interval offset + ( flowvector * scroll
|
||||
float2 vFlowUv1 = vUv1.xy + flOffset1 + ( flScrollTime1 * ( flFlowUvScrollDistance * vFlowVectorTs.xy ) );
|
||||
float2 vFlowUv2 = vUv2.xy + flOffset2 + ( flScrollTime2 * ( flFlowUvScrollDistance * vFlowVectorTs.xy ) );
|
||||
|
||||
// Lerp values to blend between the two layers of bump
|
||||
float flWeight1 = abs( ( 2.0f * frac( flTimeInIntervals + 0.5f ) ) - 1.0f );
|
||||
float flWeight2 = abs( ( 2.0f * frac( flTimeInIntervals ) ) - 1.0f );
|
||||
|
||||
float4 vNormalTexel1 = tex2D( NormalMapSampler, vFlowUv1.xy );
|
||||
float4 vNormalTexel2 = tex2D( NormalMapSampler, vFlowUv2.xy );
|
||||
|
||||
float3 vNormal1 = ( vNormalTexel1.rgb );
|
||||
float3 vNormal2 = ( vNormalTexel2.rgb );
|
||||
|
||||
// Combine both layers
|
||||
vNormal.xy = UnpackNormal2D( lerp( vNormal1.xy, vNormal2.xy, flWeight2 ) );
|
||||
|
||||
// Change bump strength based on the length of the flow vector
|
||||
//vNormal.xy *= ( length( vFlowVectorTs.xy ) + 0.05f ) * flBumpStrength;
|
||||
vNormal.xy *= ( ( vFlowVectorTs.x * vFlowVectorTs.x + vFlowVectorTs.y * vFlowVectorTs.y ) + 0.05f ) * flBumpStrength;
|
||||
|
||||
// Generate normal from 2D scaled normal
|
||||
vNormal.xyz = ComputeNormalFromXY( vNormal.xy );
|
||||
}
|
||||
#elif ( MULTITEXTURE )
|
||||
{
|
||||
vNormal.xyz = tex2D( NormalMapSampler, normalMapTexCoord );
|
||||
float3 vNormal1 = tex2D( NormalMapSampler, i.vExtraBumpTexCoord.xy );
|
||||
float3 vNormal2 = tex2D( NormalMapSampler, i.vExtraBumpTexCoord.zw );
|
||||
vNormal = 0.33 * ( vNormal + vNormal1 + vNormal2 );
|
||||
|
||||
vNormal = 2.0 * vNormal - 1.0;
|
||||
}
|
||||
#else
|
||||
{
|
||||
vNormal.xyz = DecompressNormal( NormalMapSampler, normalMapTexCoord, NORM_DECODE_NONE );
|
||||
}
|
||||
#endif
|
||||
|
||||
float3 worldSpaceNormal = mul( vNormal, i.tangentSpaceTranspose );
|
||||
float3 worldSpaceEye;
|
||||
|
||||
float flWorldSpaceDist = 1.0f;
|
||||
|
||||
#ifdef NV3X
|
||||
// for some reason, fxc doesn't convert length( half3 v ) into all _pp opcodes.
|
||||
#if ( BLEND )
|
||||
{
|
||||
worldSpaceEye = i.worldSpaceEyeVect_normalMapX.xyz;
|
||||
float worldSpaceDistSqr = dot( worldSpaceEye, worldSpaceEye );
|
||||
float rcpWorldSpaceDist = rsqrt( worldSpaceDistSqr );
|
||||
worldSpaceEye *= rcpWorldSpaceDist;
|
||||
flWorldSpaceDist = worldSpaceDistSqr * rcpWorldSpaceDist;
|
||||
}
|
||||
#else
|
||||
{
|
||||
worldSpaceEye = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceEyeVect_normalMapX.xyz );
|
||||
}
|
||||
#endif
|
||||
#else // !NV3X
|
||||
#if ( BLEND )
|
||||
{
|
||||
worldSpaceEye = i.worldSpaceEyeVect_normalMapX.xyz;
|
||||
flWorldSpaceDist = length( worldSpaceEye );
|
||||
worldSpaceEye /= flWorldSpaceDist;
|
||||
}
|
||||
#else
|
||||
{
|
||||
worldSpaceEye = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceEyeVect_normalMapX.xyz );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, worldSpaceEye );
|
||||
float3 specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect );
|
||||
specularLighting *= g_ReflectTint;
|
||||
|
||||
#if FRESNEL
|
||||
// FIXME: It's unclear that we want to do this for cheap water
|
||||
// but the code did this previously and I didn't want to change it
|
||||
float flDotResult = dot( worldSpaceEye, worldSpaceNormal );
|
||||
flDotResult = 1.0f - max( 0.0f, flDotResult );
|
||||
|
||||
float flFresnelFactor = flDotResult * flDotResult;
|
||||
flFresnelFactor *= flFresnelFactor;
|
||||
flFresnelFactor *= flDotResult;
|
||||
#else
|
||||
float flFresnelFactor = g_ReflectTint.a;
|
||||
#endif
|
||||
|
||||
float flAlpha;
|
||||
#if ( BLEND )
|
||||
{
|
||||
float flReflectAmount = saturate( flWorldSpaceDist * g_CheapWaterDeltaRecip - g_CheapWaterStartDivDelta );
|
||||
flAlpha = saturate( flFresnelFactor + flReflectAmount );
|
||||
|
||||
#if REFRACTALPHA
|
||||
// Perform division by W only once
|
||||
float ooW = 1.0f / i.vRefract_W_ProjZ.z;
|
||||
float2 unwarpedRefractTexCoord = i.vRefract_W_ProjZ * ooW;
|
||||
float fogDepthValue = tex2D( RefractSampler, unwarpedRefractTexCoord ).a;
|
||||
// Fade on the border between the water and land.
|
||||
flAlpha *= saturate( ( fogDepthValue - .05f ) * 20.0f );
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
{
|
||||
flAlpha = 1.0f;
|
||||
#if HDRTYPE == 0 || HDRENABLED == 0
|
||||
specularLighting = lerp( g_WaterFogColor, specularLighting, flFresnelFactor );
|
||||
#else
|
||||
specularLighting = lerp( GammaToLinear( g_WaterFogColor ), specularLighting, flFresnelFactor );
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// multiply the color by alpha.since we are using alpha blending to blend against dest alpha for borders.
|
||||
|
||||
#if (PIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE)
|
||||
float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_PixelFogParams, g_EyePos.xyz, i.worldPos_normalMapY.xyz, i.vRefract_W_ProjZ.w );
|
||||
#else
|
||||
float fogFactor = 0;
|
||||
#endif
|
||||
|
||||
return FinalOutput( float4( specularLighting, flAlpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
// STATIC: "BLEND" "0..1"
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 vPos : POSITION;
|
||||
float4 vNormal : NORMAL;
|
||||
float2 vNormalMapCoord : TEXCOORD0;
|
||||
float3 vTangentS : TANGENT;
|
||||
float3 vTangentT : BINORMAL;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 projPos : POSITION;
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
float fog : FOG;
|
||||
#endif
|
||||
float4 worldVertToEyeVector_normalMapX : TEXCOORD1;
|
||||
float3x3 tangentSpaceTranspose : TEXCOORD2;
|
||||
float4 vRefract_W_ProjZ : TEXCOORD5;
|
||||
float4 vExtraBumpTexCoord : TEXCOORD6;
|
||||
float4 worldPos_normalMapY : TEXCOORD7;
|
||||
};
|
||||
|
||||
const float4 cNormalMapTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
|
||||
const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 );
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o = ( VS_OUTPUT )0;
|
||||
|
||||
float3 vObjNormal;
|
||||
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
||||
|
||||
float4 projPos;
|
||||
float3 worldPos;
|
||||
|
||||
projPos = mul( v.vPos, cModelViewProj );
|
||||
o.projPos = projPos;
|
||||
|
||||
#if BLEND
|
||||
// Map projected position to the reflection texture
|
||||
o.vRefract_W_ProjZ.x = projPos.x;
|
||||
o.vRefract_W_ProjZ.y = -projPos.y; // invert Y
|
||||
o.vRefract_W_ProjZ.xy = (o.vRefract_W_ProjZ + projPos.w) * 0.5f;
|
||||
o.vRefract_W_ProjZ.z = projPos.w;
|
||||
#endif
|
||||
|
||||
o.vRefract_W_ProjZ.w = projPos.z;
|
||||
|
||||
worldPos = mul( v.vPos, cModel[0] );
|
||||
|
||||
float3 worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] );
|
||||
float3 worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] );
|
||||
float3 worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
|
||||
o.tangentSpaceTranspose[0] = worldTangentS;
|
||||
o.tangentSpaceTranspose[1] = worldTangentT;
|
||||
o.tangentSpaceTranspose[2] = worldNormal;
|
||||
|
||||
float3 worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos);
|
||||
o.worldVertToEyeVector_normalMapX.xyz = worldVertToEyeVector;
|
||||
|
||||
// FIXME: need to add a normalMapTransform to all of the water shaders.
|
||||
//o.worldVertToEyeVector_normalMapX.w = dot( v.vNormalMapCoord, cNormalMapTransform[0] ) + cNormalMapTransform[0].w;
|
||||
//o.worldPos_normalMapY.w = dot( v.vNormalMapCoord, cNormalMapTransform[1] ) + cNormalMapTransform[1].w;
|
||||
o.worldVertToEyeVector_normalMapX.w = v.vNormalMapCoord.x;
|
||||
o.worldPos_normalMapY.w = v.vNormalMapCoord.y;
|
||||
|
||||
float f45x=v.vNormalMapCoord.x+v.vNormalMapCoord.y;
|
||||
float f45y=v.vNormalMapCoord.y-v.vNormalMapCoord.x;
|
||||
o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x;
|
||||
o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y;
|
||||
o.vExtraBumpTexCoord.z=v.vNormalMapCoord.y*0.45+TexOffsets.z;
|
||||
o.vExtraBumpTexCoord.w=v.vNormalMapCoord.x*0.45+TexOffsets.w;
|
||||
|
||||
o.worldPos_normalMapY.xyz = worldPos;
|
||||
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
o.fog = CalcFixedFunctionFog( worldPos, FOGTYPE_RANGE );
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
//============ Copyright (c) Valve Corporation, All rights reserved. ============
|
||||
|
||||
// STATIC: "BASETEXTURE" "0..1"
|
||||
// STATIC: "MULTITEXTURE" "0..1"
|
||||
// STATIC: "FLASHLIGHT" "0..1"
|
||||
// STATIC: "LIGHTMAPWATERFOG" "0..1"
|
||||
// STATIC: "FLOWMAP" "0..1"
|
||||
|
||||
// Multitexture and basetexture are mutually exclusive.
|
||||
// SKIP: $MULTITEXTURE && $BASETEXTURE
|
||||
|
||||
// flowmap doesn't play with multitexture or basetexture
|
||||
// SKIP: $FLOWMAP && $MULTITEXTURE
|
||||
|
||||
// Have to have the flashlight on to get flashlightshadows.
|
||||
// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 )
|
||||
|
||||
// basetexture doesn't work with flashlight or lightmapwaterfog. multitexture doesn't either. We don't use basetexture or multitexture in newer code and instead use flowmap and flashlight.
|
||||
// SKIP: ( $FLASHLIGHT || $LIGHTMAPWATERFOG ) && ( ( $BASETEXTURE && !$FLOWMAP ) || $MULTITEXTURE )
|
||||
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
|
||||
const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 );
|
||||
|
||||
#if FLASHLIGHT
|
||||
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_4 );
|
||||
#endif
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 vPos : POSITION;
|
||||
float4 vNormal : NORMAL;
|
||||
float4 vBaseTexCoord : TEXCOORD0;
|
||||
float2 vLightmapTexCoord : TEXCOORD1;
|
||||
float2 vLightmapTexCoordOffset : TEXCOORD2;
|
||||
float3 vTangentS : TANGENT;
|
||||
float3 vTangentT : BINORMAL0;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 vProjPos_POSITION : POSITION;
|
||||
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
||||
float fog : FOG;
|
||||
#endif
|
||||
float2 vBumpTexCoord : TEXCOORD0;
|
||||
float3 vPositionToCameraRayWs : TEXCOORD1;
|
||||
float4 vReflectXY_vRefractYX : TEXCOORD2;
|
||||
float4 vProjPos : TEXCOORD3;
|
||||
float3 worldPos : TEXCOORD4;
|
||||
#if FLASHLIGHT
|
||||
float4 flashlightSpacePos : TEXCOORD5;
|
||||
#endif
|
||||
#if MULTITEXTURE
|
||||
float4 vExtraBumpTexCoord : TEXCOORD5;
|
||||
#endif
|
||||
#if ( BASETEXTURE && !FLOWMAP )
|
||||
float4 lightmapTexCoord1And2 : TEXCOORD5;
|
||||
float2 lightmapTexCoord3 : TEXCOORD6;
|
||||
#endif
|
||||
|
||||
#if LIGHTMAPWATERFOG
|
||||
float2 lightmapTexCoord : TEXCOORD7;
|
||||
#endif
|
||||
};
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o;
|
||||
|
||||
float3 vObjNormal;
|
||||
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
||||
|
||||
// Projected position
|
||||
float4 vProjPos = mul( v.vPos, cModelViewProj );
|
||||
o.vProjPos = o.vProjPos_POSITION = vProjPos;
|
||||
|
||||
// Project tangent basis
|
||||
float2 vProjTangentS = mul( v.vTangentS, cViewProj );
|
||||
float2 vProjTangentT = mul( v.vTangentT, cViewProj );
|
||||
|
||||
// Map projected position to the reflection texture
|
||||
float2 vReflectPos;
|
||||
vReflectPos = (vProjPos.xy + vProjPos.w) * 0.5f;
|
||||
|
||||
// Map projected position to the refraction texture
|
||||
float2 vRefractPos;
|
||||
vRefractPos.x = vProjPos.x;
|
||||
vRefractPos.y = -vProjPos.y; // invert Y
|
||||
vRefractPos = (vRefractPos + vProjPos.w) * 0.5f;
|
||||
|
||||
// Reflection transform
|
||||
o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x );
|
||||
|
||||
// Compute fog based on the position
|
||||
float3 vWorldPos = mul( v.vPos, cModel[0] );
|
||||
o.worldPos = vWorldPos;
|
||||
|
||||
#if ( !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 ) )
|
||||
{
|
||||
o.fog = CalcFixedFunctionFog( vWorldPos, FOGTYPE_RANGE );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Eye vector
|
||||
float3 vPositionToCameraRayWs = cEyePos.xyz - vWorldPos.xyz;
|
||||
|
||||
// Transform to the tangent space
|
||||
//o.vTangentEyeVect.x = dot( vPositionToCameraRayWs, v.vTangentS );
|
||||
//o.vTangentEyeVect.y = dot( vPositionToCameraRayWs, v.vTangentT );
|
||||
//o.vTangentEyeVect.z = dot( vPositionToCameraRayWs, vObjNormal );
|
||||
|
||||
o.vPositionToCameraRayWs.xyz = vPositionToCameraRayWs.xyz;
|
||||
|
||||
// Tranform bump coordinates
|
||||
o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
|
||||
o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
|
||||
float f45x=v.vBaseTexCoord.x+v.vBaseTexCoord.y;
|
||||
float f45y=v.vBaseTexCoord.y-v.vBaseTexCoord.x;
|
||||
#if ( MULTITEXTURE )
|
||||
{
|
||||
o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x;
|
||||
o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y;
|
||||
o.vExtraBumpTexCoord.z=v.vBaseTexCoord.y*0.45+TexOffsets.z;
|
||||
o.vExtraBumpTexCoord.w=v.vBaseTexCoord.x*0.45+TexOffsets.w;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( BASETEXTURE && !FLOWMAP )
|
||||
{
|
||||
o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset;
|
||||
|
||||
float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset;
|
||||
float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset;
|
||||
|
||||
// reversed component order
|
||||
o.lightmapTexCoord1And2.w = lightmapTexCoord2.x;
|
||||
o.lightmapTexCoord1And2.z = lightmapTexCoord2.y;
|
||||
|
||||
o.lightmapTexCoord3.xy = lightmapTexCoord3;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTMAPWATERFOG
|
||||
{
|
||||
o.lightmapTexCoord.xy = v.vLightmapTexCoord.xy;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FLASHLIGHT
|
||||
{
|
||||
o.flashlightSpacePos = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture );
|
||||
}
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
ps.1.1
|
||||
|
||||
tex t0 ; basetexture
|
||||
tex t1 ; lightmap
|
||||
|
||||
mov r0.a, 1-t1.a
|
||||
;mov r0.rgb, t0 ; * 2 * (overbrightFactor/2)
|
||||
;mov_x2 r0.rgb, t0 ; * 2 * (overbrightFactor/2)
|
||||
mul r0.rgb, t0, t1;
|
||||
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
|
|
@ -0,0 +1,37 @@
|
|||
vs.1.1
|
||||
|
||||
# DYNAMIC: "DOWATERFOG" "0..1"
|
||||
|
||||
#include "macros.vsh"
|
||||
|
||||
local( $worldPos, $worldNormal, $projPos, $reflectionVector );
|
||||
|
||||
&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
|
||||
|
||||
&AllocateRegister( \$worldPos );
|
||||
|
||||
; garymcthack
|
||||
dp4 $worldPos.z, $vPos, $cModel2
|
||||
|
||||
&CalcFog( $worldPos, $projPos );
|
||||
|
||||
&FreeRegister( \$worldPos );
|
||||
&FreeRegister( \$projPos );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Texture coordinates
|
||||
;------------------------------------------------------------------------------
|
||||
; base texcoords
|
||||
mov oT0, $vTexCoord0
|
||||
|
||||
; lightmap texcoords
|
||||
mov oT1, $vTexCoord1
|
||||
|
||||
&FreeRegister( \$worldPos ); # garymcthack
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "PASS" "0..1"
|
||||
|
||||
#define HDRTYPE HDR_TYPE_NONE
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
// CENTROID: TEXCOORD1
|
||||
|
||||
sampler BaseSampler : register( s0 );
|
||||
sampler LightmapSampler: register( s1 );
|
||||
sampler LightmapAlphaSampler: register( s2 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 baseCoord : TEXCOORD0;
|
||||
float2 lightmapCoord : TEXCOORD1;
|
||||
};
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
bool bAlphaPass = PASS ? true : false;
|
||||
|
||||
float4 base = tex2D( BaseSampler, i.baseCoord );
|
||||
float4 lightmap = tex2D( LightmapSampler, i.lightmapCoord );
|
||||
float4 alpha = tex2D( LightmapAlphaSampler, i.lightmapCoord );
|
||||
|
||||
float4 color;
|
||||
|
||||
base.a = dot( base, HALF3( HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f) ) );
|
||||
color = 2.0f * base * lightmap; // The 2x is for an assumed overbright 2 (it's always 2 on dx9)
|
||||
|
||||
if( bAlphaPass )
|
||||
{
|
||||
// Don't care about color, just return pre-multiplied alpha
|
||||
return FinalOutput( float4( 0.0f, 0.0f, 1.0f, (1.0f - alpha.a) * color.a ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return FinalOutput( float4( color.rgb, (1.0f - alpha.a) ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
vs.1.1
|
||||
|
||||
# DYNAMIC: "DOWATERFOG" "0..1"
|
||||
|
||||
#include "macros.vsh"
|
||||
|
||||
local( $worldPos, $worldNormal, $projPos, $reflectionVector );
|
||||
|
||||
&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
|
||||
|
||||
&AllocateRegister( \$worldPos );
|
||||
|
||||
; garymcthack
|
||||
dp4 $worldPos.z, $vPos, $cModel2
|
||||
|
||||
&CalcFog( $worldPos, $projPos );
|
||||
|
||||
&FreeRegister( \$worldPos );
|
||||
&FreeRegister( \$projPos );
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Texture coordinates
|
||||
;------------------------------------------------------------------------------
|
||||
; base texcoords
|
||||
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
|
||||
|
||||
; lightmap texcoords
|
||||
mov oT2, $vTexCoord1
|
||||
|
||||
; detail
|
||||
dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
|
||||
dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
|
||||
|
||||
; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh.
|
||||
mov oD0, $vColor
|
||||
|
||||
&FreeRegister( \$worldPos ); # garymcthack
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
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, t1, t0 ; fold in lightmap (color)
|
||||
+mov r0.a, v0.a ; fold in lightmap (alpha)
|
||||
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
ps.1.1
|
||||
|
||||
tex t0 ; basetexture
|
||||
tex t1 ; basetexture2
|
||||
tex t2 ; lightmap
|
||||
|
||||
; The editor uses vertex alpha as the blend factor
|
||||
lrp r0, 1-v0.a, t1, t0
|
||||
mul r0, r0, t2
|
||||
mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2)
|
|
@ -0,0 +1,50 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// STATIC: "MACROS" "0..1"
|
||||
|
||||
#define HDRTYPE HDR_TYPE_NONE
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
sampler BaseSampler : register( s0 );
|
||||
// NOTE: LightmapSampler is at the same place as the lightmap sampler in lightmappedgeneric so that we have
|
||||
// generally the same texture state here.
|
||||
sampler LightmapSampler: register( s1 );
|
||||
sampler BaseSampler2: register( s2 );
|
||||
sampler LightmapAlphaSampler: register( s3 );
|
||||
sampler MacrosSampler: register( s4 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 baseCoord : TEXCOORD0;
|
||||
float2 baseCoord2 : TEXCOORD1;
|
||||
// CENTROID: TEXCOORD2
|
||||
#if defined( _X360 )
|
||||
float2 lightmapCoord : TEXCOORD2_centroid;
|
||||
#else
|
||||
float2 lightmapCoord : TEXCOORD2;
|
||||
#endif
|
||||
float2 macrosCoord : TEXCOORD3;
|
||||
};
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
bool bMacros = MACROS ? true : false;
|
||||
|
||||
float4 base = tex2D( BaseSampler, i.baseCoord );
|
||||
float4 base2 = tex2D( BaseSampler2, i.baseCoord2 );
|
||||
|
||||
float4 lightmap = tex2D( LightmapSampler, i.lightmapCoord );
|
||||
float blendFactor = lightmap.a;
|
||||
|
||||
float4 color = 2.0f * lightmap * lerp( base2, base, blendFactor );
|
||||
if( bMacros )
|
||||
{
|
||||
float4 macros = tex2D( MacrosSampler, i.macrosCoord );
|
||||
|
||||
// Not sure what to do with macro alpha
|
||||
color.rgb *= 2.0f * lerp( macros.a, macros.b, blendFactor );
|
||||
}
|
||||
|
||||
return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
#include "common_fog_vs_fxc.h"
|
||||
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
static const int g_FogType = DOWATERFOG;
|
||||
|
||||
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
|
||||
const float4 cBaseTexCoordTransform2[2] : register( SHADER_SPECIFIC_CONST_2 );
|
||||
const float4 cMacrosTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 );
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
// This is all of the stuff that we ever use.
|
||||
float4 vPos : POSITION;
|
||||
float4 vColor : COLOR0;
|
||||
float4 vTexCoord0 : TEXCOORD0;
|
||||
float4 vTexCoord1 : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 projPos : POSITION;
|
||||
#if !defined( _X360 )
|
||||
float fog : FOG;
|
||||
#endif
|
||||
float2 baseCoord : TEXCOORD0;
|
||||
float2 baseCoord2 : TEXCOORD1;
|
||||
float2 lightmapCoord : TEXCOORD2;
|
||||
float2 macrosCoord : TEXCOORD3;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
VS_OUTPUT main( const VS_INPUT v )
|
||||
{
|
||||
VS_OUTPUT o = ( VS_OUTPUT )0;
|
||||
|
||||
float3 worldNormal, worldPos;
|
||||
float2 texCoord;
|
||||
worldPos = mul( v.vPos, cModel[0] );
|
||||
float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
|
||||
o.projPos = projPos;
|
||||
o.fogFactorsYZW = CalcFog( worldPos, projPos, g_FogType );
|
||||
#if !defined( _X360 )
|
||||
o.fog = o.fogFactorsYZW;
|
||||
#endif
|
||||
o.color = v.vColor;
|
||||
|
||||
o.baseCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
|
||||
o.baseCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
|
||||
|
||||
o.baseCoord2.x = dot( v.vTexCoord0, cBaseTexCoordTransform2[0] );
|
||||
o.baseCoord2.y = dot( v.vTexCoord0, cBaseTexCoordTransform2[1] );
|
||||
|
||||
o.lightmapCoord = v.vTexCoord1;
|
||||
|
||||
o.macrosCoord.x = dot( v.vTexCoord0, cMacrosTexCoordTransform[0] );
|
||||
o.macrosCoord.y = dot( v.vTexCoord0, cMacrosTexCoordTransform[1] );
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "aftershock_helper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
DEFINE_FALLBACK_SHADER( Aftershock, Aftershock_dx9 )
|
||||
BEGIN_VS_SHADER( Aftershock_dx9, "Aftershock" )
|
||||
BEGIN_SHADER_PARAMS
|
||||
SHADER_PARAM( COLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Color tint" )
|
||||
SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
|
||||
|
||||
SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" )
|
||||
SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
|
||||
SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
|
||||
|
||||
SHADER_PARAM( SILHOUETTETHICKNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" )
|
||||
SHADER_PARAM( SILHOUETTECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Silhouette color tint" )
|
||||
SHADER_PARAM( GROUNDMIN, SHADER_PARAM_TYPE_FLOAT, "1", "" )
|
||||
SHADER_PARAM( GROUNDMAX, SHADER_PARAM_TYPE_FLOAT, "1", "" )
|
||||
SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1", "" )
|
||||
|
||||
SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" )
|
||||
END_SHADER_PARAMS
|
||||
|
||||
void SetupVarsAftershock( AftershockVars_t &info )
|
||||
{
|
||||
info.m_nColorTint = COLORTINT;
|
||||
info.m_nRefractAmount = REFRACTAMOUNT;
|
||||
|
||||
info.m_nBumpmap = NORMALMAP;
|
||||
info.m_nBumpFrame = BUMPFRAME;
|
||||
info.m_nBumpTransform = BUMPTRANSFORM;
|
||||
|
||||
info.m_nSilhouetteThickness = SILHOUETTETHICKNESS;
|
||||
info.m_nSilhouetteColor = SILHOUETTECOLOR;
|
||||
info.m_nGroundMin = GROUNDMIN;
|
||||
info.m_nGroundMax = GROUNDMAX;
|
||||
info.m_nBlurAmount = BLURAMOUNT;
|
||||
|
||||
info.m_nTime = TIME;
|
||||
}
|
||||
|
||||
SHADER_INIT_PARAMS()
|
||||
{
|
||||
AftershockVars_t info;
|
||||
SetupVarsAftershock( info );
|
||||
InitParamsAftershock( this, params, pMaterialName, info );
|
||||
}
|
||||
|
||||
SHADER_FALLBACK
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHADER_INIT
|
||||
{
|
||||
AftershockVars_t info;
|
||||
SetupVarsAftershock( info );
|
||||
InitAftershock( this, params, info );
|
||||
}
|
||||
|
||||
SHADER_DRAW
|
||||
{
|
||||
AftershockVars_t info;
|
||||
SetupVarsAftershock( info );
|
||||
DrawAftershock( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
|
||||
}
|
||||
END_SHADER
|
|
@ -0,0 +1,199 @@
|
|||
//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============//
|
||||
|
||||
#include "BaseVSShader.h"
|
||||
#include "mathlib/VMatrix.h"
|
||||
#include "aftershock_helper.h"
|
||||
#include "convar.h"
|
||||
|
||||
// Auto generated inc files
|
||||
#include "aftershock_vs20.inc"
|
||||
#include "aftershock_ps20.inc"
|
||||
#include "aftershock_ps20b.inc"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
void InitParamsAftershock( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, AftershockVars_t &info )
|
||||
{
|
||||
// Set material flags
|
||||
SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
|
||||
SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
|
||||
|
||||
SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
|
||||
SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
|
||||
|
||||
// Set material parameter default values
|
||||
if ( ( info.m_nRefractAmount != -1 ) && ( !params[info.m_nRefractAmount]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nRefractAmount]->SetFloatValue( kDefaultRefractAmount );
|
||||
}
|
||||
|
||||
if ( ( info.m_nColorTint != -1 ) && ( !params[info.m_nColorTint]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nColorTint]->SetVecValue( kDefaultColorTint[0], kDefaultColorTint[1], kDefaultColorTint[2], kDefaultColorTint[3] );
|
||||
}
|
||||
|
||||
if( (info.m_nBumpFrame != -1 ) && !params[info.m_nBumpFrame]->IsDefined() )
|
||||
{
|
||||
params[info.m_nBumpFrame]->SetIntValue( 0 );
|
||||
}
|
||||
|
||||
if ( ( info.m_nSilhouetteThickness != -1 ) && ( !params[info.m_nSilhouetteThickness]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nSilhouetteThickness]->SetFloatValue( kDefaultSilhouetteThickness );
|
||||
}
|
||||
|
||||
if ( ( info.m_nSilhouetteColor != -1 ) && ( !params[info.m_nSilhouetteColor]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nSilhouetteColor]->SetVecValue( kDefaultSilhouetteColor[0], kDefaultSilhouetteColor[1], kDefaultSilhouetteColor[2], kDefaultSilhouetteColor[3] );
|
||||
}
|
||||
|
||||
if ( ( info.m_nGroundMin != -1 ) && ( !params[info.m_nGroundMin]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nGroundMin]->SetFloatValue( kDefaultGroundMin );
|
||||
}
|
||||
|
||||
if ( ( info.m_nGroundMax != -1 ) && ( !params[info.m_nGroundMax]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nGroundMax]->SetFloatValue( kDefaultGroundMax );
|
||||
}
|
||||
|
||||
if ( ( info.m_nBlurAmount != -1 ) && ( !params[info.m_nBlurAmount]->IsDefined() ) )
|
||||
{
|
||||
params[info.m_nBlurAmount]->SetFloatValue( kDefaultBlurAmount );
|
||||
}
|
||||
|
||||
SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f );
|
||||
}
|
||||
|
||||
void InitAftershock( CBaseVSShader *pShader, IMaterialVar** params, AftershockVars_t &info )
|
||||
{
|
||||
// Load textures
|
||||
if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
|
||||
{
|
||||
pShader->LoadTexture( info.m_nBumpmap );
|
||||
}
|
||||
}
|
||||
|
||||
void DrawAftershock( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
|
||||
IShaderShadow* pShaderShadow, AftershockVars_t &info, VertexCompressionType_t vertexCompression )
|
||||
{
|
||||
bool bBumpMapping = ( info.m_nBumpmap == -1 ) || !params[info.m_nBumpmap]->IsTexture() ? 0 : 1;
|
||||
|
||||
SHADOW_STATE
|
||||
{
|
||||
// Set stream format (note that this shader supports compression)
|
||||
unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
|
||||
int nTexCoordCount = 1;
|
||||
int userDataSize = 0;
|
||||
pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
|
||||
|
||||
// Vertex Shader
|
||||
DECLARE_STATIC_VERTEX_SHADER( aftershock_vs20 );
|
||||
SET_STATIC_VERTEX_SHADER( aftershock_vs20 );
|
||||
|
||||
// Pixel Shader
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( aftershock_ps20b );
|
||||
SET_STATIC_PIXEL_SHADER( aftershock_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_STATIC_PIXEL_SHADER( aftershock_ps20 );
|
||||
SET_STATIC_PIXEL_SHADER( aftershock_ps20 );
|
||||
}
|
||||
|
||||
// Textures
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refraction texture
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
|
||||
pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump
|
||||
pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB
|
||||
pShaderShadow->EnableSRGBWrite( true );
|
||||
|
||||
// Blending
|
||||
pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
|
||||
pShaderShadow->EnableAlphaWrites( false );
|
||||
|
||||
// !!! We need to turn this back on because EnableAlphaBlending() above disables it!
|
||||
//pShaderShadow->EnableDepthWrites( true );
|
||||
}
|
||||
DYNAMIC_STATE
|
||||
{
|
||||
// Set Vertex Shader Combos
|
||||
DECLARE_DYNAMIC_VERTEX_SHADER( aftershock_vs20 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
|
||||
SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
|
||||
SET_DYNAMIC_VERTEX_SHADER( aftershock_vs20 );
|
||||
|
||||
// Set Vertex Shader Constants
|
||||
if ( info.m_nBumpTransform != -1 )
|
||||
{
|
||||
pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nBumpTransform );
|
||||
}
|
||||
|
||||
// Time % 1000
|
||||
float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
float flTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime();
|
||||
vPackedVsConst1[0] = flTime;
|
||||
vPackedVsConst1[0] -= (float)( (int)( vPackedVsConst1[0] / 1000.0f ) ) * 1000.0f;
|
||||
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 );
|
||||
|
||||
// Set Pixel Shader Combos
|
||||
if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( aftershock_ps20b );
|
||||
SET_DYNAMIC_PIXEL_SHADER( aftershock_ps20b );
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_DYNAMIC_PIXEL_SHADER( aftershock_ps20 );
|
||||
SET_DYNAMIC_PIXEL_SHADER( aftershock_ps20 );
|
||||
}
|
||||
|
||||
// Bind textures
|
||||
pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map
|
||||
if ( bBumpMapping )
|
||||
{
|
||||
pShader->BindTexture( SHADER_SAMPLER1, info.m_nBumpmap, info.m_nBumpFrame );
|
||||
}
|
||||
|
||||
// Set Pixel Shader Constants
|
||||
float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
pShaderAPI->GetWorldSpaceCameraPosition( vEyePos );
|
||||
pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 );
|
||||
|
||||
float vPackedConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPackedConst1[0] = IS_PARAM_DEFINED( info.m_nBlurAmount ) ? params[info.m_nBlurAmount]->GetFloatValue() : kDefaultBlurAmount;
|
||||
vPackedConst1[1] = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount;
|
||||
vPackedConst1[3] = vPackedVsConst1[0]; // Time
|
||||
pShaderAPI->SetPixelShaderConstant( 6, vPackedConst1, 1 );
|
||||
|
||||
// Refract color tint
|
||||
pShaderAPI->SetPixelShaderConstant( 7, IS_PARAM_DEFINED( info.m_nColorTint ) ? params[info.m_nColorTint]->GetVecValue() : kDefaultColorTint, 1 );
|
||||
|
||||
// Silhouette values
|
||||
float vPackedConst8[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPackedConst8[0] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[0] : kDefaultSilhouetteColor[0];
|
||||
vPackedConst8[1] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[1] : kDefaultSilhouetteColor[1];
|
||||
vPackedConst8[2] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[2] : kDefaultSilhouetteColor[2];
|
||||
vPackedConst8[3] = IS_PARAM_DEFINED( info.m_nSilhouetteThickness ) ? params[info.m_nSilhouetteThickness]->GetFloatValue() : kDefaultSilhouetteThickness;
|
||||
pShaderAPI->SetPixelShaderConstant( 8, vPackedConst8, 1 );
|
||||
|
||||
// Ground min/max
|
||||
float vPackedConst9[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
vPackedConst9[0] = IS_PARAM_DEFINED( info.m_nGroundMin ) ? params[info.m_nGroundMin]->GetFloatValue() : kDefaultGroundMin;
|
||||
vPackedConst9[1] = IS_PARAM_DEFINED( info.m_nGroundMax ) ? params[info.m_nGroundMax]->GetFloatValue() : kDefaultGroundMax;
|
||||
pShaderAPI->SetPixelShaderConstant( 9, vPackedConst9, 1 );
|
||||
|
||||
// Set c0 and c1 to contain first two rows of ViewProj matrix
|
||||
VMatrix mView, mProj;
|
||||
pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] );
|
||||
pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] );
|
||||
VMatrix mViewProj = mView * mProj;
|
||||
mViewProj = mViewProj.Transpose3x3();
|
||||
pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 2 );
|
||||
}
|
||||
pShader->Draw();
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============//
|
||||
|
||||
#ifndef AFTERSHOCK_HELPER_H
|
||||
#define AFTERSHOCK_HELPER_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseVSShader;
|
||||
class IMaterialVar;
|
||||
class IShaderDynamicAPI;
|
||||
class IShaderShadow;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init params/ init/ draw methods
|
||||
//-----------------------------------------------------------------------------
|
||||
struct AftershockVars_t
|
||||
{
|
||||
AftershockVars_t() { memset( this, 0xFF, sizeof(AftershockVars_t) ); }
|
||||
|
||||
int m_nColorTint;
|
||||
int m_nRefractAmount;
|
||||
|
||||
int m_nBumpmap;
|
||||
int m_nBumpFrame;
|
||||
int m_nBumpTransform;
|
||||
|
||||
int m_nSilhouetteThickness;
|
||||
int m_nSilhouetteColor;
|
||||
int m_nGroundMin;
|
||||
int m_nGroundMax;
|
||||
int m_nBlurAmount;
|
||||
|
||||
int m_nTime;
|
||||
};
|
||||
|
||||
// Default values (Arrays should only be vec[4])
|
||||
static const float kDefaultColorTint[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
static const float kDefaultRefractAmount = 0.1f;
|
||||
static const float kDefaultSilhouetteThickness = 0.2f;
|
||||
static const float kDefaultSilhouetteColor[4] = { 0.3f, 0.3f, 0.5f, 1.0f };
|
||||
static const float kDefaultGroundMin = -0.3f;
|
||||
static const float kDefaultGroundMax = -0.1f;
|
||||
static const float kDefaultBlurAmount = 0.01f;
|
||||
|
||||
void InitParamsAftershock( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, AftershockVars_t &info );
|
||||
void InitAftershock( CBaseVSShader *pShader, IMaterialVar** params, AftershockVars_t &info );
|
||||
void DrawAftershock( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
|
||||
IShaderShadow* pShaderShadow, AftershockVars_t &info, VertexCompressionType_t vertexCompression );
|
||||
|
||||
#endif // AFTERSHOCK_HELPER_H
|
|
@ -0,0 +1,159 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// Includes =======================================================================================
|
||||
#include "common_vertexlitgeneric_dx9.h"
|
||||
|
||||
// Texture Samplers ===============================================================================
|
||||
sampler g_tRefractionSampler : register( s0 );
|
||||
sampler g_tBumpSampler : register( s1 );
|
||||
|
||||
// Shaders Constants and Globals ==================================================================
|
||||
const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix
|
||||
const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix
|
||||
|
||||
const float4 g_vCameraPosition : register( c5 );
|
||||
const float4 g_vPackedConst6 : register( c6 );
|
||||
#define g_flBlurAmount g_vPackedConst6.x // 0.01f;
|
||||
#define g_flRefractAmount g_vPackedConst6.y // Default = 1.0f
|
||||
#define g_flTime g_vPackedConst6.w
|
||||
|
||||
const float4 g_cColorTint : register( c7 );
|
||||
|
||||
const float4 g_vPackedConst8 : register( c8 );
|
||||
#define g_cSilhouetteColor g_vPackedConst8 //= { 0.3, 0.3, 0.5 };
|
||||
#define g_flSilhouetteThickness g_vPackedConst8.w //= 0.2f;
|
||||
|
||||
const float2 g_vGroundMinMax : register( c9 ); //= { -0.3, -0.1 };
|
||||
|
||||
// 8 2D Poisson offsets (designed to use .xy and .wz swizzles (not .zw)
|
||||
static const float4 g_vPoissonOffset[4] = { float4 (-0.0876f, 0.9703f, 0.5651f, 0.4802f ),
|
||||
float4 ( 0.1851f, 0.1580f, -0.0617f, -0.2616f ),
|
||||
float4 (-0.5477f, -0.6603f, 0.0711f, -0.5325f ),
|
||||
float4 (-0.0751f, -0.8954f, 0.4054f, 0.6384f ) };
|
||||
|
||||
// Interpolated values ============================================================================
|
||||
struct PS_INPUT
|
||||
{
|
||||
float3 vWorldNormal : TEXCOORD0; // World-space normal
|
||||
float3 vWorldTangent : TEXCOORD1;
|
||||
float3 vWorldBinormal : TEXCOORD2;
|
||||
float3 vProjPosForRefract : TEXCOORD3;
|
||||
float3 vWorldViewVector : TEXCOORD4;
|
||||
float4 vUv0 : TEXCOORD5; // uv.xy, uvScroll.xy
|
||||
float4 vUv1 : TEXCOORD6; // uv.xy, uvScroll.xy
|
||||
float2 vUvGroundNoise : TEXCOORD7;
|
||||
};
|
||||
|
||||
// Main ===========================================================================================
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
/*
|
||||
// Bump layer 0
|
||||
float2 vUv0 = i.vUv0Uv1.xy;
|
||||
float2 vUv0Scroll = i.vUv0Uv1.xy * 3.0f;
|
||||
vUv0Scroll.y -= g_flTime * 0.1f;
|
||||
|
||||
float4 vBumpTexel0 = tex2D( g_tBumpSampler, vUv0Scroll.xy );
|
||||
vBumpTexel0 = tex2D( g_tBumpSampler, vUv0.xy + (vBumpTexel0.xy*0.03) );
|
||||
|
||||
// Bump layer 1
|
||||
float2 vUv1 = i.vUv0Uv1.xy * 10.0f;
|
||||
float2 vUv1Scroll = i.vUv0Uv1.xy * 32.0f;
|
||||
vUv1Scroll.y -= g_flTime * 0.1f;
|
||||
|
||||
float4 vBumpTexel1 = tex2D( g_tBumpSampler, vUv1Scroll.xy );
|
||||
vBumpTexel1 = tex2D( g_tBumpSampler, vUv1.xy + (vBumpTexel1.xy*0.03) );
|
||||
//*/
|
||||
|
||||
// Bump layer 0
|
||||
float4 vBumpTexel0 = tex2D( g_tBumpSampler, i.vUv0.wz );
|
||||
vBumpTexel0 = tex2D( g_tBumpSampler, i.vUv0.xy + ( vBumpTexel0.xy*0.03 ) );
|
||||
|
||||
// Bump layer 1
|
||||
float4 vBumpTexel1 = tex2D( g_tBumpSampler, i.vUv1.wz );
|
||||
vBumpTexel1 = tex2D( g_tBumpSampler, i.vUv1.xy + ( vBumpTexel1.xy*0.03 ) );
|
||||
|
||||
// Combine bump layers into tangetn normal
|
||||
float3 vTangentNormal = ( vBumpTexel0 * 2.0f ) - 1.0f;
|
||||
vTangentNormal.xyz += ( vBumpTexel1 * 2.0f - 1.0f ) * 0.5f; // * 0.5f;
|
||||
|
||||
// Transform into world space
|
||||
float3 vWorldNormal = Vec3TangentToWorld( vTangentNormal.xyz, i.vWorldNormal, i.vWorldTangent, i.vWorldBinormal );
|
||||
|
||||
// Effect mask
|
||||
//float flEffectMask = saturate( dot( -i.vWorldViewVector.xyz, i.vWorldNormal.xyz ) * lerp( 2.0f, 1.0f, g_flSilhouetteThickness ) );
|
||||
float flEffectMask = saturate( dot( -i.vWorldViewVector.xyz, i.vWorldNormal.xyz ) * ( (2.0f - g_flSilhouetteThickness) ) );
|
||||
|
||||
// Simulate ground intersection
|
||||
flEffectMask *= smoothstep( g_vGroundMinMax.x, g_vGroundMinMax.y, i.vWorldNormal.z );
|
||||
|
||||
// Soften mask by squaring term
|
||||
flEffectMask *= flEffectMask;
|
||||
|
||||
// Silhouette mask
|
||||
float flSilhouetteHighlightMask = saturate( flEffectMask * ( 1.0f - flEffectMask ) * 4.0f );
|
||||
flSilhouetteHighlightMask *= flSilhouetteHighlightMask * flSilhouetteHighlightMask;
|
||||
|
||||
// Transform world space normal into clip space and project
|
||||
float3 vProjNormal;
|
||||
vProjNormal.x = dot( vWorldNormal.xyz, g_mViewProj0.xyz ); // 1st row
|
||||
vProjNormal.y = dot( vWorldNormal.xyz, g_mViewProj1.xyz ); // 2nd row
|
||||
|
||||
// Compute coordinates for sampling refraction
|
||||
float2 vRefractTexCoordNoWarp = i.vProjPosForRefract.xy / i.vProjPosForRefract.z;
|
||||
float2 vRefractTexCoord = vProjNormal.xy;
|
||||
float scale = lerp( 0.0f, g_flRefractAmount, flEffectMask );// * flEffectMask * flEffectMask ); // Using flEffectMask^3
|
||||
vRefractTexCoord.xy *= scale;
|
||||
vRefractTexCoord.xy += vRefractTexCoordNoWarp.xy;
|
||||
|
||||
// Blur by scalable Poisson filter
|
||||
float flBlurAmount = g_flBlurAmount * flEffectMask;
|
||||
float3 cRefract = tex2D( g_tRefractionSampler, vRefractTexCoord.xy );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].xy * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].wz * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].xy * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].wz * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].xy * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].wz * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].xy * flBlurAmount ) );
|
||||
cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].wz * flBlurAmount ) );
|
||||
cRefract /= 9.0f;
|
||||
|
||||
// Undo tone mapping
|
||||
cRefract /= LINEAR_LIGHT_SCALE;
|
||||
|
||||
// Refract color tint
|
||||
float fColorTintStrength = 1.0f - flEffectMask;
|
||||
float3 cRefractColorTint = lerp( g_cColorTint, 1.0f, fColorTintStrength );
|
||||
|
||||
// Ground noise
|
||||
//float flGroundNoise = tex2D( g_tBumpSampler, i.vUvGroundNoise.xy ).g;
|
||||
//flGroundNoise *= smoothstep( g_vGroundMinMax.y, g_vGroundMinMax.y+0.4, -i.vWorldNormal.z );
|
||||
//flGroundNoise = smoothstep( 0.2, 0.9, flGroundNoise );
|
||||
|
||||
//===============//
|
||||
// Combine terms //
|
||||
//===============//
|
||||
float4 result;
|
||||
result.rgb = cRefract.rgb * cRefractColorTint.rgb;
|
||||
result.rgb += result.rgb * ( flSilhouetteHighlightMask * g_cSilhouetteColor.rgb );
|
||||
//result.rgb += flGroundNoise;
|
||||
|
||||
//result.rgb = float3( 0.0, 0.0, 0.0 );
|
||||
//result.rg = vRefractTexCoord.xy;
|
||||
//result.rg = i.vUv0Uv1.xy;
|
||||
//result.rgb = vBumpTexel0.rgb;
|
||||
//result.rgb = vTangentNormal;
|
||||
//result.rgb = vWorldNormal;
|
||||
//result = flEffectMask;
|
||||
//result = flSilhouetteHighlightMask;
|
||||
|
||||
//result = tex2D( g_tBumpSampler, i.vUvGroundNoise.xy ).y;
|
||||
//result.rgb = flGroundNoise;
|
||||
|
||||
// Set alpha to...
|
||||
result.a = flEffectMask;
|
||||
|
||||
|
||||
return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); //go back to final output when it'll fit.
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
|
||||
// DYNAMIC: "SKINNING" "0..1"
|
||||
|
||||
// Includes
|
||||
#include "common_vs_fxc.h"
|
||||
|
||||
// Globals
|
||||
static const bool g_bSkinning = SKINNING ? true : false;
|
||||
const float g_flTime : register( SHADER_SPECIFIC_CONST_0 );
|
||||
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
|
||||
|
||||
// Structs
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 vPos : POSITION; // Position
|
||||
float4 vNormal : NORMAL; // Normal
|
||||
float4 vBoneWeights : BLENDWEIGHT; // Skin weights
|
||||
float4 vBoneIndices : BLENDINDICES; // Skin indices
|
||||
float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
|
||||
float4 vTangent : TANGENT;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 vProjPosition : POSITION; // Projection-space position
|
||||
float3 vWorldNormal : TEXCOORD0; // World-space normal
|
||||
float3 vWorldTangent : TEXCOORD1;
|
||||
float3 vWorldBinormal : TEXCOORD2;
|
||||
float3 vProjPosForRefract : TEXCOORD3;
|
||||
float3 vWorldViewVector : TEXCOORD4;
|
||||
float4 vUv0 : TEXCOORD5;
|
||||
float4 vUv1 : TEXCOORD6;
|
||||
float2 vUvGroundNoise : TEXCOORD7;
|
||||
};
|
||||
|
||||
// Main
|
||||
VS_OUTPUT main( const VS_INPUT i )
|
||||
{
|
||||
VS_OUTPUT o;
|
||||
|
||||
float4 vObjPosition = i.vPos;
|
||||
float4 vObjTangent = i.vTangent;
|
||||
float3 vObjNormal;
|
||||
DecompressVertex_Normal( i.vNormal, vObjNormal );
|
||||
|
||||
// Transform the position
|
||||
float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
|
||||
float3 vWorldNormal = { 0.0f, 0.0f, 0.0f };
|
||||
float3 vWorldTangent = { 0.0f, 0.0f, 0.0f };
|
||||
float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f };
|
||||
SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal );
|
||||
vWorldNormal.xyz = normalize( vWorldNormal.xyz );
|
||||
vWorldTangent.xyz = normalize( vWorldTangent.xyz );
|
||||
vWorldBinormal.xyz = normalize( vWorldBinormal.xyz );
|
||||
|
||||
o.vWorldNormal.xyz = vWorldNormal.xyz;
|
||||
o.vWorldTangent.xyz = vWorldTangent.xyz;
|
||||
o.vWorldBinormal.xyz = vWorldBinormal.xyz;
|
||||
|
||||
// Transform into projection space
|
||||
float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
|
||||
o.vProjPosition = vProjPosition;
|
||||
|
||||
// Map projected position to the refraction texture
|
||||
float2 vRefractPos;
|
||||
vRefractPos.x = vProjPosition.x;
|
||||
vRefractPos.y = -vProjPosition.y; // Invert Y
|
||||
vRefractPos = (vRefractPos + vProjPosition.w) * 0.5f;
|
||||
o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w);
|
||||
|
||||
// View vector
|
||||
float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz);
|
||||
o.vWorldViewVector.xyz = vWorldViewVector.xyz;
|
||||
|
||||
// Tangent space transform
|
||||
//o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x );
|
||||
//o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y );
|
||||
//o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z );
|
||||
|
||||
// Texture coordinates
|
||||
float2 vBaseUv;
|
||||
vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] );
|
||||
vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] );
|
||||
|
||||
// Bump layer 0
|
||||
float2 vUv0 = vBaseUv.xy;
|
||||
float2 vUv0Scroll = vBaseUv.xy * 3.0f;
|
||||
vUv0Scroll.y -= g_flTime * 0.1f;
|
||||
|
||||
o.vUv0.xy = vUv0.xy;
|
||||
o.vUv0.wz = vUv0Scroll.xy;
|
||||
|
||||
// Bump layer 1
|
||||
float2 vUv1 = vBaseUv.xy * 8.0f;
|
||||
float2 vUv1Scroll = vBaseUv.xy * 16.0f;
|
||||
vUv1Scroll.y -= g_flTime * 0.1f;
|
||||
|
||||
o.vUv1.xy = vUv1.xy;
|
||||
o.vUv1.wz = vUv1Scroll.xy;
|
||||
|
||||
// Ground noise
|
||||
o.vUvGroundNoise.xy = vBaseUv.xy;
|
||||
o.vUvGroundNoise.x *= 3.5f;
|
||||
o.vUvGroundNoise.y *= 0.2105f;
|
||||
o.vUvGroundNoise.y -= g_flTime * 0.04f;
|
||||
|
||||
return o;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
sampler TexSampler : register( s0 );
|
||||
|
||||
float g_flBloomAmount : register( c0 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate
|
||||
};
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 result = g_flBloomAmount * tex2D( TexSampler, i.baseTexCoord );
|
||||
result.a = 1.0f;
|
||||
return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
// blurs colors by averages
|
||||
// bleeds alpha by max of current vs averages
|
||||
|
||||
sampler g_texSampler : register( s0 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
float2 g_vPsTapOffsets[2] : register( c0 );
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 cOut;
|
||||
|
||||
cOut = tex2D( g_texSampler, float2( i.uv.x + g_vPsTapOffsets[0].x, i.uv.y + g_vPsTapOffsets[0].y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x , i.uv.y + g_vPsTapOffsets[0].y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x - g_vPsTapOffsets[0].x, i.uv.y + g_vPsTapOffsets[0].y ) );
|
||||
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x + g_vPsTapOffsets[0].x, i.uv.y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x , i.uv.y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x - g_vPsTapOffsets[0].x, i.uv.y ) );
|
||||
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x + g_vPsTapOffsets[0].x, i.uv.y - g_vPsTapOffsets[0].y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x , i.uv.y - g_vPsTapOffsets[0].y ) );
|
||||
cOut += tex2D( g_texSampler, float2( i.uv.x - g_vPsTapOffsets[0].x, i.uv.y - g_vPsTapOffsets[0].y ) );
|
||||
|
||||
cOut *= (1.0f/9.0f);
|
||||
|
||||
cOut.a = max( cOut.a * 1.0f, tex2D( g_texSampler, i.uv ).a ); //never reduce alpha, only increase it
|
||||
return saturate( cOut );
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
sampler g_texSampler : register( s0 );
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
float2 g_vPsTapOffsets[2] : register( c0 );
|
||||
|
||||
float4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
float4 cOut;
|
||||
|
||||
cOut = 0.25 * tex2D( g_texSampler, i.uv + g_vPsTapOffsets[0] );
|
||||
cOut += 0.25 * tex2D( g_texSampler, i.uv - g_vPsTapOffsets[0] );
|
||||
cOut += 0.25 * tex2D( g_texSampler, i.uv + g_vPsTapOffsets[1] );
|
||||
cOut += 0.25 * tex2D( g_texSampler, i.uv - g_vPsTapOffsets[1] );
|
||||
|
||||
return cOut;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
|
||||
#include "common_ps_fxc.h"
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 vColor : COLOR0;
|
||||
};
|
||||
|
||||
HALF4 main( PS_INPUT i ) : COLOR
|
||||
{
|
||||
return i.vColor;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue