⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clvector.fx

📁 在GPU上实现数值模拟技术(线性方程组)的通用架构
💻 FX
📖 第 1 页 / 共 2 页
字号:
	float4 f4MatVector = tex2D(sVector,v.TexCoords)*fSize.w;//fMultiply;

	f4Result.rg = f4MatVector.rg * tex2D(sVector2,f4ShiftCoords.xy).ba;
	f4Result.ba = f4MatVector.ba * tex2D(sVector2,f4ShiftCoords.zw).rg;

	return f4Result;
}

float4 psVectorMultiplyMatAllCases2_noadd(vertex2pixel v) : COLOR0 {
	float4 f4ShiftCoords   = computeShiftedCoordsAllCasesP1(v.TexCoords,fSize.z/*fShift*/)/fSize.xyxy;
	
	float4 f4Result;
	float4 f4MatVector = tex2D(sVector,v.TexCoords)*fSize.w;//fMultiply;

	f4Result.rg = f4MatVector.rg * tex2D(sVector2,f4ShiftCoords.xy).ba;
	f4Result.ba = f4MatVector.ba * tex2D(sVector2,f4ShiftCoords.zw).rg;

	return f4Result;
}

/*
 * Case "3"
 */
float4 psVectorMultiplyMatPosOnly3_noadd(vertex2pixel v) : COLOR0 {
	float4 f4ShiftCoords   = computeShiftedCoordsPosOnlyP1(v.TexCoords,fSize.z/*fShift*/)/fSize.xyxy;
	
	float4 f4Result;
	float4 f4MatVector = tex2D(sVector,v.TexCoords)*fSize.w;//fMultiply;

	f4Result.r   = f4MatVector.r * tex2D(sVector2,f4ShiftCoords.xy).a;
	f4Result.gba = f4MatVector.gba * tex2D(sVector2,f4ShiftCoords.zw).rgb;

	return f4Result;
}

float4 psVectorMultiplyMatAllCases3_noadd(vertex2pixel v) : COLOR0 {
	float4 f4ShiftCoords   = computeShiftedCoordsAllCasesP1(v.TexCoords,fSize.z/*fShift*/)/fSize.xyxy;
	
	float4 f4Result;
	float4 f4MatVector = tex2D(sVector,v.TexCoords)*fSize.w;//fMultiply;

	f4Result.r   = f4MatVector.r * tex2D(sVector2,f4ShiftCoords.xy).a;
	f4Result.gba = f4MatVector.gba * tex2D(sVector2,f4ShiftCoords.zw).rgb;

	return f4Result;
}

//////////

float4 psUnpackVector(vertex2pixel v) : COLOR{

	float4 result;
	float2 coords = float2(v.TexCoords.x/2,v.TexCoords.y);
	
	if (round((v.TexCoords.y*fSize.y*2)%2)==1) coords.x += 0.5;
	
	float4 vecValue = tex2D(sVector,coords);
	
	if (round((v.TexCoords.x*fSize.x*2)%4) == 3)
		result = float4(vecValue.a,0,0,0);
	else if (round((v.TexCoords.x*fSize.x*2)%4) == 2)
		result = float4(vecValue.b,0,0,0);
	else if (round((v.TexCoords.x*fSize.x*2)%4) == 1)
		result = float4(vecValue.g,0,0,0);
	else 
		result = float4(vecValue.r,0,0,0);	
	
	return result;
}


float4 psPackVector(vertex2pixel v) : COLOR {

	// remark: using different constant definitions in this function
	// fShift  = packed size in X
	// fSize.x = unpacked size in X
	// fSize.y = unpacked size in Y
	// fSize.b = half the packed size in X (=fSize.x/2)
	// fSize.a = 1/(unpacked size in X)

	float4 result;

	float2 coords = float2(round((v.TexCoords.x*fShift)%fSize.b)*4.0, floor(round(v.TexCoords.x*fShift)/fSize.b)+(v.TexCoords.y*fSize.y));

	// rescale back to [0..1] in unpacked coords
	coords /= fSize.xy;

	result.r = tex2D(sVector,coords).r;	coords.x += fSize.a;
	result.g = tex2D(sVector,coords).r;	coords.x += fSize.a;
	result.b = tex2D(sVector,coords).r;	coords.x += fSize.a;
	result.a = tex2D(sVector,coords).r;

	return result;
}

/////////////////////////////////////////////////////
// TECHNIQUES
/////////////////////////////////////////////////////

technique tMultiplyScal {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psMultily();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tReduceAddFirst {
	pass P0 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddFirst();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tReduceAddRest {
	pass P0 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddRest();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tReduceAddLast {
	// for r-only encoded (unpacked)
	pass P0 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddLast();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
    
    // for RGBA encoded (packed)
	pass P1 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddLastRGBA();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

}

technique tReduceAddRestX {
	pass P0 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddRestX();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;
    }   
}

technique tReduceAddRestY {
	pass P0 {
		VertexShader = compile vs_1_1 vsReduce();
		PixelShader  = compile PS_PROFILE psReduceAddRestY();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tVectorAdd {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorAdd();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorAddClFloat();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P2 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorSubClFloat();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tVectorMultiply {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiply();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
    
	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyClFloat();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tVectorMultiplyMatPosOnly {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly0();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly1();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P2 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly2();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P3 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly3();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tVectorMultiplyMatAllCases {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases0();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases1();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P2 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases2();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P3 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases3();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}


technique tVectorMultiplyMatAllCases_noadd {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases0_noadd();

		CullMode			= NONE; 
		ZWriteEnable		= FALSE;
		ZEnable				= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases1_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P2 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases2_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P3 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatAllCases3_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}


technique tVectorMultiplyMatPosOnly_noadd {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly0_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P1 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly1_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P2 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly2_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   

	pass P3 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psVectorMultiplyMatPosOnly3_noadd();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tUnpackVector {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psUnpackVector();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

technique tPackVector {
	pass P0 {
		VertexShader = compile vs_1_1 vsAll();
		PixelShader  = compile PS_PROFILE psPackVector();

		CullMode			= NONE; 
		ZEnable				= FALSE;
		ZWriteEnable		= FALSE;
		AlphaBlendEnable	= FALSE;				
    }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -