XNA:当前顶点声明不包括当前顶点着色器所需的所有元素.Normal0 缺失 [英] XNA: The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing

查看:20
本文介绍了XNA:当前顶点声明不包括当前顶点着色器所需的所有元素.Normal0 缺失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有点麻烦.我使用 xna 已经有一段时间了,但我对 3D 完全陌生.我正在关注 msdn 网站上 winformsgraphicsdevice 示例中的代码.它有一个控件,可以在屏幕上绘制一个原始三角形.就这么简单,但我在这一行遇到了一个例外:

Hey I'm having a little trouble. I've been working with xna for a while, but I'm completely new to 3D. I'm following the code verbatim from the winformsgraphicsdevice sample on the msdn website. It has a control that draws a primitive triangle to the screen. Simple as that, but I get an exception on this line:

GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);

说的是:

当前顶点声明没有包含当前顶点着色器需要的所有元素.Normal0 缺失."

我假设它与我的 VertexPositionColor 变量 vertices 有关.该代码在这里:

I'm assuming it has something to do with my VertexPositionColor variable, vertices. That code is here:

vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.Black);
vertices[1] = new VertexPositionColor(new Vector3( 1, -1, 0), Color.Black);
vertices[2] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Black);

推荐答案

你的顶点着色器需要一个 normal 值(用于光照计算)但是 VertexPositionColor 结构不需要没有它.

Your vertex shader is demanding a normal value (used for lighting calculations) but VertexPositionColor struct doesn't have it.

您必须创建一个结构来存储顶点位置、颜色和法线数据,因为它不是 XNA 上的预构建类型.

You'll have to create a struct for storing vertex position, color AND normal data as it's not a prebuilt type on XNA.

您可以在此处了解如何创建它:http:///www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php

You can learn how to create it here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php

他在那里创建了一个名为 VertexPositionColorNormal 的结构,使用它代替您当前使用的 VertexPositionColor.

There he creates a struct called VertexPositionColorNormal, use it instead of VertexPositionColor that you're currently using.

如果您不需要任何照明并且您没有使用 BasicEffect,只需从您使用的技术中删除您的照明变量/计算.如果您使用 BasicEffect,请尝试将 LightingEnabledTextureEnabled 属性设置为 false.

If you don't want any lighting and you're not using BasicEffect, just remove your lighting variables/calculations from the technique you're using. If you are using BasicEffect try setting LightingEnabled and TextureEnabled properties to false.

这篇关于XNA:当前顶点声明不包括当前顶点着色器所需的所有元素.Normal0 缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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