⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vsh_prep.pl

📁 hl2 source code. Do not use it illegal.
💻 PL
📖 第 1 页 / 共 2 页
字号:
	$maxNumBones = 3;
}
else
{
	$maxNumBones = 0;
}

if( $usesLighting )
{
	$totalLightCombos = 22;
}
else
{
	$totalLightCombos = 1;
}

if( $usesHeightFog )
{
	$totalFogCombos = 2;
}
else
{
	$totalFogCombos = 1;
}

#push @finalheader, "// hack to force dependency checking\n";
#push @finalheader, "\#ifdef NEVER\n";
#push @finalheader, "\#include \"" . $filename_base . "\.vsh\"\n";
#push @finalheader, "\#include \"..\\..\\devtools\\bin\\vsh_prep.pl\"\n";
#push @finalheader, "\#endif\n";

$usesModelView = 0;
$usesModelViewProj = 0;
$usesModel = 0;
if( $usesSkinning )
{
	$usesModel = 1;
}

$shaderPermutation = 1;
# Run the output program for all the combinations of bones and lights.
for( $g_numBones = 0; $g_numBones <= $maxNumBones; $g_numBones++ )
{
	for( $lightCombo = 0; $lightCombo < $totalLightCombos; $lightCombo++ )
	{
		for( $fogCombo = 0; $fogCombo < $totalFogCombos; $fogCombo++, $shaderPermutation++ )
		{
			$g_staticLightType = $g_staticLightTypeArray[$lightCombo];
			$g_ambientLightType = $g_ambientLightTypeArray[$lightCombo];
			$g_localLightType1 = $g_localLightType1Array[$lightCombo];
			$g_localLightType2 = $g_localLightType2Array[$lightCombo];
			if( $fogCombo == 0 )
			{
				$g_fogType = "rangefog";
			}
			else
			{
				$g_fogType = "heightfog";
			}
			$g_usesPos				= 0;
			$g_usesBoneWeights		= 0;
			$g_usesBoneIndices		= 0;
			$g_usesNormal			= 0;
			$g_usesColor			= 0;
			$g_usesSpecular			= 0;
			$g_usesTexCoord0		= 0;
			$g_usesTexCoord1		= 0;
			$g_usesTexCoord2		= 0;
			$g_usesTexCoord3		= 0;
			$g_usesTangentS			= 0;
			$g_usesTangentT			= 0;
			$g_usesUserData			= 0;
			undef @output;
			eval $outputProgram;
			if( $g_dx9 )
			{
				# Have to make another pass through after we know which v registers are used. . yuck.
				$g_usesPos				= &UsesRegister( $vPos, @output );
				$g_usesBoneWeights		= &UsesRegister( $vBoneWeights, @output );
				$g_usesBoneIndices		= &UsesRegister( $vBoneIndices, @output );
				$g_usesNormal			= &UsesRegister( $vNormal, @output );
				$g_usesColor			= &UsesRegister( $vColor, @output );
				$g_usesSpecular			= &UsesRegister( $vSpecular, @output );
				$g_usesTexCoord0		= &UsesRegister( $vTexCoord0, @output );
				$g_usesTexCoord1		= &UsesRegister( $vTexCoord1, @output );
				$g_usesTexCoord2		= &UsesRegister( $vTexCoord2, @output );
				$g_usesTexCoord3		= &UsesRegister( $vTexCoord3, @output );
				$g_usesTangentS			= &UsesRegister( $vTangentS, @output );
				$g_usesTangentT			= &UsesRegister( $vTangentT, @output );
				$g_usesUserData			= &UsesRegister( $vUserData, @output );
				undef @output;
				eval $outputProgram;
			}
			&CheckUnfreedRegisters();
			for( $i = 0; $i < scalar( @output ); $i++ )
			{
				# remove whitespace from the beginning of each line.
				$output[$i] =~ s/^\s+//;
				# remove LINEINFO from empty lines.
				$output[$i] =~ s/^; LINEINFO.*//;
			}
	#		print @output;			
			$outfilename_base = 
				"vertexShader_" . $filename_base . "_" . 
				$g_staticLightType . "_" . 
			    $g_ambientLightType . "_" . 
			    $g_localLightType1 . "_" . 
			    $g_localLightType2 . "_" . 
				$g_numBones . "_" . $g_fogType;
			$outfilename = "$vshtmp\\" . $outfilename_base . ".tmp";
			$outhdrfilename = "$vshtmp\\" . $outfilename_base . ".h";
	#		print "$filename_base $g_numBones bones light1: $g_lightType1 light2: $g_lightType2\n";

			open OUTPUT, ">$outfilename" || die;
			print OUTPUT @output;
			close OUTPUT;

			local( $instructionCount ) = &CountInstructions( @output );
			if( &UsesRegister( $cModelView0, @output ) ||
				&UsesRegister( $cModelView1, @output ) ||
				&UsesRegister( $cModelView2, @output ) ||
				&UsesRegister( $cModelView3, @output ) )
			{
				$usesModelView = 1;
			}
			if( &UsesRegister( $cModelViewProj0, @output ) ||
				&UsesRegister( $cModelViewProj1, @output ) ||
				&UsesRegister( $cModelViewProj2, @output ) ||
				&UsesRegister( $cModelViewProj3, @output ) )
			{
				$usesModelViewProj = 1;
			}
			if( &UsesRegister( $cModel0, @output ) ||
				&UsesRegister( $cModel1, @output ) ||
				&UsesRegister( $cModel2, @output ) )
			{
				$usesModel = 1;
			}

			local( $debug );

			$debug = 1;
	#		for( $debug = 1; $debug >= 0; $debug-- )
			{
				# assemble the vertex shader
				unlink $outhdrfilename;
				if( $g_dx9 )
				{
					$vsa = "..\\..\\devtools\\bin\\vsa9";
					$vsadebug = "$vsa /nologo /Zi /Fh$outhdrfilename";
					$vsanodebug = "$vsa /nologo /Fh$outhdrfilename";
				}
				else
				{
					$vsa = "..\\..\\devtools\\bin\\vsa8_1";
					$vsadebug = "$vsa -h";
					$vsanodebug = "$vsa -h";
				}
				if( $debug )
				{
#					print "$vsadebug $outfilename 2>&1\n";
					@vsaoutput = `$vsadebug $outfilename 2>&1`;
					print @vsaoutput;
				}
				else
				{
#					print "$vsanodebug $outfilename 2>&1\n";
					@vsaoutput = `$vsanodebug $outfilename 2>&1`;
#					print @vsaoutput;
				}
				&TranslateErrorMessages( @vsaoutput );
				if( $debug )
				{
					print $filename_base . " ";
					print &PadString( $shaderPermutation, 3 ) . " ";
#					print &PadString( $lightCombo, 2 ) . " ";
					print &PadString( $g_staticLightType, 6 ) . " ";
					print &PadString( $g_ambientLightType, 7 ) . " ";
					print &PadString( $g_localLightType1, 11 ) . " ";
					print &PadString( $g_localLightType2, 11 ) . " ";
					print &PadString( $g_numBones . " bones ", 7 );
					print &PadString( $g_fogType . " ", 10 );
					print "$instructionCount instructions\n";
				}

				if( !stat $outhdrfilename )
				{
					print "didn't create $outhdrfilename\n";
					# should really just die here.
					die;
				}

				# read the header file
				open HDR, "<$outhdrfilename";
				@hdr = <HDR>;
				close HDR;

				# Remove the header file. . we don't need it anymore since we are 
				# going to generate a ".inc" file.
				unlink $outhdrfilename;
				
				local( $i );
				for( $i = 0; $i < scalar( @hdr ); $i++ )
				{
					if( $g_dx9 )
					{
						$hdr[$i] =~ s/g_.*_main/$outfilename_base/;
						$hdr[$i] =~ s/DWORD/static unsigned int/;
						$hdr[$i] =~ s/const//;
					}
					else
					{
						$hdr[$i] =~ s/dwVertexShader/$outfilename_base/;
						$hdr[$i] =~ s/DWORD/static unsigned int/;
					}
				}
			
				if( $debug )
				{
	#				push @finalheader, "#ifdef _DEBUG\n";
				}
				else
				{
	#				push @finalheader, "#ifndef _DEBUG\n";
				}
				push @finalheader, @hdr;
	#			push @finalheader, "#endif\n";
			}
		}
	}
}

