Jump to content
  • Advertisement
Sign in to follow this  
acid2

Multitexturing troubles.

This topic is 4808 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

Hey all, for my terrain I want to use 2 texture layers. One layer where each tile is a quad, u and v go 0 - 1 per tile. The second layer is acting like the terrain is one huge quad. This is so I can apply textures on the first layer, and a lightmap on top. I can't get the second layer to appear though. Here is my vertex definition
using System;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Rebirth.Extensions.Terrain
{
	public struct TerrainVertex
	{
		public const VertexFormats Format = VertexFormats.PositionNormal | VertexFormats.Texture2;

		public static int StrideSize = 40;

		public TerrainVertex(Vector3 pos, Vector3 norm, Vector2 tex1, Vector2 tex2)
		{
			X = pos.X; Y = pos.Y; Z = pos.Z;
			Nx = norm.X; Ny = norm.Y; Nz = norm.Z;

			U1 = tex1.X; V1 = tex1.Y;
			U2 = tex2.X; V2 = tex1.Y;
		}
		public TerrainVertex(float posx, float posy, float posz,
			float normx, float normy, float normz,
			float tex1x, float tex1y, float tex2x, float tex2y)
		{
			X = posx; Y = posy; Z = posz;
			Nx = normx; Ny = normy; Nz = normz;

			U1 = tex1x; U2 = tex2x;
			V1 = tex1y; V2 = tex2y;
		}

		private float X, Y, Z, Nx, Ny, Nz, U1, V1, U2, V2;
	}
}

Vertex creation:
Verts[index] = new TerrainVertex(
	new Vector3(x, 0, y), new Vector3(0, 1, 0),
	new Vector2(tu, tv), new Vector2(lu, lv));
Texture States:
device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;

device.TextureState[1].ColorOperation = TextureOperation.Modulate;
device.TextureState[1].ColorArgument0 = TextureArgument.TextureColor;
device.TextureState[1].ColorArgument1 = TextureArgument.Current;

device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
well, you should setup alpha-operations for the second texstage aswell, i guess. for safety, you should also disable the third texstage. i'm not shure why you pasted the blending-stuff under texturestages, blending does not relate to texture-stages at all.

Share this post


Link to post
Share on other sites
Yes, but I thought I may have ended up messing something up :P Why do I need to disable the third level?

Share this post


Link to post
Share on other sites
In this post, I'm using 0-based stage offsets, so stage 1 is the second stage, etc.

Like kusma said, don't forget to set up the alpha blending params for stage 1 as well. Disabling stage 2 is just a precaution in case something else is messing it up.

In addition, be sure to set the TexCoordIndex (don't know the real name in C#) of stage 1 to 1, so the second stage will get its texture coordinates from the second set of texture coordinates in each vertex. Also, you may have to set the TextureTransformFlags of stage 1 to Count2, and the TexCoordIndex of stage 1 to passthru. Again, I don't know the names in C#, but there should be something similar.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!