Jump to content
  • Advertisement
Sign in to follow this  

Mesh.Box with Effects (parralax mapping)

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

alrighty, so i have a Mesh.Box, and i can render it fine, thats not difficult. ive been trying to add an effect, namely parralax mapping to the Cube/Box, but i have a problem... first of all, trying to render the effect with the Mesh.Box by itself like this:

doesnt work at all... so i did this to the mesh:
internal Mesh OptimizeMesh(Mesh mesh, Device myDevice)
            int[] adjac = new int[mesh.NumberFaces * 3];
            Mesh temp = mesh.Optimize(MeshFlags.OptimizeCompact | MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeDeviceIndependent | MeshFlags.OptimizeStripeReorder, adjac);
            VertexElement[] elements = new VertexElement[]{
                new VertexElement(0, sizeof( float ) * 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, sizeof( float ) * 3, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, sizeof( float ) * 6, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, sizeof( float ) * 8, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
                new VertexElement(0, sizeof( float ) * 11, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),

            mesh = temp.Clone(MeshFlags.Managed, elements, myDevice);
            mesh.ComputeTangent(0, 0, -1, 0);
            return mesh;

and now it renders... but the textures dont show up... i have tried the exact same process with a mesh.FromFile and it works how i want it too... am imissing something?

Share this post

Link to post
Share on other sites
After running into no end of trouble trying to find out if the Mesh.Box has texture coordinates, I found the Mesh.Box FVF does suggest it has, but locking the vertex data only works properly for PostionNormal vertices, so the data just doesn't seem to be there. You can lock the Mesh.Vertexbuffer of the cloned mesh and set the values yourself (note that a Mesh.Box is a set of 6 quads, using 24 vertices to properly apply texture coordinates).

Another thing you might want to try (and I recommend doing that first), is replacing the call to mesh.ComputeTangent(...) with a call to mesh.ComputeTangentFrame(0). I'm not entirely sure what mesh.ComputeTangent does, but I guess mesh.ComputeTangentFrame might be what you're after. As an unrelated note, you also should dispose of the temp mesh once you've cloned it and the original mesh once an optimized copy has been made.

If all else fails, try enabling the debug runtimes and enable unmanaged debugging on the debug tab of your project's property sheet in Visual Studio. This makes DirectX spew forth a lot more info about what might be going wrong. Another option would be to use PIX or a 3rd party shader debugging tool like NVidiaPerfHud to track down the error.

Hope this helps :)

Share this post

Link to post
Share on other sites
ive tried ComputeTangentFrame also, same result... I just tried the ComputeTangent after a reading another post somewhere...

anyways, what exactly do you mean by "You can lock the Mesh.Vertexbuffer of the cloned mesh and set the values yourself", do you mean set the texture coords? If so, how exactly would i go about doing that?

sorry, im REALLY new to most of this stuff...

ive been running DX under debug and unmanaged code debugging but it doesnt spit out harldy anything... mostly warnings that its ignoring redundant crap

[Edited by - perkbrian on March 8, 2007 7:13:44 PM]

Share this post

Link to post
Share on other sites
You might want to click that link I posted to find some tutorials on how to lock a vertexbuffer on Google. We have some available on MDXInfo that lock vertex buffers, but IIRC they don't cover the locking indepth.

If you want more theory, locking a buffer basically is a way to tell D3D that you want to get access to the buffer's content. Since the buffer may be in system ram or video ram, locking provides an abstraction for accessing the buffer, regardless of what memory it is in. Also, as the CPU and GPU (your videocard) work asynchronously, locking a buffer tells the GPU to stop using it for rendering, so you can safely edit its contents on the CPU.

You can either lock a buffer as an Array or as a GraphicsStream. A GraphicsStream allows you to tranfer raw bytes to and from the buffer sequentially. Using an Array, you can just edit the vertex structs in the buffer, which is much more convenient, if a bit less efficient. In your situation, you could define a custom struct based on your vertex declaration (so the struct fields match the vertex elements) and use the appropriate overload to the Mesh.VertexBuffer.Lock method that returns an array. These are typically the overloads that take a type as a parameter, but more details on this can be found in the documentation.

With all that being said, I think you might be a lot easier off loading a box Mesh that already has texture coordinates from a file. I think eventually you'll want to apply the effect to other meshes than the good old box, so you'll need this functionality anyway.

Hope this helps :)

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!