sdk_lightmap

From Valve Developer Community
Jump to: navigation, search
Obsolete-notext.png
This entity is Obsolete. Its use is discouraged, and it may only exist/function in older engine branches.


sdk_lightmap is a sample Shader that was provided with the original Source SDK, it has since been replaced by the current set of SDK Shaders.

Obsolete-notext.pngDeprecated:This shader relies on deprecated functionality of the materialsystem that has been removed from the Source 2007 SDK and upwards.

sdk_lightmap_ps20.fxc

#include "common_ps_fxc.h"

sampler BaseTextureSampler	: register( s0 );
sampler LightmapSampler		: register( s1 );

struct PS_INPUT
{
	HALF2 vBaseTexCoord	: TEXCOORD0;
	HALF2 vLightmapTexCoord : TEXCOORD1;
};

HALF4 main( PS_INPUT i ) : COLOR
{
	// Sample the texture and lightmap.
	HALF4 baseColor = tex2D( BaseTextureSampler, i.vBaseTexCoord );
	HALF4 lightmapSample = tex2D( LightmapSampler, i.vLightmapTexCoord );
	
	// Multiply the base and lightmap colors.
	baseColor *= lightmapSample;
	
	return baseColor;
}

sdk_lightmap_vs20.fxc

#include "common_vs_fxc.h"

struct VS_INPUT
{
	float3 vPos						: POSITION;
	float2 vBaseTexCoord			: TEXCOORD0;
	float2 vLightmapTexCoord		: TEXCOORD1;
};

struct VS_OUTPUT
{
    float4 vProjPos					: POSITION;	
	float  flFog					: FOG;
	float2 vBaseTexCoord			: TEXCOORD0;
	float2 vLightmapTexCoord		: TEXCOORD2;
};

VS_OUTPUT main( const VS_INPUT v )
{
	VS_OUTPUT o = ( VS_OUTPUT )0;

	// Project the point.
	float4 vProjPos = mul( float4( v.vPos, 1 ), cModelViewProj );
	o.vProjPos = vProjPos;

	// Pass texture coordinates through to the pixel shader.
	o.vBaseTexCoord = v.vBaseTexCoord;
	o.vLightmapTexCoord = v.vLightmapTexCoord;

	// Calculate the fog.
	float3 worldPos = mul( float4( v.vPos, 1 ), cModel[0] );
	o.flFog = 0;

	return o;
}

sdk_lightmap.cpp

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Just about as simple as a shader gets. Specify a vertex
//          and pixel shader, bind textures, and that's it.
//
// $Header: $
// $NoKeywords: $
//=============================================================================//

#include "BaseVSShader.h"
#include "convar.h"

// Note: you have to run buildshaders.bat to generate these files from the FXC code.
#include "sdk_lightmap_ps20.inc"
#include "sdk_lightmap_vs20.inc"


BEGIN_VS_SHADER( SDK_Lightmap, "Help for SDK_Lightmap" )

	BEGIN_SHADER_PARAMS
	END_SHADER_PARAMS

	// Set up anything that is necessary to make decisions in SHADER_FALLBACK.
	SHADER_INIT_PARAMS()
	{
	}

	SHADER_FALLBACK
	{
		return 0;
	}

	SHADER_INIT
	{
		LoadTexture( BASETEXTURE );
	}

	SHADER_DRAW
	{
		SHADOW_STATE
		{
			// Enable the texture for base texture and lightmap.
			pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true );
			pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true );
			
			int fmt = VERTEX_POSITION;
			pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0, 0 );

			sdk_lightmap_vs20_Static_Index vshIndex;
			pShaderShadow->SetVertexShader( "sdk_lightmap_vs20", vshIndex.GetIndex() );

			sdk_lightmap_ps20_Static_Index pshIndex;
			pShaderShadow->SetPixelShader( "sdk_lightmap_ps20", pshIndex.GetIndex() );

			DefaultFog();
		}
		DYNAMIC_STATE
		{
			BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME );
			pShaderAPI->BindLightmap( SHADER_TEXTURE_STAGE1 );
		}
		Draw();
	}
END_SHADER