HLSL问题:缺少TextureCoordinate0 [英] problem with HLSL :TextureCoordinate0 is missing

查看:127
本文介绍了HLSL问题:缺少TextureCoordinate0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个非常简单的游戏,并且正在与HLSL合作.我的绘制方法出现此错误:

当前顶点声明不包括当前顶点着色器所需的所有元素.缺少TextureCoordinate0."

这是我的绘画方法:

Im trying to create a very simple game, and am working with HLSL. i got this error in my draw method:

"The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing."

and here is my draw method:

public void Draw(Matrix View, Matrix Projection,Vector3 CameraPosition)

{ // Calculate the base transformation by combining translation, rotation, and scaling

        Matrix baseWorld = Matrix.CreateScale(Scale) *
            Matrix.CreateFromYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z) *
            Matrix.CreateTranslation(Position);
        foreach (ModelMesh mesh in Model.Meshes)
        {
            Matrix localWorld = modelTransforms[mesh.ParentBone.Index] * baseWorld;

            foreach (ModelMeshPart part in mesh.MeshParts)
            {
                Effect effect = part.Effect;
                if (part.Effect is BasicEffect)
                {
                    ((BasicEffect)effect).World = localWorld;
                    ((BasicEffect)effect).View = View;
                    ((BasicEffect)effect).Projection = Projection;
                    ((BasicEffect)effect).EnableDefaultLighting();
                }
                else
                {
                    setEffectParameter(effect, "World", localWorld);
                    setEffectParameter(effect, "View", View);
                    setEffectParameter(effect, "Projection", Projection);
                    setEffectParameter(effect, "CameraPosition", CameraPosition);

                    Material.SetEffectParameters(effect);
                }
            }
            mesh.Draw();
        }



但是,如果在VertexShaderFunction(在LightingEffect中)中,而不是"output.UV = input.UV",我将"output.UV = float2(somefloat,somefloat)"放进去,不会出错.

还有另一件事,当我尝试加载大教堂"模型和其他模型时出现此错误,但是对于茶壶"模型,我没有错误!

我真的很困惑!

这是我完整的代码和模型. http://www.uploadmb.com/dw.php?id=1336639273

谢谢您的帮助.



but if in VertexShaderFunction (in LightingEffect), instead of "output.UV = input.UV" i put "output.UV=float2(somefloat,somefloat)" i got no error.

and there is a another thing, i got this error when i try to load my "Cathedral" model and others, but for "teapot" model i got no error!

i''m realy confused!

here is my complete code and models. http://www.uploadmb.com/dw.php?id=1336639273

thank you for your helping.

推荐答案

非常简单.您的某些模型具有UV坐标,而有些则没有.着色器尝试使用它们,并且在未加载任何着色器时会出现问题.这正是您的错误消息的含义.

VertexDeclarations确定确定顶点缓冲区中的数据结构是什么样的,并在加载模型时自动建立.尝试在自己的代码中为简单的对象(例如立方体或球体)设置缓冲区(而不是将脏的工作留给加载3D模型的代码),您将很快了解它的工作方式以及为什么顶点不着色器会出现问题找不到所需的组件.

查看那些教程 [
Its very simple. Some of your models have UV coordinates and some do not. The shader tries to use them and gets into problems when none are loaded. And that''s exactly what your error message means.

VertexDeclarations determine determine what the data structures in the vertex buffers look like and are set up automatically when a model is loaded. Try setting up the buffers for simple objects like cubes or spheres in your own code (instead of leaving the dirty work to the code that loads 3D models) and you will quickly see how that works and why the shader will get problems when the vertices don''t have some component it is looking for.

Look at those tutorials[^]. There, among a few other things, vertex buffers and vertex declarations are set up to create a 3D landscape from a height map.


这篇关于HLSL问题:缺少TextureCoordinate0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