Beispiel #1
0
/**
 * Get the flags associated with a format string
 * @param format The format string to search.
 * @param flags A pointer to flags that are turned on.
 * @return A pointer to the format string
 */
const char *_get_flags(const char *format, uchar *flags)
{
	uchar f;
	uchar done = 0;
	
	// start with no flags
	CLEAR_FLAGS(f, PRINTF_ALL);
	
	// skip past the % char
	++format;
	
	while(!done) {

		char ch = *format++;

		switch(ch) {
		case '-':
			// justify, overrides padding
			SET_FLAGS(f, PRINTF_JUSTIFY);
			CLEAR_FLAGS(f, PRINTF_PADDING);
			break;
		case '+':
			// sign, overrides space
			SET_FLAGS(f, PRINTF_SIGN);
			CLEAR_FLAGS(f, PRINTF_SPACE);
			break;
		case ' ':
			if(!GET_FLAG(f, PRINTF_SIGN)) {
				SET_FLAGS(f, PRINTF_SPACE);
			}
			break;
		case '#':
			SET_FLAGS(f, PRINTF_PREFIX);
			break;
		case '0':
			if(!GET_FLAG(f, PRINTF_JUSTIFY)) {
				SET_FLAGS(f, PRINTF_PADDING);
			}
			break;
		default:
			done = 1;
			--format;
		}
	}

	*flags = f;

	return format;
}
	END_SHADER_PARAMS

	SHADER_INIT_PARAMS()
	{
		if( !params[ENVMAPTINT]->IsDefined() )
			params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
		if( !params[ENVMAPMASKSCALE]->IsDefined() )
			params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );
		if( !params[DETAILSCALE]->IsDefined() )
			params[DETAILSCALE]->SetFloatValue( 4.0f );

		// No texture means no env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}

		// Get rid of the envmap if it's optional for this dx level.
		if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() )
		{
			params[ENVMAP]->SetUndefined();
		}

		// If mat_specular 0, then get rid of envmap
		if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() )
		{
			params[ENVMAP]->SetUndefined();
		}
	}
	END_SHADER_PARAMS

	SHADER_INIT_PARAMS()
	{
		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
		if( !params[ENVMAPMASKSCALE]->IsDefined() )
			params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );

		if( !params[DETAILSCALE]->IsDefined() )
			params[DETAILSCALE]->SetFloatValue( 1.0f );

		if( !params[ENVMAPTINT]->IsDefined() )
			params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );

		// No texture means no self-illum or env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}
	}
Beispiel #4
0
/**
 * Sets a property key to the specified value. If the key does
 * not exist and <tt>useMalloc<tt> is <tt>KNI_TRUE<tt>, use
 * <tt>midpMalloc()<tt> to make a copy of the contents of
 * <tt>key<tt>. If the key does not exist and <tt>useMalloc<tt>
 * is <tt>KNI_FALSE<tt>, make a copy of the pointer to
 * <tt>key<tt>. If the <tt>key<tt> already exists in the
 * property lists, modify its associated value.
 *
 * @param propertySet The property set in which to add/modify
 *                    <tt>key<tt>
 * @param key The key to set
 * @param value The value to associate with <tt>key<tt>
 * @param useMalloc If <tt>KNI_TRUE<tt>, use <tt>midpMalloc()<tt>
 *                  to make a copy of the contents of <tt>value<tt>,
 *                  otherwise make a copy of the pointer to
 *                  <tt>value<tt>.
 */
static void
setProp(Property** propertySet, const char* key, const char* value,
        jboolean useMalloc) {
    Property *p;
    for (p = *propertySet; p; p = p->next) {
        if (strcmp(key, p->key) == 0) {
            if (IS_NEW_VALUE(p)) {
                midpFree((void *)p->value);
            }
            if (useMalloc) {
                SET_NEW_VALUE(p);
                p->value = midpStrdup(value);
            } else {
                UNSET_NEW_VALUE(p);
                p->value = value;
            }
            /*
             * if midpStrdup fails we will just return without setting
             * the value to anything other than NULL
             */
            return;
        }
    }

    /* If the value is not defined, add it now */
    p = (Property*)midpMalloc(sizeof(Property));
    if (NULL != p){
        p->next = *propertySet;
        CLEAR_FLAGS(p);
        if (useMalloc) {
            SET_NEW_VALUE(p);
            SET_NEW_KEY(p);
            p->key = midpStrdup(key);
            p->value = midpStrdup(value);
        } else {
            UNSET_NEW_VALUE(p);
            UNSET_NEW_KEY(p);
            p->value = value;
            p->key = key;
        }

        if ((p->key == NULL) || (p->value == NULL && value != NULL)) {
            /* do nothing if there is no memory */
            if (useMalloc) {
                midpFree((void *)p->key);
                midpFree((void *)p->value);
            }
            midpFree((void *)p);
            return;
        }
        *propertySet = p ;
    }
}
Beispiel #5
0
extern t_account * create_vaccount(const char *username, unsigned int uid)
{
    /* this is a modified(?) version of account_create */
    t_account * account;

    account = malloc(sizeof(t_account));
    if (!account)
    {
		eventlog(eventlog_level_error,"create_vaccount","could not allocate memory for account");
		return NULL;
    }
    account->attrs    = NULL;
    account->age      = 0;
    CLEAR_FLAGS(account);

    account->namehash = 0; /* hash it later */
    account->uid      = 0;

    account->filename = NULL;	/* there is no local account file */
    account->bits_state = account_state_unknown;

    if (username)
    {
		if (username[0]!='#') {
			if (strchr(username,' '))
			{
				eventlog(eventlog_level_error,"create_vaccount","username contains spaces");
				account_destroy(account);
				return NULL;
			}
			if (strlen(username)>=MAX_USER_NAME)
			{
				eventlog(eventlog_level_error,"create_vaccount","username \"%s\" is too long (%u chars)",username,strlen(username));
				account_destroy(account);
				return NULL;
			}
			account_set_strattr(account,"BNET\\acct\\username",username);
            account->namehash = account_hash(username);
		} else {
			if (str_to_uint(&username[1],&account->uid)<0) {
				eventlog(eventlog_level_warn,"create_vaccount","invalid username \"%s\"",username);
			}
		}
    }
    account_set_numattr(account,"BNET\\acct\\userid",account->uid);
    return account;
}
	BEGIN_SHADER_PARAMS
	END_SHADER_PARAMS

	// Set up anything that is necessary to make decisions in SHADER_FALLBACK.
	SHADER_INIT_PARAMS()
	{
		// No texture means no self-illum or env mask in base alpha
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		
		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}

		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
	}
