Jump to content
  • Advertisement
Sign in to follow this  

HLSL problem

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

Before I render any of my meshes, I can alter position, rotation and scale. This works. The problem arises after I do these modifications. The shader completely ignores the changes I made to the mesh vertex coordinates and only only uses the original mesh info. An example of a terrain I made and the HLSL water acting as if it was still at the origin: "effectinstances" only referenced when declaring mesh... this is my problem. Here is my code for initializing my mesh with shaders.
public BaseMesh(Device _dev, String XFilePath, Coordinate _coord)
			dev = _dev;
			coord = _coord;

			mesh = Mesh.FromFile(Global.settings.InstallPath + "resources/" + XFilePath, MeshFlags.Managed, dev, out effectinstances);
			mesh = mesh.Clone(MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, dev);
			// Lock the vertex buffer to acces vertices
			CustomVertex.PositionNormalTextured[] lockedVerts = null;
			lockedVerts = mesh.LockVertexBuffer(
				mesh.NumberVertices) as CustomVertex.PositionNormalTextured[];

			// Copy the position data into a simple vector array
			// And, since the mesh is pretty boring and flat, add some jaggedness.
			Vector3[] odeVerts = new Vector3[lockedVerts.Length];
			for(int i = 0; i < lockedVerts.Length; ++i)
				odeVerts = lockedVerts.Position;
				odeVerts.X *= Coord.Scale.X;
				odeVerts.Z *= Coord.Scale.Z;
				odeVerts.Y *= Coord.Scale.Y;

				odeVerts.X += Coord.Position.X;
				odeVerts.Z += Coord.Position.Z;
				odeVerts.Y += Coord.Position.Y;

				// propogate the jagginess back to the mesh
				lockedVerts.Position = odeVerts;

			mesh.OptimizeInPlace( MeshFlags.OptimizeCompact | MeshFlags.OptimizeAttributeSort, (GraphicsStream)null );

			short[] odeIndices = mesh.IndexBuffer.Lock(0, typeof(short), 0, mesh.NumberFaces*3) as short[];

			geom = new ODE.Geoms.TriMesh(odeVerts, odeIndices);

			effect = new Effect[effectinstances.Length];

			for(int z=0; z < effectinstances.Length; z++)
				if(effectinstances[z].EffectFilename != null)
					effect[z] = Effect.FromFile(dev, Global.settings.InstallPath + @"resources\" + effectinstances[z].EffectFilename, null, null, ShaderFlags.None, null);
					effect[z].Technique = effect[z].FindNextValidTechnique(null);


Share this post

Link to post
Share on other sites
When using a vertex shader, this shader should take care of transforming the vertices. The vertices are received in object space (i.e. only transformed with respect to the local object origin). To transform it into world space you need to multiply it with the world matrix in the vertex shader. This also means you must pass the world matrix to your effect instance when you use it. Afterwards, similar steps hold for world-to-view and view-to-screen transformations. Some can be combined, depending on the shader.



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!