print "   usesmodelview: $usesModelView ";
print "usesmodelviewproj: $usesModelViewProj ";
print "usesmodel: $usesModel\n";

# stick info about the shaders at the end of the inc file.
push @finalheader, "static PrecompiledShaderByteCode_t $filename_base" . "_vertex_shaders[] = {\n";
for( $g_numBones = 0; $g_numBones <= $maxNumBones; $g_numBones++ )
{
	for( $lightCombo = 0; $lightCombo < $totalLightCombos; $lightCombo++ )
	{
		for( $fogCombo = 0; $fogCombo < $totalFogCombos; $fogCombo++ )
		{
			$g_staticLightType = $g_staticLightTypeArray[$lightCombo];
			$g_ambientLightType = $g_ambientLightTypeArray[$lightCombo];
			$g_localLightType1 = $g_localLightType1Array[$lightCombo];
			$g_localLightType2 = $g_localLightType2Array[$lightCombo];
			if( $fogCombo == 0 )
			{
				$g_fogType = "rangefog";
			}
			else
			{
				$g_fogType = "heightfog";
			}
			$outfilename_base = 
				"\tvertexShader_" . $filename_base . "_" .
				$g_staticLightType . "_" . $g_ambientLightType . "_" . 
				$g_localLightType1 . "_" . $g_localLightType2 . "_" . 
				$g_numBones . "_" . $g_fogType;
			push @finalheader, "{ $outfilename_base, sizeof( $outfilename_base ) },\n";
		}	
	}
}
push @finalheader, "};\n";


