问题描述
嘿,我有一个小麻烦。我一直与XNA了一段时间,但我完全新的3D。我下面从MSDN网站上的winformsgraphicsdevice样品code一字不差。它绘制原始三角形屏幕控制。就这么简单,但我得到在这条线的异常:
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList,顶点,0,1);
它说:
当前的顶点声明不包括所有当前顶点着色器所需的元素。Normal0是失踪。
我猜想它是与我的 VertexPositionColor
变量,顶点
。这code是在这里:
顶点=新VertexPositionColor [3];
顶点[0] =新VertexPositionColor(新Vector3类型(-1,-1,0),Color.Black);
顶点[1] =新VertexPositionColor(新Vector3类型(1,-1,0),Color.Black);
顶点[2] =新VertexPositionColor(新Vector3类型(0,1,0),Color.Black);
您的顶点着色器,要求一个的正常的值(用于照明计算),但 VertexPositionColor
结构没有它。
您必须创建一个结构来存储顶点位置,颜色和正常的数据,因为它不是在XNA一个prebuilt型。
您可以学习如何在这里创建它: HTTP:/ /www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php
在那里,他创建了一个名为结构 VertexPositionColorNormal
,用它来代替 VertexPositionColor
您目前使用
如果你不希望任何照明和你没有使用 BasicEffect
,只是删除您的照明变量/从你使用的技术计算。如果您使用的是 BasicEffect
尝试设置 LightingEnabled
和 TextureEnabled
属性为false。
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);
Which says:
"The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing."
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);
Your vertex shader is demanding a normal value (used for lighting calculations) but VertexPositionColor
struct doesn't have it.
You'll have to create a struct for storing vertex position, color AND normal data as it's not a prebuilt type on XNA.
You can learn how to create it here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php
There he creates a struct called VertexPositionColorNormal
, use it instead of VertexPositionColor
that you're currently using.
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.
这篇关于新华社:当前顶点声明不包括所有当前顶点着色器所需的元素。 Normal0缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!