Beispiel #7
0
	SHADER_INIT_PARAMS()
	{
		SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );

		if ( g_pHardwareConfig->HasFastVertexTextures() )
			SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );

		//const bool bIsDecal = IS_FLAG_SET( MATERIAL_VAR_DECAL );
		const bool bDeferredActive = GetDeferredExt()->IsDeferredLightingEnabled();
		if( bDeferredActive )// && !bIsDecal )
		{
			const bool bTranslucent = IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
			const bool bAlphaTest = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST );

			if( bTranslucent ) 
			{
				CLEAR_FLAGS( MATERIAL_VAR_TRANSLUCENT );
				SET_FLAGS( MATERIAL_VAR_ALPHATEST );

				params[ALPHATESTREFERENCE]->SetFloatValue( 0.5f );
			}
			else if( bAlphaTest )
			{
				if( params[ALPHATESTREFERENCE]->GetFloatValue() == 0.0f )
					params[ALPHATESTREFERENCE]->SetFloatValue( 0.5f );
			}
		}

		const bool bDrawToGBuffer = DrawToGBuffer( params );

		if ( bDrawToGBuffer )
		{
			defParms_gBuffer parms_gbuffer;
			SetupParmsGBuffer( parms_gbuffer );
			InitParmsGBuffer( parms_gbuffer, this, params );
		
			defParms_shadow parms_shadow;
			SetupParmsShadow( parms_shadow );
			InitParmsShadowPass( parms_shadow, this, params );
		}
	}
	END_SHADER_PARAMS

	SHADER_INIT_PARAMS()
	{
		if( !params[DETAILSCALE]->IsDefined() )
			params[DETAILSCALE]->SetFloatValue( 1.0f );

		if( !params[ENVMAPTINT]->IsDefined() )
			params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );

		if( !params[ENVMAPCONTRAST]->IsDefined() )
			params[ENVMAPCONTRAST]->SetFloatValue( 0.0f );
		
		if( !params[ENVMAPSATURATION]->IsDefined() )
			params[ENVMAPSATURATION]->SetFloatValue( 1.0f );
		
		if( !params[UNLITFACTOR]->IsDefined() )
			params[UNLITFACTOR]->SetFloatValue( 0.3f );

		if( !params[FRESNELREFLECTION]->IsDefined() )
			params[FRESNELREFLECTION]->SetFloatValue( 1.0f );

		if( !params[ENVMAPMASKFRAME]->IsDefined() )
			params[ENVMAPMASKFRAME]->SetIntValue( 0 );
		
		if( !params[ENVMAPFRAME]->IsDefined() )
			params[ENVMAPFRAME]->SetIntValue( 0 );

		// No texture means no self-illum or env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}
	}
Beispiel #9
0
void methctx_reference(STATE, OBJECT ctx) {
  struct fast_context *fc;

  /* Don't do it again. */
  if(!stack_context_p(ctx)) return;
  
  /* Has to be done first because this uses informated we're about
     to overwrite. */
  object_memory_context_referenced(state->om, ctx);
  
  CLEAR_FLAGS(ctx);
  ctx->gc_zone = YoungObjectZone;
  switch(FASTCTX(ctx)->type) {
  case FASTCTX_NORMAL:
    SET_CLASS(ctx, BASIC_CLASS(fastctx));
    ctx->obj_type = MContextType;
    ctx->CTXFast = TRUE;
    break;
  case FASTCTX_BLOCK:  
    SET_CLASS(ctx, BASIC_CLASS(blokctx));
    ctx->obj_type = BContextType;
    break;
  case FASTCTX_NMC:
    SET_CLASS(ctx, BASIC_CLASS(nmc));
    ctx->obj_type = MContextType;
    break;
  }
  SET_NUM_FIELDS(ctx, FASTCTX_FIELDS);
  ctx->StoresBytes = TRUE;
  ctx->ForeverYoung = TRUE;
  
  fc = FASTCTX(ctx);
  
  /* Fixup the locals tuple. */
  if(!NIL_P(fc->locals) && fc->locals->gc_zone == 0) {
    fc->locals->gc_zone = YoungObjectZone;
  }

}
Beispiel #10
0
/************************************************************************
 *									*
 *	device_init( par, param ) - initialize the device info.		*
 *									*
 *  Original:	MEL	2/89						*
 *									*
 ************************************************************************/
device_init( )
{
    int mat, mat2, i;

    n_con = 0;
    n_ckt = 0;
    dopcalcdone = FALSE;

    /*Electrons*/
    impur[N].diff_coeff = Nmobil;;
    impur[N].coupling = Ncoupling;
    impur[N].boundary = Nboundary;
    impur[N].algebc = NULL;
    impur[N].active = NULL;
    impur[N].time_val = time_val;
    impur[N].block_set = electron_block;
    /*constants*/
    for(mat = 0; mat < MAXMAT; mat++) {
	for(i = 0; i < 25; i++) {
		impur[N].constant[mat][i][0] = 0.0;
		impur[N].constant[mat][i][1] = 0.0;
		}
	for(mat2 = 0; mat2 < MAXMAT; mat2++) {
	    impur[N].seg[SEG0][mat][mat2] = 1.0;
	    impur[N].seg[SEGE][mat][mat2] = 0.0;
	    impur[N].seg[TRN0][mat][mat2] = 0.0;
	    impur[N].seg[TRNE][mat][mat2] = 0.0;
	}
    }
    CLEAR_FLAGS(N, ALL_FLAGS);
    SET_FLAGS(N, PSEUDO);

    /*interstitials*/
    impur[H].diff_coeff = Hmobil;
    impur[H].coupling = Hcoupling;
    impur[H].boundary = Hboundary;
    impur[H].algebc = NULL;
    impur[H].active = NULL;
    impur[H].time_val = time_val;
    impur[H].block_set = hole_block;
    /*constants*/
    for(mat = 0; mat < MAXMAT; mat++) {
	for(i = 0; i < 25; i++) {
		impur[H].constant[mat][i][0] = 0.0;
		impur[H].constant[mat][i][1] = 0.0;
		}
	for(mat2 = 0; mat2 < MAXMAT; mat2++) {
	    impur[H].seg[SEG0][mat][mat2] = 1.0;
	    impur[H].seg[SEGE][mat][mat2] = 0.0;
	    impur[H].seg[TRN0][mat][mat2] = 0.0;
	    impur[H].seg[TRNE][mat][mat2] = 0.0;
	}
    }
    CLEAR_FLAGS(H, ALL_FLAGS);
    SET_FLAGS(H, PSEUDO);

    /*potential*/
    CLEAR_FLAGS(Psi, ALL_FLAGS);
    SET_FLAGS(N, (MOBILE | DIFFUSING | STEADY | LOCKSTEP) );
    impur[Psi].diff_coeff = NULL;
    impur[Psi].boundary = Psiboundary;
    impur[Psi].algebc = NULL;
    impur[Psi].coupling = NULL;
    impur[Psi].active = NULL;
    impur[Psi].time_val = NULL;
    impur[Psi].block_set = poisson_block;
    for(mat = 0; mat < MAXMAT; mat++) {
	for(i = 0; i < 25; i++) {
		impur[Psi].constant[mat][i][0] = 0.0;
		impur[Psi].constant[mat][i][1] = 0.0;
		}
	for(mat2 = 0; mat2 < MAXMAT; mat2++) {
	    impur[Psi].seg[0][mat][mat2] = 0.0;
	    impur[Psi].seg[1][mat][mat2] = 0.0;
	    impur[Psi].seg[2][mat][mat2] = 0.0;
	    impur[Psi].seg[3][mat][mat2] = 0.0;
	}
    }

    /*circuit terms*/
    CLEAR_FLAGS(CKT, ALL_FLAGS);
    impur[CKT].diff_coeff = NULL;
    impur[CKT].boundary = NULL;
    impur[CKT].algebc = NULL;
    impur[CKT].coupling = NULL;
    impur[CKT].active = NULL;
    impur[CKT].time_val = NULL;
    impur[CKT].block_set = circuit_setup;
    /*these are all useless...*/
    for(mat = 0; mat < MAXMAT; mat++) {
	for(i = 0; i < 25; i++) {
		impur[Psi].constant[mat][i][0] = 0.0;
		impur[Psi].constant[mat][i][1] = 0.0;
		}
	for(mat2 = 0; mat2 < MAXMAT; mat2++) {
	    impur[Psi].seg[0][mat][mat2] = 0.0;
	    impur[Psi].seg[1][mat][mat2] = 0.0;
	    impur[Psi].seg[2][mat][mat2] = 0.0;
	    impur[Psi].seg[3][mat][mat2] = 0.0;
	}
    }
}
void InitVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info )
{
	Assert( info.m_nPhong >= 0 );

	if( params[info.m_nPhong]->GetIntValue() )
	{
		InitSkin_DX9( pShader, params, true, info );
		return;
	}

	Assert( info.m_nFlashlightTexture >= 0 );
	pShader->LoadTexture( info.m_nFlashlightTexture );
	
	bool bIsBaseTextureTranslucent = false;
	if ( params[info.m_nBaseTexture]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nBaseTexture );
		
		if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
		{
			bIsBaseTextureTranslucent = true;
		}
	}
	// No alpha channel in any of the textures? No self illum or envmapmask
	if ( !bIsBaseTextureTranslucent )
	{
		CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	if ( params[info.m_nDetail]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nDetail );
	}
	
	if ( g_pConfig->UseBumpmapping() )
	{
		if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
		{
			pShader->LoadBumpMap( info.m_nBumpmap );
			SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL );
		}
	}

	// Don't alpha test if the alpha channel is used for other purposes
	if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
	{
		CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
	}
	
	if ( params[info.m_nEnvmap]->IsDefined() )
	{
		if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) )
		{
			pShader->LoadCubeMap( info.m_nEnvmap );
		}
		else
		{
			pShader->LoadTexture( info.m_nEnvmap );
		}
		
		if( !g_pHardwareConfig->SupportsCubeMaps() )
		{
			SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE );
		}
	}
	if ( params[info.m_nEnvmapMask]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nEnvmapMask );
	}
}
	SHADER_INIT_PARAMS()
	{

		if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() )
		{
			params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 );
		}
	
		params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );

		// Write over $basetexture with $albedo if we are going to be using diffuse normal mapping.
		if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && params[ALBEDO]->IsDefined() &&
			params[BASETEXTURE]->IsDefined() && 
			!( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) )
		{
			params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() );
		}
	
		if( !params[NODIFFUSEBUMPLIGHTING]->IsDefined() )
		{
			params[NODIFFUSEBUMPLIGHTING]->SetIntValue( 0 );
		}

		if( !params[SELFILLUMTINT]->IsDefined() )
		{
			params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
		}

		if( !params[DETAILSCALE]->IsDefined() )
		{
			params[DETAILSCALE]->SetFloatValue( 4.0f );
		}

		if( !params[BUMPFRAME]->IsDefined() )
		{
			params[BUMPFRAME]->SetIntValue( 0 );
		}

		if( !params[DETAILFRAME]->IsDefined() )
		{
			params[DETAILFRAME]->SetIntValue( 0 );
		}

		// No texture means no self-illum or env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}

		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
		if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) )
		{
			SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
		}

		// srgb read 360
		InitIntParam( SHADERSRGBREAD360, params, 0 );
	}
void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info )
{
	if ( g_pHardwareConfig->SupportsBorderColor() )
	{
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
	}
	else
	{
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
	}

	// Write over $basetexture with $albedo if we are going to be using diffuse normal mapping.
	if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() &&
		params[info.m_nBaseTexture]->IsDefined() && 
		!( params[info.m_nNoDiffuseBumpLighting]->IsDefined() && params[info.m_nNoDiffuseBumpLighting]->GetIntValue() ) )
	{
		params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() );
	}

	if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() )
	{
		if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 )
		{
			Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName );
			params[info.m_nEnvmap]->SetUndefined();
		}
	}
	
	if ( (mat_disable_lightwarp.GetBool() ) &&
		 (info.m_nLightWarpTexture != -1) )
	{
		params[info.m_nLightWarpTexture]->SetUndefined();
	}
	if ( (mat_disable_fancy_blending.GetBool() ) &&
		 (info.m_nBlendModulateTexture != -1) )
	{
		params[info.m_nBlendModulateTexture]->SetUndefined();
	}

	if( !params[info.m_nEnvmapTint]->IsDefined() )
		params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f );

	if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() )
		params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 );

	if( !params[info.m_nSelfIllumTint]->IsDefined() )
		params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f );

	if( !params[info.m_nDetailScale]->IsDefined() )
		params[info.m_nDetailScale]->SetFloatValue( 4.0f );

	if ( !params[info.m_nDetailTint]->IsDefined() )
		params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );

	InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 );
	InitIntParam( info.m_nDetailTextureCombineMode, params, 0 );

	if( !params[info.m_nFresnelReflection]->IsDefined() )
		params[info.m_nFresnelReflection]->SetFloatValue( 1.0f );

	if( !params[info.m_nEnvmapMaskFrame]->IsDefined() )
		params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 );
	
	if( !params[info.m_nEnvmapFrame]->IsDefined() )
		params[info.m_nEnvmapFrame]->SetIntValue( 0 );

	if( !params[info.m_nBumpFrame]->IsDefined() )
		params[info.m_nBumpFrame]->SetIntValue( 0 );

	if( !params[info.m_nDetailFrame]->IsDefined() )
		params[info.m_nDetailFrame]->SetIntValue( 0 );

	if( !params[info.m_nEnvmapContrast]->IsDefined() )
		params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f );
	
	if( !params[info.m_nEnvmapSaturation]->IsDefined() )
		params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f );
	
	InitFloatParam( info.m_nAlphaTestReference, params, 0.0f );

	// No texture means no self-illum or env mask in base alpha
	if ( !params[info.m_nBaseTexture]->IsDefined() )
	{
		CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	if( params[info.m_nBumpmap]->IsDefined() )
	{
		params[info.m_nEnvmapMask]->SetUndefined();
	}
	
	// If in decal mode, no debug override...
	if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
	{
		SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
	}

	SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
	if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) )
	{
		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
	}

	// If mat_specular 0, then get rid of envmap
	if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() )
	{
		params[info.m_nEnvmap]->SetUndefined();
	}

	if( !params[info.m_nBaseTextureNoEnvmap]->IsDefined() )
	{
		params[info.m_nBaseTextureNoEnvmap]->SetIntValue( 0 );
	}
	if( !params[info.m_nBaseTexture2NoEnvmap]->IsDefined() )
	{
		params[info.m_nBaseTexture2NoEnvmap]->SetIntValue( 0 );
	}

	if( ( info.m_nSelfShadowedBumpFlag != -1 ) &&
		( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() )
		)
	{
		params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 );
	}
	// handle line art parms
	InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 );
	InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 );
	InitFloatParam( info.m_nOutlineAlpha, params, 1.0 );

    // Parallax cubemaps
    //cubemap parallax correction requires all 4 lines (if the 2nd, 3rd, or 4th are undef, undef the first one (checking done on first var)
    if (!(params[info.m_nEnvmapParallaxObb2]->IsDefined() && params[info.m_nEnvmapParallaxObb3]->IsDefined() && params[info.m_nEnvmapOrigin]->IsDefined()))
    {
        params[info.m_nEnvmapParallaxObb1]->SetUndefined();
    }
}
	// Set up anything that is necessary to make decisions in SHADER_FALLBACK.
	SHADER_INIT_PARAMS()
	{
		// FLASHLIGHTFIXME
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );

		// Write over $basetexture with $albedo if we are going to be using diffuse normal mapping.
		if( ShouldUseBumpmapping( params ) && params[ALBEDO]->IsDefined() &&
			params[BASETEXTURE]->IsDefined() && 
			!( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) )
		{
			params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() );
		}

		if( IsUsingGraphics() && params[ENVMAP]->IsDefined() && !CanUseEditorMaterials() )
		{
			if( stricmp( params[ENVMAP]->GetStringValue(), "env_cubemap" ) == 0 )
			{
				Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName );
				params[ENVMAP]->SetUndefined();
			}
		}
		
		if( !params[ENVMAPMASKSCALE]->IsDefined() )
		{
			params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );
		}

		if( !params[ENVMAPTINT]->IsDefined() )
		{
			params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
		}

		if( !params[SELFILLUMTINT]->IsDefined() )
		{
			params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
		}

		if( !params[DETAILSCALE]->IsDefined() )
		{
			params[DETAILSCALE]->SetFloatValue( 4.0f );
		}

		if( !params[DETAILBLENDFACTOR]->IsDefined() )
		{
			params[DETAILBLENDFACTOR]->SetFloatValue( 1.0f );
		}

		if( !params[FRESNELREFLECTION]->IsDefined() )
		{
			params[FRESNELREFLECTION]->SetFloatValue( 1.0f );
		}

		if( !params[ENVMAPMASKFRAME]->IsDefined() )
		{
			params[ENVMAPMASKFRAME]->SetIntValue( 0 );
		}
		
		if( !params[ENVMAPFRAME]->IsDefined() )
		{
			params[ENVMAPFRAME]->SetIntValue( 0 );
		}

		if( !params[BUMPFRAME]->IsDefined() )
		{
			params[BUMPFRAME]->SetIntValue( 0 );
		}

		if( !params[ENVMAPCONTRAST]->IsDefined() )
		{
			params[ENVMAPCONTRAST]->SetFloatValue( 0.0f );
		}
		
		if( !params[ENVMAPSATURATION]->IsDefined() )
		{
			params[ENVMAPSATURATION]->SetFloatValue( 1.0f );
		}

		if( !params[ALPHATESTREFERENCE]->IsDefined() )
		{
			params[ALPHATESTREFERENCE]->SetFloatValue( 0.0f );
		}

		// No texture means no self-illum or env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}

		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
		if( ShouldUseBumpmapping( params ) && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) )
		{
			SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
		}

		// Get rid of the envmap if it's optional for this dx level.
		if( params[ENVMAPOPTIONAL]->IsDefined() && (params[ENVMAPOPTIONAL]->GetIntValue() > g_pHardwareConfig->GetDXSupportLevel()) )
		{
			params[ENVMAP]->SetUndefined();
		}

		// If mat_specular 0, then get rid of envmap
		if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() )
		{
			params[ENVMAP]->SetUndefined();
		}

		if( params[SEAMLESS_SCALE]->IsDefined() && params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f )
		{
			if( params[BUMPMAP]->IsDefined() )
			{
				Warning( "Can't use $bumpmap with $seamless_scale for lightmappedgeneric_dx8.  Implicitly disabling $bumpmap: %s\n", pMaterialName );
				params[BUMPMAP]->SetUndefined();
			}
			if( params[ENVMAP]->IsDefined() )
			{
				Warning( "Can't use $envmap with $seamless_scale for lightmappedgeneric_dx8. Implicitly disabling $envmap: %s\n", pMaterialName );
				params[ENVMAP]->SetUndefined();
			}
		}

		if ( !params[SEAMLESS_SCALE]->IsDefined() )
		{
			// zero means don't do seamless mapping.
			params[SEAMLESS_SCALE]->SetFloatValue( 0.0f );
		}

		// Get rid of envmap if we aren't using bumpmapping 
		// *and* we have normalmapalphaenvmapmask *and* we don't have envmapmask elsewhere
		if ( params[ENVMAP]->IsDefined() && params[BUMPMAP]->IsDefined() && IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ) && !ShouldUseBumpmapping( params ) )
		{
			if ( !IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) && !params[ENVMAPMASK]->IsDefined() )
			{
				params[ENVMAP]->SetUndefined();
			}
		}
	}
//-----------------------------------------------------------------------------
// Initialize shader parameters
//-----------------------------------------------------------------------------
void InitParamsVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info )
{	
	Assert( info.m_nPhong >= 0 );
	Assert( info.m_nPhongExponent >= 0 );
	Assert( info.m_nPhongExponentTexture >= 0 );
	Assert( info.m_nLightWarpTexture >= 0 );
	Assert( info.m_nPhongBoost >= 0 );
	Assert( info.m_nPhongFresnelRanges >= 0 );

	if( !params[info.m_nPhong]->IsDefined() )
	{
		params[info.m_nPhong]->SetIntValue( 0 );
	}

	if( params[info.m_nPhong]->GetIntValue() != 0 )
	{
		if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
		{
			params[info.m_nPhong]->SetIntValue( 0 );
		}
		else
		{
			InitParamsSkin_DX9( pShader, params, pMaterialName, true, info );
			return;
		}
	}
	
	// FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
	Assert( info.m_nFlashlightTexture >= 0 );
	params[info.m_nFlashlightTexture]->SetStringValue( "effects/flashlight001" );
	
	// Write over $basetexture with $info.m_nBumpmap if we are going to be using diffuse normal mapping.
	if( info.m_nAlbedo != -1 && g_pConfig->UseBumpmapping() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() &&
		params[info.m_nBaseTexture]->IsDefined() )
	{
		params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() );
	}

	if( bVertexLitGeneric )
	{
		SET_FLAGS( MATERIAL_VAR_MODEL );
		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
	}
	else
	{
		CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
	}

	if( !params[info.m_nEnvmapMaskFrame]->IsDefined() )
	{
		params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 );
	}
	
	if( !params[info.m_nEnvmapTint]->IsDefined() )
	{
		params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f );
	}

	if( (info.m_nSelfIllumTint != -1) && (!params[info.m_nSelfIllumTint]->IsDefined()) )
	{
		params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f );
	}

	if( !params[info.m_nDetailScale]->IsDefined() )
	{
		params[info.m_nDetailScale]->SetFloatValue( 4.0f );
	}
	
	// With HDR, we don't support envmap contrast and saturation since they were
	// trying to emulate HDR effects.
	if( !params[info.m_nEnvmapContrast]->IsDefined())
	{
		params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f );
	}
	
	// With HDR, we don't support envmap contrast and saturation since they were
	// trying to emulate HDR effects.
	if( !params[info.m_nEnvmapSaturation]->IsDefined() )
	{
		params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f );
	}
	
	if( !params[info.m_nEnvmapFrame]->IsDefined() )
	{
		params[info.m_nEnvmapFrame]->SetIntValue( 0 );
	}

	if( (info.m_nBumpFrame != -1) && !params[info.m_nBumpFrame]->IsDefined() )
	{
		params[info.m_nBumpFrame]->SetIntValue( 0 );
	}

	// No texture means no self-illum or env mask in base alpha
	if ( !params[info.m_nBaseTexture]->IsDefined() )
	{
		CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	// If in decal mode, no debug override...
	if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
	{
		SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
	}

	if( ( (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() ) || params[info.m_nEnvmap]->IsDefined() )
	{
		SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
	}
	else
	{
		CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
	}

	bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
	if( hasNormalMapAlphaEnvmapMask )
	{
		params[info.m_nEnvmapMask]->SetUndefined();
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	if( IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ) && info.m_nBumpmap != -1 && 
		params[info.m_nBumpmap]->IsDefined() && !hasNormalMapAlphaEnvmapMask )
	{
		Warning( "material %s has a normal map and $basealphaenvmapmask.  Must use $normalmapalphaenvmapmask to get specular.\n\n", pMaterialName );
		params[info.m_nEnvmap]->SetUndefined();
	}
	
	if( params[info.m_nEnvmapMask]->IsDefined() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() )
	{
		params[info.m_nEnvmapMask]->SetUndefined();
		if( !hasNormalMapAlphaEnvmapMask )
		{
			Warning( "material %s has a normal map and an envmapmask.  Must use $normalmapalphaenvmapmask.\n\n", pMaterialName );
			params[info.m_nEnvmap]->SetUndefined();
		}
	}

	// If mat_specular 0, then get rid of envmap
	if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() )
	{
		params[info.m_nEnvmap]->SetUndefined();
	}

	if( ( info.m_nHDRColorScale != -1 ) && !params[info.m_nHDRColorScale]->IsDefined() )
	{
		params[info.m_nHDRColorScale]->SetFloatValue( 1.0f );
	}
}
void InitLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, LightmappedGeneric_DX9_Vars_t &info )
{
	if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpmap );
	}

	if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap2]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpmap2 );
	}

	if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpMask]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpMask );
	}

	if (params[info.m_nBaseTexture]->IsDefined())
	{
		pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );

		if (!params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent())
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}
	}

	if (params[info.m_nBaseTexture2]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nBaseTexture2, TEXTUREFLAGS_SRGB );
	}

	if (params[info.m_nLightWarpTexture]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nLightWarpTexture );
	}

	if ((info.m_nBlendModulateTexture != -1) &&
		(params[info.m_nBlendModulateTexture]->IsDefined()) )
	{
		pShader->LoadTexture( info.m_nBlendModulateTexture );
	}

	if (params[info.m_nDetail]->IsDefined())
	{
		int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue();
		nDetailBlendMode = nDetailBlendMode > 1 ? 1 : nDetailBlendMode;
		
		pShader->LoadTexture( info.m_nDetail, nDetailBlendMode != 0 ? TEXTUREFLAGS_SRGB : 0 );
	}

	pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
	
	// Don't alpha test if the alpha channel is used for other purposes
	if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
	{
		CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
	}
		
	if (params[info.m_nEnvmap]->IsDefined())
	{
		if ( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) )
		{
			pShader->LoadCubeMap( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 );
		}
		else
		{
			pShader->LoadTexture( info.m_nEnvmap );
		}

		if ( !g_pHardwareConfig->SupportsCubeMaps() )
		{
			SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE );
		}

		if ( params[info.m_nEnvmapMask]->IsDefined() )
		{
			pShader->LoadTexture( info.m_nEnvmapMask );
		}
	}
	else
	{
		params[info.m_nEnvmapMask]->SetUndefined();
	}

	// We always need this because of the flashlight.
	SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
}
//-----------------------------------------------------------------------------
// Initialize shader parameters
//-----------------------------------------------------------------------------
void InitParamsSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VertexLitGeneric_DX9_Vars_t &info )
{	
	// FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
	Assert( info.m_nFlashlightTexture >= 0 );

	if ( g_pHardwareConfig->SupportsBorderColor() )
	{
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
	}
	else
	{
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
	}
	
	// Write over $basetexture with $info.m_nBumpmap if we are going to be using diffuse normal mapping.
	if( info.m_nAlbedo != -1 && g_pConfig->UseBumpmapping() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() &&
		params[info.m_nBaseTexture]->IsDefined() )
	{
		params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() );
	}

	// This shader can be used with hw skinning
	SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
	SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );

	// No texture means no env mask in base alpha
	if ( !params[info.m_nBaseTexture]->IsDefined() )
	{
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	// If in decal mode, no debug override...
	if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
	{
		SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
	}

	// Lots of reasons to want tangent space, since we bind a flat normal map in many cases where we don't have a bump map
	bool bBump = (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined();
	bool bEnvMap = (info.m_nEnvmap != -1) && params[info.m_nEnvmap]->IsDefined();
	bool bDiffuseWarp = (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined();
	bool bPhong = (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined();
	if( bBump || bEnvMap || bDiffuseWarp || bPhong )
	{
		SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
	}
	else
	{
		CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
	}

	if ( ( info.m_nSelfIllumFresnel != -1 ) && ( !params[info.m_nSelfIllumFresnel]->IsDefined() ) )
	{
		params[info.m_nSelfIllumFresnel]->SetIntValue( 0 );
	}

	if ( ( info.m_nSelfIllumFresnelMinMaxExp != -1 ) && ( !params[info.m_nSelfIllumFresnelMinMaxExp]->IsDefined() ) )
	{
		params[info.m_nSelfIllumFresnelMinMaxExp]->SetVecValue( 0.0f, 1.0f, 1.0f );
	}

	if ( ( info.m_nBaseMapAlphaPhongMask != -1 ) && ( !params[info.m_nBaseMapAlphaPhongMask]->IsDefined() ) )
	{
		params[info.m_nBaseMapAlphaPhongMask]->SetIntValue( 0 );
	}

	if ( ( info.m_nEnvmapFresnel != -1 ) && ( !params[info.m_nEnvmapFresnel]->IsDefined() ) )
	{
		params[info.m_nEnvmapFresnel]->SetFloatValue( 0 );
	}
}
Beispiel #18
0
int
main (int argc, char** argv)
{
  char *kfile, *tfile, *cfile, *tafile, *lfile;
  size_t ksize, tsize, iter, depth;
 // FILE *kout, *tout;
  char opt;
  graph_t **gtrain; int* target;
  FILE* fileTrain, *fileResult, *fileTarget;
  core_t core;
  gtrain = NULL;
  lfile = tafile = cfile = kfile = NULL;
  depth = 3;
  CLEAR_FLAGS();
  SET_RUNNABLE();
  ksize = tsize = 0;
  core = TanimotoCore;
  while((opt = getopt(argc, argv, "mvihd:k:t:c:a:l:")) != -1) {
    switch(opt){
    case 'v':
      SET_VERBOSE();
      break;
    case 'i':
      SET_INFO();
      break;
    case 'd':
      depth = strtol((const char*) optarg, 0, 10);
      break;
    case 'k':
      SET_K_FILE();
      kfile = optarg;
      break;
    case 't':
      SET_T_FILE();
      tfile = optarg;
      break;      
    case 'c':
      SET_C_FILE();
      cfile = optarg;
      break;
    case 'a':
      SET_TA_FILE();
      tafile = optarg;
      break;
    case 'l':
      SET_L_FILE();
      lfile = optarg;
      break;
    case 'h':
      SET_HELP();
      break;
      
    case 'm':
      SET_PROVA_MINMAX();
      break;
      
    default:
      SET_HELP();
    }
  }
  if(HELP()) {
    usage();
    CLEAR_FLAGS();
  }
  if(INFO()) {
    info();
    CLEAR_FLAGS();
  }
  if(optind < argc) {
    if(!strcmp(argv[optind], "tanimoto")) {
      printf("tanimoto kernel\n");    	
    } else if(!strcmp(argv[optind], "minmax")) {
      printf("minmax kernel\n");
      core = MinMaxCore;
    } else
      printf("unavailable core ...\ndefault core: tanimoto\n");
  } //else
    //printf("default core: tanimoto\n");
  if(RUNNABLE()) {
    if(K_FILE() && T_FILE()) {
      if((fileTrain = fopen(kfile, "r")) && (fileTarget = fopen(tfile, "r"))) {
    	  gtrain = parse(fileTrain, &ksize);
    	  fclose(fileTrain);
    	  
    	  target=parseTarget(fileTarget, ksize);
    	  fclose(fileTarget);
    	  
    	  if(target==0)
    		  printf("\ncheck training file and target file");
    	  else
    		  FoldCrossValidation(core, gtrain, target, ksize, depth);

    	  for(iter = 0; iter < ksize; iter++)
    		  free_graph(gtrain[iter]);

    	  XFREE(gtrain);
    	  XFREE(target);  
      	}else fatal("unable to open training file");
    }
    
    if(TA_FILE() && C_FILE()) {
      fileResult = fopen(cfile, "r");
      fileTarget = fopen(tafile, "r");
      printf("\nAccuratezza: %f\n", getAccuracy(fileTarget, fileResult));
      fclose(fileResult);
      fclose(fileTarget);
    }
    /*
    if(L_FILE()) {
      file = fopen(lfile, "r");
      printf("\nLeaveOneOut: %f\n", getLeaveOneOut(file));
      fclose(file);
    }
    */

    if(K_FILE() && !T_FILE()) {
      if((fileTrain = fopen(kfile, "r"))) {
    	  gtrain = parse(fileTrain, &ksize);
    	  fclose(fileTrain);

    	print_graph(gtrain[0]);
    	print_graph(gtrain[1]);
    	  
    	  if(gtrain==0)
    		  printf("\ncheck training file");
    	  else
    		  WriteKernelMatrix(core, gtrain, ksize, depth);
    		  
    	  for(iter = 0; iter < ksize; iter++)
    		  free_graph(gtrain[iter]);

    	  XFREE(gtrain);  
      	}else fatal("unable to open training file");
    }
    
    if(PROVA_MINMAX()) {
    	printf("\nPROVA MIN MAX\n");
    	
    	fileTrain = fopen("./minmax.mol2", "r");
    	gtrain = parse(fileTrain, &ksize);
    	//print_graph(gtrain[0]);
    	//print_graph(gtrain[1]);
    	
    	print_graph(gtrain[0]);
    	print_graph(gtrain[1]);
    	
    	printf("\nMinMax: %f", MinMaxCore(gtrain[0], gtrain[1], 3));
    	//printf("\nTanimoto: %f", TanimotoCore(gtrain[0], gtrain[1], 3));
    	
    	fclose(fileTrain);
     }

    
  } //else usage();
  return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------
// Initialize shader
//-----------------------------------------------------------------------------
void InitSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, VertexLitGeneric_DX9_Vars_t &info )
{
	Assert( info.m_nFlashlightTexture >= 0 );
	pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
	
	bool bIsBaseTextureTranslucent = false;
	if ( params[info.m_nBaseTexture]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
		
		if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
		{
			bIsBaseTextureTranslucent = true;
		}

		if ( ( info.m_nWrinkle != -1 ) && ( info.m_nStretch != -1 ) &&
			params[info.m_nWrinkle]->IsDefined() && params[info.m_nStretch]->IsDefined() )
		{
			pShader->LoadTexture( info.m_nWrinkle, TEXTUREFLAGS_SRGB );
			pShader->LoadTexture( info.m_nStretch, TEXTUREFLAGS_SRGB );
		}
	}

	bool bHasSelfIllumMask = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && (info.m_nSelfIllumMask != -1) && params[info.m_nSelfIllumMask]->IsDefined();

	// No alpha channel in any of the textures? No self illum or envmapmask
	if ( !bIsBaseTextureTranslucent )
	{
		bool bHasSelfIllumFresnel = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && ( info.m_nSelfIllumFresnel != -1 ) && ( params[info.m_nSelfIllumFresnel]->GetIntValue() != 0 );

		// Can still be self illum with no base alpha if using one of these alternate modes
		if ( !bHasSelfIllumFresnel && !bHasSelfIllumMask )
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
		}

		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	if ( (info.m_nPhongExponentTexture != -1) && params[info.m_nPhongExponentTexture]->IsDefined() &&
		 (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nPhongExponentTexture );
	}

	if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() &&
		 (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nDiffuseWarpTexture );
	}

	if ( (info.m_nPhongWarpTexture != -1) && params[info.m_nPhongWarpTexture]->IsDefined() &&
		 (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nPhongWarpTexture );
	}

	if ( info.m_nDetail != -1 && params[info.m_nDetail]->IsDefined() )
	{
		int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue();
		if ( nDetailBlendMode == 0 ) // Mod2X
			pShader->LoadTexture( info.m_nDetail );
		else
			pShader->LoadTexture( info.m_nDetail, TEXTUREFLAGS_SRGB );
	}

	if ( g_pConfig->UseBumpmapping() )
	{
		if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
		{
			pShader->LoadBumpMap( info.m_nBumpmap );
			SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL );

			if ( ( info.m_nNormalWrinkle != -1 ) && ( info.m_nNormalStretch != -1 ) &&
				params[info.m_nNormalWrinkle]->IsDefined() && params[info.m_nNormalStretch]->IsDefined() )
			{
				pShader->LoadTexture( info.m_nNormalWrinkle );
				pShader->LoadTexture( info.m_nNormalStretch );
			}
		}
	}
	
	if ( params[info.m_nEnvmap]->IsDefined() )
	{
		pShader->LoadCubeMap( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0  );
	}

	if ( bHasSelfIllumMask )
	{
		pShader->LoadTexture( info.m_nSelfIllumMask );
	}
}
Beispiel #20
0
extern t_account * account_create(char const * username, char const * passhash1)
{
    t_account * account;

    if (username && account_check_name(username)<0)
    {
        eventlog(eventlog_level_error,"account_create","got bad account name");
        return NULL;
    }

    if (!(account = malloc(sizeof(t_account))))
    {
		eventlog(eventlog_level_error,"account_create","could not allocate memory for account");
		return NULL;
    }

    account->filename = NULL;
    account->attrs    = NULL;
    account->age      = 0;
    CLEAR_FLAGS(account);

    account->namehash = 0; /* hash it later before inserting */
#ifndef ACCT_DYN_LOAD
    account->uid      = 0;
#endif /* !ACCT_DYN_LOAD */
#ifdef ACCT_DYN_UNLOAD
    account->ref      = 0;
#endif /* ACCT_DYN_UNLOAD */


    if (username) /* actually making a new account */
    {
        char * temp;

		if (account_check_name(username)<0)
		{
	    	eventlog(eventlog_level_error,"account_create","invalid account name \"%s\"",username);
		    account_destroy(account);
		    return NULL;
		}
		if (!passhash1)
		{
            eventlog(eventlog_level_error,"account_create","got NULL passhash1");
            account_destroy(account);
            return NULL;
		}

#ifdef WITH_STORAGE_DB
	    /* In DB (MySQL) storage i always use the real login name as id */
	    if (!(temp = malloc(strlen(username)+1))) /* name + NUL */
	    {
	        eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
	        account_destroy(account);
	        return NULL;
	    }
	    sprintf(temp,"%s",username);
#else
# ifndef ACCT_DYN_LOAD
		if (prefs_get_savebyname()==0)
		{
	        if (!(temp = malloc(strlen(prefs_get_userdir())+1+8+1))) /* dir + / + uid + NUL */
	        {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
				account_destroy(account);
				return NULL;
		    }
		    sprintf(temp,"%s/%06u",prefs_get_userdir(),maxuserid+1); /* FIXME: hmm, maybe up the %06 to %08... */
		}
		else
# endif /* ! ACCT_DYN_LOAD */
		{
		    char const * safename;
		    char *	 filename;

		    if (!(filename = strdup(username)))
		    {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for filename");
				account_destroy(account);
				return NULL;
		    }
		    str_to_lower(filename);
		    if (!(safename = escape_fs_chars(filename,strlen(filename))))
		    {
				eventlog(eventlog_level_error,"account_create","could not escape username");
				account_destroy(account);
				free(filename);
				return NULL;
		    }
		    free(filename);
		    if (!(temp = malloc(strlen(prefs_get_userdir())+1+strlen(safename)+1))) /* dir + / + name + NUL */
		    {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
				account_destroy(account);
				return NULL;
		    }
		    sprintf(temp,"%s/%s",prefs_get_userdir(),safename);
		    free((void *)safename); /* avoid warning */
		}
#endif /* WITH_DB_STORAGE */
		account->filename = temp;

	    SET_FLAG(account,account_flag_loaded);

		if (account_set_strattr(account,"BNET\\acct\\username",username)<0)
		{
	    	eventlog(eventlog_level_error,"account_create","could not set username");
		    account_destroy(account);
		    return NULL;
		}
#ifndef ACCT_DYN_LOAD
		if (account_set_numattr(account,"BNET\\acct\\userid",maxuserid+1)<0)
		{
		    eventlog(eventlog_level_error,"account_create","could not set userid");
		    account_destroy(account);
		    return NULL;
		}
#endif /* !ACCT_DYN_LOAD */
		if (account_set_strattr(account,"BNET\\acct\\passhash1",passhash1)<0)
		{
		    eventlog(eventlog_level_error,"account_create","could not set passhash1");
		    account_destroy(account);
		    return NULL;
		}

#ifdef WITH_BITS
		account_set_bits_state(account,account_state_valid);
		if (!bits_master) {
		    eventlog(eventlog_level_warn,"account_create","account_create should not be called on BITS clients");
		}
#endif /* WITH_BITS */
    }
#ifdef WITH_BITS
    else /* empty account to be filled in later */
		account_set_bits_state(account,account_state_valid);
#endif /* WITH_BITS */

    return account;
}
	END_SHADER_PARAMS

	SHADER_INIT_PARAMS()
	{
		// FLASHLIGHTFIXME
		params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );

		// We don't want no stinking bump mapping on models in dx8.
		// Wait a minute!  We want specular bump. .need to make that work by itself.
//		params[BUMPMAP]->SetUndefined();
//		if( IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ) )
//		{
//			CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
//			params[ENVMAP]->SetUndefined();
//		}
		// default to 'MODEL' mode...
		if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ))
			SET_FLAGS( MATERIAL_VAR_MODEL );

		if( !params[ENVMAPMASKSCALE]->IsDefined() )
			params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );

		if( !params[ENVMAPMASKFRAME]->IsDefined() )
			params[ENVMAPMASKFRAME]->SetIntValue( 0 );
		
		if( !params[ENVMAPTINT]->IsDefined() )
			params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );

		if( !params[SELFILLUMTINT]->IsDefined() )
			params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );

		if( !params[DETAILSCALE]->IsDefined() )
			params[DETAILSCALE]->SetFloatValue( 4.0f );

		if( !params[ENVMAPCONTRAST]->IsDefined() )
			params[ENVMAPCONTRAST]->SetFloatValue( 0.0f );
		
		if( !params[ENVMAPSATURATION]->IsDefined() )
			params[ENVMAPSATURATION]->SetFloatValue( 1.0f );
		
		if( !params[ENVMAPFRAME]->IsDefined() )
			params[ENVMAPFRAME]->SetIntValue( 0 );

		if( !params[BUMPFRAME]->IsDefined() )
			params[BUMPFRAME]->SetIntValue( 0 );

		// No texture means no self-illum or env mask in base alpha
		if ( !params[BASETEXTURE]->IsDefined() )
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}

		// If in decal mode, no debug override...
		if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
		{
			SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
		}

		// Force software skinning if the file says so
		if (!IS_FLAG_SET(MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING))
		{
#ifdef DIFFUSE_BUMP_ON_DX8
			// Software skin if diffuse bump mapping is used at all.
			if( g_pConfig->bBumpmap && 
				( ( params[BASETEXTURE]->IsDefined() && params[BUMPMAP]->IsDefined() ) ||
				  ( params[BUMPMAP]->IsDefined() && !params[ENVMAP]->IsDefined() ) ) )
			{
				SET_FLAGS( MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING );
			}
#endif
		}

		if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() )
		{
			SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
		}
		
		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );

		if( !params[DETAIL]->IsDefined() && !params[BUMPMAP]->IsDefined() )
		{
			SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_TEXKILL );
		}

		// Get rid of the envmap if it's optional for this dx level.
		if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() )
		{
			params[ENVMAP]->SetUndefined();
		}

		// If mat_specular 0, then get rid of envmap
		if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() )
		{
			params[ENVMAP]->SetUndefined();
		}
	}
void InitLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, LightmappedGeneric_DX9_Vars_t &info )
{
	bool hasNormalMapAlphaEnvmapMask = g_pConfig->UseSpecular() && IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );

	if ( ( g_pConfig->UseBumpmapping() || hasNormalMapAlphaEnvmapMask ) && params[info.m_nBumpmap]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpmap );
	}

	if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap2]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpmap2 );
	}

	if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpMask]->IsDefined() )
	{
		pShader->LoadBumpMap( info.m_nBumpMask );
	}

	if (params[info.m_nBaseTexture]->IsDefined())
	{
		pShader->LoadTexture( info.m_nBaseTexture );

		if (!params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent())
		{
			CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
			CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
		}
	}

	if (params[info.m_nBaseTexture2]->IsDefined() )
	{
		pShader->LoadTexture( info.m_nBaseTexture2 );
	}

	if ((info.m_nBlendModulateTexture != -1) &&
		(params[info.m_nBlendModulateTexture]->IsDefined()) )
	{
		pShader->LoadTexture( info.m_nBlendModulateTexture );
	}

	if (params[info.m_nDetail]->IsDefined())
	{
		int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue();
		nDetailBlendMode = nDetailBlendMode > 1 ? 1 : nDetailBlendMode;

		if ( nDetailBlendMode == 0 ) //Mod2X
			pShader->LoadTexture( info.m_nDetail );
		else
			pShader->LoadTexture( info.m_nDetail );
	}

	pShader->LoadTexture( info.m_nFlashlightTexture );
	
	// Don't alpha test if the alpha channel is used for other purposes
	if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
	{
		CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
	}
		
	if ( g_pConfig->UseSpecular() )
	{
		if ( params[info.m_nEnvmap]->IsDefined() )
		{
			pShader->LoadCubeMap( info.m_nEnvmap );

			if (params[info.m_nEnvmapMask]->IsDefined())
			{
				pShader->LoadTexture( info.m_nEnvmapMask );
			}
		}
		else
		{
			params[info.m_nEnvmapMask]->SetUndefined();
		}
	}
	else
	{
		params[info.m_nEnvmap]->SetUndefined();
		params[info.m_nEnvmapMask]->SetUndefined();
	}

	// We always need this because of the flashlight.
	SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );

	if( IS_PARAM_DEFINED( info.m_nPaintSplatNormal ) )
	{
		pShader->LoadBumpMap( info.m_nPaintSplatNormal );
	}

	if( IS_PARAM_DEFINED( info.m_nPaintSplatEnvMap ) )
	{
		pShader->LoadCubeMap( info.m_nPaintSplatEnvMap );
	}

	if ( IS_PARAM_DEFINED( info.m_nFoW ) )
	{
		pShader->LoadTexture( info.m_nFoW );
	}
}
void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info )
{
	// Override vertex fog via the global setting if it isn't enabled/disabled in the material file.
	if ( !IS_FLAG_DEFINED( MATERIAL_VAR_VERTEXFOG ) && mat_force_vertexfog.GetBool() )
	{
		SET_FLAGS( MATERIAL_VAR_VERTEXFOG );
	}

	params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );

	// Write over $basetexture with $albedo if we are going to be using diffuse normal mapping.
	if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() &&
		params[info.m_nBaseTexture]->IsDefined() && 
		!( params[info.m_nNoDiffuseBumpLighting]->IsDefined() && params[info.m_nNoDiffuseBumpLighting]->GetIntValue() ) )
	{
		params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() );
	}

	if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() )
	{
		if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 )
		{
			Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName );
			params[info.m_nEnvmap]->SetUndefined();
		}
	}
	
	if ( (mat_disable_lightwarp.GetBool() ) &&
		 (info.m_nLightWarpTexture != -1) )
	{
		params[info.m_nLightWarpTexture]->SetUndefined();
	}
	if ( (mat_disable_fancy_blending.GetBool() ) &&
		 (info.m_nBlendModulateTexture != -1) )
	{
		params[info.m_nBlendModulateTexture]->SetUndefined();
	}

	if( !params[info.m_nEnvmapTint]->IsDefined() )
		params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f );

	if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() )
		params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 );

	if( !params[info.m_nSelfIllumTint]->IsDefined() )
		params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f );

	if( !params[info.m_nDetailScale]->IsDefined() )
		params[info.m_nDetailScale]->SetFloatValue( 4.0f );

	if ( !params[info.m_nDetailTint]->IsDefined() )
		params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );

	InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 );
	InitIntParam( info.m_nDetailTextureCombineMode, params, 0 );

	if( !params[info.m_nFresnelReflection]->IsDefined() )
		params[info.m_nFresnelReflection]->SetFloatValue( 1.0f );

	if( !params[info.m_nEnvmapMaskFrame]->IsDefined() )
		params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 );
	
	if( !params[info.m_nEnvmapFrame]->IsDefined() )
		params[info.m_nEnvmapFrame]->SetIntValue( 0 );

	if( !params[info.m_nBumpFrame]->IsDefined() )
		params[info.m_nBumpFrame]->SetIntValue( 0 );

	if( !params[info.m_nDetailFrame]->IsDefined() )
		params[info.m_nDetailFrame]->SetIntValue( 0 );

	if( !params[info.m_nEnvmapContrast]->IsDefined() )
		params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f );
	
	if( !params[info.m_nEnvmapSaturation]->IsDefined() )
		params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f );
	
	InitFloatParam( info.m_nAlphaTestReference, params, 0.0f );

	// No texture means no self-illum or env mask in base alpha
	if ( !params[info.m_nBaseTexture]->IsDefined() )
	{
		CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
		CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
	}

	if( params[info.m_nBumpmap]->IsDefined() )
	{
		params[info.m_nEnvmapMask]->SetUndefined();
	}
	
	// If in decal mode, no debug override...
	if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
	{
		SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
	}

	SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
	if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) )
	{
		SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
	}

	// If mat_specular 0, then get rid of envmap
	if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() )
	{
		params[info.m_nEnvmap]->SetUndefined();
	}

	if( !params[info.m_nBaseTextureNoEnvmap]->IsDefined() )
	{
		params[info.m_nBaseTextureNoEnvmap]->SetIntValue( 0 );
	}
	if( !params[info.m_nBaseTexture2NoEnvmap]->IsDefined() )
	{
		params[info.m_nBaseTexture2NoEnvmap]->SetIntValue( 0 );
	}

	if( ( info.m_nSelfShadowedBumpFlag != -1 ) &&
		( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() )
		)
	{
		params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 );
	}
	// handle line art parms
	InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 );
	InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 );
	InitFloatParam( info.m_nOutlineAlpha, params, 1.0 );

	// parallax mapping
	InitFloatParam( info.m_nHeightScale, params, 0.1 );

	// srgb read 360
	InitIntParam( info.m_nShaderSrgbRead360, params, 0 );

	InitFloatParam( info.m_nEnvMapLightScale, params, 0.0f );

	SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nFoW, "_rt_fog_of_war" );

	if ( g_pConfig->m_bPaintInGame )
	{
		if( info.m_nPaintSplatNormal != -1 )
		{
			if( !params[info.m_nPaintSplatNormal]->IsDefined() )
			{
				params[info.m_nPaintSplatNormal]->SetStringValue( "paint/splatnormal_default" );
			}
		}
		
		if( info.m_nPaintSplatEnvMap != -1 )
		{
			if( !params[info.m_nPaintSplatEnvMap]->IsDefined() )
			{
				if( params[info.m_nEnvmap]->IsDefined() )
				{
					params[info.m_nPaintSplatEnvMap]->SetStringValue( params[info.m_nEnvmap]->GetStringValue() );
				}
				else
				{
					params[info.m_nPaintSplatEnvMap]->SetStringValue( "env_cubemap" );
				}
			}
		}
	}
	else
	{
		if( info.m_nPaintSplatNormal != -1 )
		{
			params[info.m_nPaintSplatNormal]->SetUndefined();
		}

		if( info.m_nPaintSplatEnvMap != -1 )
		{
			params[info.m_nPaintSplatEnvMap]->SetUndefined();
		}
	}
}