• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Stefan Fischlschweiger

[SharpDX] Unable to render texured models using BasicEffect

6 posts in this topic

I finished porting my game project from XNA to SharpDX. Since the shader file I used in XNA (which was from riemers tut) doesn't work here anymore I wanted to use SharpDX's BasicEffect shader for rendering until I get myself into shader coding.

 

Unfortunatly this only works as long as I keep textures disabled.

If I set TextureEnabled = true the program crashes as soon as it tries to render a model with the following error:

 

D3D11 ERROR: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'TEXCOORD'/0, but the declaration doesn't provide a matching name. [ STATE_CREATION ERROR #163: CREATEINPUTLAYOUT_MISSINGELEMENT]

 

Here's the code of my model render class:

using MetastormDX.Services;
using SharpDX;
using SharpDX.Direct3D11;
using SharpDX.Toolkit.Graphics;

namespace MetastormDX.Models
{
    public static class ModelDrawer
    {
        /// <summary>
        /// Generic model drawing method.
        /// </summary>
        /// <param name="model">Model to be drawn.</param>
        /// <param name="modelTexture">Model textures.</param>
        /// <param name="modelPos">Current position of the model in world space.</param>
        /// <param name="modelRot">Current rotation of the model.</param>
        public static void DrawModel(Model model, Texture2DBase[] modelTexture, Vector3 modelPos, Quaternion modelRot)
        {
            Matrix worldMatrix = Matrix.Scaling(0.05f, 0.05f, 0.05f) * Matrix.RotationQuaternion(modelRot) *
                Matrix.Translation(modelPos);

            Matrix[] modelTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransforms);

            int i = 0;
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    BasicEffect currentEffect = effect;
                    currentEffect.View = ScreenManager.ScreenManager.ViewMatrix;
                    currentEffect.Projection = ScreenManager.ScreenManager.ProjectionMatrix;
                    currentEffect.World = worldMatrix;
                    currentEffect.TextureView = modelTexture[i++];
                    currentEffect.TextureEnabled = true;
                    currentEffect.PreferPerPixelLighting = true;
                    currentEffect.EnableDefaultLighting();

                    currentEffect.CurrentTechnique.Passes[0].Apply();
                }

                mesh.Draw(GameServices.Graphics);
            }
        }
    }
}

0

Share this post


Link to post
Share on other sites

When you set TextureEnabled to true, BasicEffect will switch to a version of the shader that expects your vertices' texture coordinates to be in element "TEXCOORD0". However, according to the error message, your vertices don't provide any coordinates with that name. How are you loading the model and what vertex type are you using? If you're using a custom one, maybe you forgot to add the attribute to the struct's field that holds the texture coordinates?

2

Share this post


Link to post
Share on other sites

This is my model loading code:

public Model LoadModel(string assetName, Effect effect, out Texture2D[] textures)
        {
            int i = 0;
            Model newModel = GameServices.Content.Load<Model>(assetName);
            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    i++;
            textures = new Texture2D[i];
            i = 0;
            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (var effect1 in mesh.Effects)
                {
                    var currentEffect = (BasicEffect) effect1;
                    textures[i++] = currentEffect.Texture as Texture2D;
                }

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    meshPart.Effect = effect.Clone();

            return newModel;
        }

The models are compiled .tkb

The model as retured in newModel is stored in the respective class instance where I need it and passed to the draw code as is. 

0

Share this post


Link to post
Share on other sites

When you inspect the loaded model in the debugger, what do the InputElements in the VertexInputLayouts look like? Do they include a "TEXCOORD" element? If they don't, are you sure that your model contains texture coordinates?

The SharpDX Toolkit automatically chooses an appropriate Vertex struct and corresponding VertexInputLayout for you. If there is no InputElement for texture coordinates, the model compiler probably wasn't able to find any texture coordinates in the source model.

Edited by lwm
1

Share this post


Link to post
Share on other sites

It shows me 2 InputElements: SV_POSITION and NORMAL

 

Gotta investigate this

 

BTW: The models were created in 3dsMax 2014, exported to .fbx and then converted with tkmodel.exe

Edited by Lordadmiral Drake
0

Share this post


Link to post
Share on other sites

So, I reexported and converted all my models. Now the render code doesn't crash anymore. But all models are plain black instead of textured. Appearantly the textures are not loaded. All texture variable values show "null"

 

EDIT: Finally, textures are working :D Had to put them in the same folder as the model, set build action to none on the textures and ToolkitModel on the model.

Edited by Lordadmiral Drake
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0