bool CNodeStdVLight::CreateSolvers(GenericShaderData *ShaderData)
{
    if ( GetNumJacks_In_Connected() < GetNumJacks_In() )
        return false;

    CJack *pJ_Out = GetJack_Out( 0 );
    const int res = pJ_Out->GetResourceType();

    CHLSL_Var *tg = GetInputToWriteTo( pJ_Out->GetSmartType() );
    SetAllocating( !tg );
    if ( !tg )
        tg = pJ_Out->AllocateVarFromSmartType();
    pJ_Out->SetTemporaryVarTarget( tg );

    CHLSL_Solver_StdVLight *solver = new CHLSL_Solver_StdVLight( GetUniqueIndex() );
    solver->SetResourceType( res );
    solver->SetState( m_bStaticLighting, m_bHalfLambert );

    for ( int i = 0; i < GetNumJacks_In(); i++ )
        solver->AddSourceVar( GetJack_In(i)->GetTemporaryVarTarget_End() );

    solver->AddTargetVar( tg );
    AddSolver( solver );

    return true;
}
bool CNodeDot::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < 2 )
		return false;

	CJack *pJ1 = GetJack_In( 0 );
	CJack *pJ2 = GetJack_In( 1 );
	CJack *pJ_Out = GetJack_Out( 0 );

	int type0 = pJ_Out->GetSmartType();
	const int res = pJ_Out->GetResourceType();

	if ( pJ2->GetSmartType() == HLSLVAR_FLOAT1 )
		swap( pJ1, pJ2 );

	CHLSL_Var *tg = GetInputToWriteTo( type0 );
	SetAllocating( !tg );
	if ( !tg )
		tg = pJ_Out->AllocateVarFromSmartType();
	pJ_Out->SetTemporaryVarTarget( tg );

	CHLSL_Solver_Dot *solver = new CHLSL_Solver_Dot( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddSourceVar( pJ1->GetTemporaryVarTarget_End() );
	solver->AddSourceVar( pJ2->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	//Msg("add solver has %i src vars\n", solver->GetNumSourceVars());

	return true;
}
bool CNodeSubtract::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < 2 )
		return false;

	CJack *pJ1 = GetJack_In( 0 );
	CJack *pJ2 = GetJack_In( 1 );
	CJack *pJ_Out = GetJack_Out( 0 );

	int type1 = pJ1->GetSmartType();
	int type2 = pJ2->GetSmartType();
	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = GetInputToWriteTo( max( type1, type2 ) );
	SetAllocating( !tg );
	if ( !tg )
		tg = pJ_Out->AllocateVarFromSmartType();
	pJ_Out->SetTemporaryVarTarget( tg );

	CHLSL_Solver_Subtract *solver = new CHLSL_Solver_Subtract( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddSourceVar( pJ1->GetTemporaryVarTarget_End() );
	solver->AddSourceVar( pJ2->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	return true;
}
bool CNodeLightscale::CreateSolvers(GenericShaderData *ShaderData)
{
    CJack *pJ_Out = GetJack_Out( 0 );
    const int res = pJ_Out->GetResourceType();

    SetAllocating( false );
    CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();
    tg->MakeConstantOnly();

    CHLSL_Solver_Lightscale *solver = new CHLSL_Solver_Lightscale( GetUniqueIndex() );
    solver->SetResourceType( res );
    solver->AddTargetVar( tg );
    solver->SetState( m_iLightScale );
    AddSolver( solver );
    return true;
}
bool CNodeRandom::CreateSolvers(GenericShaderData *ShaderData)
{
	CJack *pJ_Out = GetJack_Out( 0 );
	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();
	tg->MakeConstantOnly();

	CHLSL_Solver_Random *solver = new CHLSL_Solver_Random( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddTargetVar( tg );
	solver->SetState( m_iNumComponents, m_flValue_Min, m_flValue_Max );
	AddSolver( solver );

	return true;
}
bool CNodeStdMorph::CreateSolvers(GenericShaderData *ShaderData)
{
	const int numJacksIn = GetNumJacks_In();
	if ( GetNumJacks_In_Connected() < numJacksIn )
		return false;

#define __ALLOCVARONOVERWRITEFAIL( _in, _out ) CHLSL_Var *tg##_out = NULL;\
	if ( _in + 1 > GetNumJacks_In() || _out + 1 > GetNumJacks_Out() )\
	{}\
	else if ( GetJack_In( _in )->GetTemporaryVarTarget_End()->CanBeOverwritten() )\
	{\
		tg##_out = GetJack_In( _in )->GetTemporaryVarTarget_End();\
		GetJack_Out( _out )->SetTemporaryVarTarget( tg##_out );\
	}\
	else\
	{\
		tg##_out = GetJack_Out( _out )->AllocateVarFromSmartType();\
	}

	bool bWillAlloc = !GetJack_In( 0 )->GetTemporaryVarTarget_End()->CanBeOverwritten();
	if ( m_iSkinMode >= STD_SKINNING_MODE_POS_NORMAL && !GetJack_In( 2 )->GetTemporaryVarTarget_End()->CanBeOverwritten() )
		bWillAlloc = true;
	if ( m_iSkinMode >= STD_SKINNING_MODE_POS_NORMAL_TANGENT && !GetJack_In( 4 )->GetTemporaryVarTarget_End()->CanBeOverwritten() )
		bWillAlloc = true;

	SetAllocating( bWillAlloc );

	CHLSL_Solver_StdMorph *solver = new CHLSL_Solver_StdMorph( GetUniqueIndex() );

	solver->SetState( m_iSkinMode );
	for ( int i = 0; i < numJacksIn; i++ )
		solver->AddSourceVar( GetJack_In(i)->GetTemporaryVarTarget_End() );

	__ALLOCVARONOVERWRITEFAIL( 0, 0 )
	__ALLOCVARONOVERWRITEFAIL( 2, 1 )
	__ALLOCVARONOVERWRITEFAIL( 4, 2 )

	solver->AddTargetVar( tg0 );
	if ( m_iSkinMode >= STD_SKINNING_MODE_POS_NORMAL )
		solver->AddTargetVar( tg1 );
	if ( m_iSkinMode >= STD_SKINNING_MODE_POS_NORMAL_TANGENT )
		solver->AddTargetVar( tg2 );

	AddSolver( solver );

	return true;
}
bool CNodeConstant::CreateSolvers(GenericShaderData *ShaderData)
{
	CJack *pJ_Out = GetJack_Out( 0 );

	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();
	tg->MakeConstantOnly();

	CHLSL_Solver_Constant *solver = new CHLSL_Solver_Constant( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddTargetVar( tg );
	solver->SetComponentInfo( m_iChannelInfo );
	AddSolver( solver );

	return true;
}
bool CNodeCustom::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < GetNumJacks_In() )
		return false;

	Assert( m_pCode_Function && Q_strlen( m_pCode_Function ) );
	Assert( m_bInline || Q_strlen(m_szFilePath) );

	SetAllocating( true );

	char *pszFuncString = CKVPacker::ConvertKVSafeString( m_pCode_Function, false );
	char *pszGlobalString = CKVPacker::ConvertKVSafeString( m_pCode_Global, false );

	int iHierachyType = GetHierachyTypeIterateFullyRecursive();
	int envflags = m_iEnvFlags;
	if ( iHierachyType & HLSLHIERACHY_PS )
		envflags &= ~NODECUSTOM_ADDENV_LIGHTING_VS;

	if ( iHierachyType & HLSLHIERACHY_VS )
		envflags &= ~NODECUSTOM_ADDENV_LIGHTING_PS;

	CHLSL_Solver_Custom *solver = new CHLSL_Solver_Custom( GetUniqueIndex() );
	solver->SetResourceType( RESOURCETYPE_VARIABLE );
	solver->Init( pszGlobalString, pszFuncString, envflags,
		m_szFunctionName, m_szFilePath,
		m_hszVarNames_In, m_hszVarNames_Out,
		this );

	delete [] pszFuncString;
	delete [] pszGlobalString;

	for ( int i = 0; i < GetNumJacks_In(); i++ )
		solver->AddSourceVar( GetJack_In( i )->GetTemporaryVarTarget_End() );

	for ( int i = 0; i < GetNumJacks_Out(); i++ )
	{
		CJack *pJ = GetJack_Out( i );
		CHLSL_Var *pTg = pJ->AllocateVarFromSmartType();
		solver->AddTargetVar( pTg );
	}

	AddSolver( solver );

	return true;
}
bool CNodeBreak::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_Out() != GetNumJacks_In() )
		return false;

	CHLSL_Solver_Break *solver = new CHLSL_Solver_Break( GetUniqueIndex() );

	for ( int i = 0; i < GetNumJacks_In(); i++ )
	{
		CJack *pJ_In = GetJack_In( i );
		if ( pJ_In->GetNumBridgesConnected() < 1 )
			break;
		GetJack_Out( i )->SetTemporaryVarTarget( pJ_In->GetTemporaryVarTarget_End() );
	}

	AddSolver( solver );
	return true;
}
bool CNodeClip::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < GetNumJacks_In() )
		return false;

	CJack *pJ_In_0 = GetJack_In( 0 );
	CJack *pJ_Out_0 = GetJack_Out( 0 );

	CHLSL_Var *pt = pJ_In_0->GetTemporaryVarTarget_End();

	pJ_Out_0->SetTemporaryVarTarget( pt );

	CHLSL_Solver_Clip *solver = new CHLSL_Solver_Clip( GetUniqueIndex() );
	solver->AddSourceVar( pt );
	solver->AddTargetVar( pt );
	AddSolver( solver );
	return true;
}
Example #11
0
void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags)
{
	if (!tex->isHardwareCanvas())
	{
		if (translation <= 0)
		{
			translation = -translation;
		}
		else
		{
			auto remap = TranslationToTable(translation);
			translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
		}

		FTextureBuffer texbuffer = tex->CreateTexBuffer(translation, flags | CTF_ProcessData);
		CreateTexture(texbuffer.mWidth, texbuffer.mHeight, 4, VK_FORMAT_B8G8R8A8_UNORM, texbuffer.mBuffer);
	}
	else
	{
		auto fb = GetVulkanFrameBuffer();

		VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
		int w = tex->GetWidth();
		int h = tex->GetHeight();

		ImageBuilder imgbuilder;
		imgbuilder.setFormat(format);
		imgbuilder.setSize(w, h);
		imgbuilder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
		mImage.Image = imgbuilder.create(fb->device);
		mImage.Image->SetDebugName("VkHardwareTexture.mImage");

		ImageViewBuilder viewbuilder;
		viewbuilder.setImage(mImage.Image.get(), format);
		mImage.View = viewbuilder.create(fb->device);
		mImage.View->SetDebugName("VkHardwareTexture.mImageView");

		auto cmdbuffer = fb->GetTransferCommands();

		VkImageTransition imageTransition;
		imageTransition.addImage(&mImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, true);
		imageTransition.execute(cmdbuffer);
	}
}
bool CNodeStdSkinning::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < GetNumJacks_In() )
		return false;

	SetAllocating( true );

	CHLSL_Solver_StdSkinning *solver = new CHLSL_Solver_StdSkinning( GetUniqueIndex() );

	solver->SetState( m_iSkinMode );
	for ( int i = 0; i < GetNumJacks_In(); i++ )
		solver->AddSourceVar( GetJack_In(i)->GetTemporaryVarTarget_End() );
	for ( int i = 0; i < GetNumJacks_Out(); i++ )
		solver->AddTargetVar( GetJack_Out(i)->AllocateVarFromSmartType() );

	AddSolver( solver );

	return true;
}
bool CNodeMultiply::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < 2 )
		return false;

	CJack *pJ1 = GetJack_In( 0 );
	CJack *pJ2 = GetJack_In( 1 );
	CJack *pJ_Out = GetJack_Out( 0 );

	int type1 = pJ1->GetSmartType();
	int type2 = pJ2->GetSmartType();
	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = NULL;
	
	if ( type1 == type2 || type1 == HLSLVAR_FLOAT1 || type2 == HLSLVAR_FLOAT1 )
		tg = GetInputToWriteTo( max( type1, type2 ) );
	else if ( type1 == HLSLVAR_FLOAT3 && type2 == HLSLVAR_MATRIX3X3 )
		tg = GetInputToWriteTo( HLSLVAR_FLOAT3 );
	else if ( type1 == HLSLVAR_FLOAT3 && type2 == HLSLVAR_MATRIX4X3 )
		tg = GetInputToWriteTo( HLSLVAR_FLOAT3 );
	else if ( type1 == HLSLVAR_FLOAT4 && type2 == HLSLVAR_MATRIX4X4 )
		tg = GetInputToWriteTo( HLSLVAR_FLOAT4 );
	else if ( type1 == HLSLVAR_MATRIX3X3 && type2 == HLSLVAR_FLOAT3 )
		tg = GetInputToWriteTo( HLSLVAR_FLOAT3 );

	SetAllocating( !tg );
	if ( !tg )
		tg = pJ_Out->AllocateVarFromSmartType();
	pJ_Out->SetTemporaryVarTarget( tg );

	CHLSL_Solver_Multiply *solver = new CHLSL_Solver_Multiply( GetUniqueIndex() );
	solver->SetMatrixRotationOnly( m_bMatrixRotation );
	solver->SetResourceType( res );
	solver->AddSourceVar( pJ1->GetTemporaryVarTarget_End() );
	solver->AddSourceVar( pJ2->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	//Msg("add solver has %i src vars\n", solver->GetNumSourceVars());

	return true;
}
bool CNodeVCompression::CreateSolvers(GenericShaderData *ShaderData)
{
	const bool bUseTangent = m_iCompressionMode == COMPRESSION_MODE_NORMAL_TANGENT;

	SetAllocating( true );
	CHLSL_Solver_VCompression *solver =  new CHLSL_Solver_VCompression( GetUniqueIndex() );
	solver->SetCompressionType( m_iCompressionMode );

	solver->AddSourceVar( GetJack_In(0)->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( GetJack_Out(0)->AllocateVarFromSmartType() );

	if ( bUseTangent )
	{
		solver->AddSourceVar( GetJack_In(1)->GetTemporaryVarTarget_End() );
		solver->AddTargetVar( GetJack_Out(1)->AllocateVarFromSmartType() );
	}

	AddSolver( solver );
	return true;
}
bool CNodeUtility_Declare::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < 1 )
		return false;

	CJack *pJ1 = GetJack_In( 0 );
	CJack *pJ_Out = GetJack_Out( 0 );

	const int res = pJ_Out->GetResourceType();

	SetAllocating( true );
	CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();

	CHLSL_Solver_Utility_Declare *solver = new CHLSL_Solver_Utility_Declare( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddSourceVar( pJ1->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	return true;
}
bool CNodeVSInput::CreateSolvers(GenericShaderData *ShaderData)
{
	for ( int i = 0; i < GetNumJacks_Out(); i++ )
	{
		CJack *pJ = GetJack_Out( i );
		if ( !pJ->GetNumBridgesConnected() )
			continue;

		const int res = pJ->GetResourceType();
		CHLSL_Var *var = pJ->AllocateVarFromSmartType();
		var->MakeConstantOnly();

		CHLSL_Solver_ReadSemantics *solver = new CHLSL_Solver_ReadSemantics( GetUniqueIndex() );
		solver->SendVSSetup( curSetup );
		solver->SetResourceType( res );
		solver->AddTargetVar( var );
		AddSolver( solver );
	}

	SmartCreateDummySolver();
	return true;
}
bool CNodeMCompose::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < GetNumJacks_In() )
		return false;

	CJack *pJ_Out = GetJack_Out( 0 );

	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();
	SetAllocating( true );

	CHLSL_Solver_MComp *solver = new CHLSL_Solver_MComp( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->SetState( iTargetMatrix, bColumns );
	for ( int i = 0; i < GetNumJacks_In(); i++ )
		solver->AddSourceVar( GetJack_In(i)->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	return true;
}
bool CNodeUtility_Assign::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( GetNumJacks_In_Connected() < 2 )
		return false;

	CJack *pJ1 = GetJack_In( 0 );
	CJack *pJ2 = GetJack_In( 1 );
	CJack *pJ_Out = GetJack_Out( 0 );
	if ( !pJ1->GetTemporaryVarTarget_End()->CanBeOverwritten() )
	{
		SetOutputsUndefined();
		OnShowSolverErrored();
		return false;
	}


	const int res = pJ_Out->GetResourceType();

	CHLSL_Var *tg = pJ1->GetTemporaryVarTarget_End_Smart( pJ1->GetSmartType(), true );
	Assert( tg );
	if ( !tg->CanBeOverwritten() )
		tg = NULL;
	if ( !( tg->GetType() & pJ1->GetSmartType() ) )
		tg = NULL;

	SetAllocating( !tg );
	if ( !tg )
		tg = pJ_Out->AllocateVarFromSmartType();
	pJ_Out->SetTemporaryVarTarget( tg );

	CHLSL_Solver_Utility_Assign *solver = new CHLSL_Solver_Utility_Assign( GetUniqueIndex() );
	solver->SetResourceType( res );
	solver->AddSourceVar( pJ1->GetTemporaryVarTarget_End() );
	solver->AddSourceVar( pJ2->GetTemporaryVarTarget_End() );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	return true;
}
bool CNodeBumpBasis::CreateSolvers(GenericShaderData *ShaderData)
{
	for ( int i = 0; i < GetNumJacks_Out(); i++ )
	{
		CJack *pJCur = GetJack_Out(i);
		if ( !pJCur->GetNumBridgesConnected() && i != 0 )
			continue;

		const int res = pJCur->GetResourceType();

		CHLSL_Var *tg = pJCur->AllocateVarFromSmartType();
		tg->MakeConstantOnly();

		CHLSL_Solver_BumpBasis *solver = new CHLSL_Solver_BumpBasis( GetUniqueIndex() );
		solver->SetResourceType( res );
		solver->AddTargetVar( tg );
		solver->SetState( i );
		AddSolver( solver );
	}

	return !!GetNumSolvers();
}
bool CNodePSOutput::CreateSolvers(GenericShaderData *ShaderData)
{
	for ( int i = 0; i < GetNumJacks_In(); i++ )
	{
		CJack *pJ = GetJack_In( i );
		if ( !pJ->GetNumBridgesConnected() )
			continue;

		CJack *sourceJack = pJ->GetBridge( 0 )->GetInputJack();
		CHLSL_Var *src = sourceJack->GetTemporaryVarTarget();
		const int res = pJ->GetResourceType();

		CHLSL_Solver_WriteSemantics *solver = new CHLSL_Solver_WriteSemantics( GetUniqueIndex() );
		solver->SetResourceType( res );
		solver->AddSourceVar( src );

		AddSolver( solver );
	}

	SmartCreateDummySolver();
	return true;
}
bool CNodeCallback::CreateSolvers(GenericShaderData *ShaderData)
{
	if ( !szCallbackName || !Q_strlen( szCallbackName ) || !iNumComponents )
		return false;
	int target = shaderEdit->FindCallback( szCallbackName );
	if ( target < 0 )
		return false;

	CJack *pJ_Out = GetJack_Out( 0 );

	const int res = pJ_Out->GetResourceType();

	SetAllocating( true );
	CHLSL_Var *tg = pJ_Out->AllocateVarFromSmartType();
	tg->MakeConstantOnly();

	CHLSL_Solver_Callback *solver = new CHLSL_Solver_Callback( GetUniqueIndex() );
	solver->SetState( target, szCallbackName, iNumComponents );
	solver->SetResourceType( res );
	solver->AddTargetVar( tg );
	AddSolver( solver );

	return true;
}
void CBaseContainerNode::Solve_ContainerLeft()
{
	AddSolver( new CHLSL_Solver_ContainerBasic( GetUniqueIndex() ) );
}