push @finalheader, "struct $filename_base" . "_VertexShader_t : public PrecompiledShader_t\n";
push @finalheader, "{\n";
push @finalheader, "\t$filename_base" . "_VertexShader_t()\n";
push @finalheader, "\t{\n";
push @finalheader, "\t\tm_nFlags = 0;\n";
if( $usesSkinning )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_SKINNING;\n";
}
if( $usesLighting )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_LIGHTING;\n";
}
if( $usesHeightFog )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_HEIGHT_FOG;\n";
}
if( $usesModelView )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_MODEL_VIEW_MATRIX;\n";
}
if( $usesModelViewProj )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_MODEL_VIEW_PROJ_MATRIX;\n";
}
if( $usesModel )
{
	push @finalheader, "\t\tm_nFlags |= SHADER_USES_MODEL_MATRIX;\n";
}

#push @finalheader, "\t\tppVertexShaders = $filename_base" . "_vertex_shaders;\n";
push @finalheader, "\t\tm_pByteCode = $filename_base" . "_vertex_shaders;\n";
push @finalheader, "\t\tm_pName = \"$filename_base\";\n";
push @finalheader, "\t\tm_nShaderCount = " . ( $maxNumBones + 1 ) * $totalFogCombos * $totalLightCombos . ";\n";
push @finalheader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n";
push @finalheader, "\t}\n";
push @finalheader, "};\n";
push @finalheader, "static $filename_base" . "_VertexShader_t $filename_base" . "_VertexShaderInstance;\n";


# Write the final header file with the compiled vertex shader programs.
$finalheadername = "$vshtmp\\" . $filename_base . ".inc";
#print "writing $finalheadername\n";
open FINALHEADER, ">$finalheadername" || die;
print FINALHEADER @finalheader;
close FINALHEADER;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -