summaryrefslogtreecommitdiff
path: root/materialsystem/stdshaders/flashlight_ps11.fxc
blob: f2416d1653b7745599001a503c3ebff363dd62e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose: 
//
//=============================================================================

//	STATIC: "NORMALMAP"				"0..1"
//	STATIC: "NOCULL"				"0..1"

#include "common_ps_fxc.h"

sampler SpotSampler					: register( s0 );
sampler BaseTextureSampler			: register( s1 );
sampler NormalizingCubemapSampler	: register( s2 );
// use a normalizing cube map here if we aren't normal mapping
#if NORMALMAP
sampler NormalMapSampler			: register( s3 );
#else
sampler NormalizingCubemapSampler2	: register( s3 );
#endif

static const HALF g_OverbrightFactor = 2.0f;

struct PS_INPUT
{
	float4 spotTexCoord				: TEXCOORD0;
	float2 baseTexCoord				: TEXCOORD1;
#if NORMALMAP
	float3 tangentPosToLightVector	: TEXCOORD2;
	float2 normalMapTexCoord		: TEXCOORD3;
#else
	float3 worldPosToLightVector	: TEXCOORD2;
	float3 normal					: TEXCOORD3;
#endif
	float4 vertAtten				: COLOR0;
};

float4 main( PS_INPUT i ) : COLOR
{
#if NORMALMAP
	float3 normal = tex2D( NormalMapSampler, i.normalMapTexCoord ) * 2.0f - 1.0f;
#else
	float3 normal = texCUBE( NormalizingCubemapSampler2, i.normal ) * 2.0f - 1.0f;
#endif
	
	float3 spotColor = tex2D( SpotSampler, i.spotTexCoord );
	float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
	float3 baseColor = baseSample.xyz;
#if NORMALMAP
	// wrap this!
	float3 tangentPosToLightVector = texCUBE( NormalizingCubemapSampler, i.tangentPosToLightVector ) * 2.0f - 1.0f;
	float nDotL = saturate( dot( tangentPosToLightVector, normal ) );
#else
	float3 worldPosToLightVector = texCUBE( NormalizingCubemapSampler, i.worldPosToLightVector ) * 2.0f - 1.0f;
	float nDotL = saturate( dot( worldPosToLightVector, normal ) );
#endif	
	float3 outcolor;

	outcolor = spotColor * baseColor * g_OverbrightFactor;

#if !NOCULL
	outcolor *= nDotL;
#endif

	// NOTE!!  This has to be last to avoid loss of range.
	outcolor *= i.vertAtten;

	return float4( outcolor.xyz, baseSample.a * i.vertAtten.a );
}