Talk:Shader authoring/Anatomy of a Shader/Combo Variables

From Valve Developer Community
Jump to: navigation, search

static combo doesn't work as it's supposed

Hello everyone,
Today I tried to work with static combos but it didn't work as I wanted it to work.
here is the code:

// STATIC: "QUALITY" "0..4"
#include "common_ps_fxc.h"

struct PS_INPUT
{
	float2 baseTexCoord			: TEXCOORD0;
	float2 ZeroTexCoord				: TEXCOORD1;
	float2 bloomTexCoord            : TEXCOORD2;
};

sampler BaseTexture : register ( s0 );
const float blur_amount : register( c1 );
const float2 blur_center : register( c2 );
const float2 texelsize : register( c3 );

float4 main(PS_INPUT i) : COLOR //takes texture coordinates as input
{	
	/* Output texture color */
	float4 output = float4(0.0, 0.0, 0.0, 0.0);
	float2 tmpCoord = i.baseTexCoord;
	float4 BaseMap = tex2D(BaseTexture, i.baseTexCoord);
	float4 BaseMask;

	float intensity = dot( BaseMap, float4(0.5, 0.5, 0.5, 0.0) );
	
	if(intensity < 0.5)
	{
		BaseMask = float4(1.0, 1.0, 1.0, 1.0);
	}
	else
	{
		BaseMask = float4(0.0, 0.0, 0.0, 0.0);
	}
	
	tmpCoord += texelsize * 0.5 - blur_center;
#if (QUALITY == 4)
	for(int i = 0; i < 18; i++)
	{
		float scale = 1.0 - blur_amount * (float(i) / 11.0);

		output += tex2D( BaseTexture, tmpCoord * scale + blur_center );
	}
	
	output /= 18;	
#elif (QUALITY == 3)
	for(int i = 0; i < 14; i++)
	{
		float scale = 1.0 - blur_amount * (float(i) / 11.0);

		output += tex2D( BaseTexture, tmpCoord * scale + blur_center );
	}
	
	output /= 14;
#elif (QUALITY == 2)
	for(int i = 0; i < 9; i++)
	{
		float scale = 1.0 - blur_amount * (float(i) / 11.0);

		output += tex2D( BaseTexture, tmpCoord * scale + blur_center );
	}
	
	output /= 9;
#elif (QUALITY == 1)
	for(int i = 0; i < 5; i++)
	{
		float scale = 1.0 - blur_amount * (float(i) / 11.0);

		output += tex2D( BaseTexture, tmpCoord * scale + blur_center );
	}
	
	output /= 5;
#endif

	output.a = BaseMask.a;	

	return output; //return texel at tex coordinates location
}

With this my Shader doesn't work, without it my Shader works fine. --Pfannkuchen 20:05, 24 January 2011 (UTC)