Jump to content
  • Advertisement
Sign in to follow this  
Kest

HLSL - Variable texture operation index

This topic is 3687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm sort of a hack when it comes to vertex shader code, so any corrective input is appreciated. In this vertex shader function..
float vParamTex[16];

void vsMethod_Param_TE4(vNormInput v_in,
	out float4 oPos : POSITION,		// Position
	out float4 oDif : COLOR0,		// Color + Alpha
	out float2 oTex1 : TEXCOORD0,	// Primary Texture Coordinate
	out float2 oTex2 : TEXCOORD1,	// Secondary Texture Coordinate
	out float2 oTex3 : TEXCOORD2,	// Third Texture Coordinate
	out float2 oTex4 : TEXCOORD3 )	// Fourth Texture Coordinate
{
	// Transform Vertex
	float3 vp = mul( float4(v_in.Pos.xyz, 1.0f), WorldMatrix);
	oPos = mul( float4(vp, 1.0f), ViewProj);

	// Set Diffuse to show light
	float3 normal = normalize( mul( v_in.normal, WorldMatrix ) );
	oDif = GetLightDiffuse( normal );

	// Set param coordinates
	oTex1.x = ( v_in.Tex.x * vParamTex[0] ) + vParamTex[2];
	oTex1.y = ( v_in.Tex.y * vParamTex[1] ) + vParamTex[3];
	oTex2.x = ( v_in.Tex.x * vParamTex[4] ) + vParamTex[6];
	oTex2.y = ( v_in.Tex.y * vParamTex[5] ) + vParamTex[7];
	oTex3.x = ( v_in.Tex.x * vParamTex[8] ) + vParamTex[10];
	oTex3.y = ( v_in.Tex.y * vParamTex[9] ) + vParamTex[11];

	// Fake reflection effect
	float3 vz = normalize( cross( normal, float3(vParamTex[14], vParamTex[15], 0.0f) ) );
	float3 vx = normalize( cross( normal, vz ) );
	vp += normalize( vp - Camera.Position ) * 192.0;
	oTex4.x = dot( vp, vx ) * vParamTex[12];
	oTex4.y = dot( vp, vz ) * vParamTex[13];
}





..I'm handling oTex4 at the bottom in a specific way. Now I've found that I actually need to control which texture layer (oTex1, oTex2, oTex3, oTex4) recieves this special operation per material (not per vertex). I guess I need each object material to be able to specify a texture index. Anyone have advice about how to best go about this? Can I reference the textures by array/index (ie: oTex[2].x)? And even if I can, how can I write this function in a managable way? My first guess would be to just handle all texture layers normally, then overwrite one of them at the bottom, which would waste some processing. It's a mess. I appreciate any help.

Share this post


Link to post
Share on other sites
Advertisement
I'm guessing DX9 (right?).

You can use a volume texture, where each slice is a texture. Then you'd use the Z element when fetching from the texture to index into which texture to use. Alternatively, a CubeMap might work as well.

With DX10 you should be able to use Texture Arrays.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!