Question

As I'm sure most of you know WP7 doesn't support custom shader files which to me unless I'm missing something means that I can't draw anything from just vertex and indices data like I can on Windows, I need to use a Model either loaded in or parsed from other data types.

What I'm looking for is a method for taking a Model variable and heightmap bitmap (presumably loaded as a Texture2D) and create a vertex for each pixel based on the grey-scale value, it would also be nice to set the vertical scale from a function constructor variable as well.

For reference here is my function that draws the models in my game:

protected void DrawMesh(Model myMesh, Vector3 meshPos, float meshRot)
{
    // Copy any parent transforms
    Matrix[] transforms = new Matrix[myMesh.Bones.Count];
    myMesh.CopyAbsoluteBoneTransformsTo(transforms);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in myMesh.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.View = camera.View;
            effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(MathHelper.ToRadians(meshRot)) * Matrix.CreateTranslation(meshPos);
            effect.Projection = camera.Projection;
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();

    }
}

Does anyone know how I can do this fairly simply? I'd prefer not to over complicate things with multiple files yet before I understand the process.

Thanks!

-Ryan

Était-ce utile?

La solution

First of all, a lack of custom shaders does not imply that you cannot draw with raw vertices/indices. In fact you can on WP7. What it implies is that you cannot control raw pixel output (pixel shader), or write code that changes each individual vertex's projection mapping to the screen (vertex shader). There are other kinds of shaders too at various stages of the entire pipeline, but none of them have anything to do with telling the graphics card which vertices & indices to use. You do that yourself in your game code. In fact they (or rather, data taken from them down the chain) are used as inputs to shaders (among other things).

That said, you can still generate vertices yourself, in game code. And even manipulate them too if you wish, to a certain degree. Doesn't require any shaders to generate vertices & indices and draw them raw, even on WP7. Do not use Model for this; that's overkill.

You can use GetData on your texture to get its color values, and simply generate an array of vertices (VertexPositionColor, or texture, or any other format you wish) based on the color value of each pixel. There is a tutorial laying out everything you need to do here. Almost everything there will work as-is on WP7 except the effect parameters; map those instead to a BasicEffect or the like. There are no custom shaders in it.

Post-script: You should read up on the basics of 3D graphics, in terms of what shaders do vs. what vertices are meant for, and really the whole pipeline, to get a better understanding. There are plenty of good articles, blogs, and books out there.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top