# Search Results

• ### How to create per-vertex normals when reusing vertex data?

##### - by Chris Smith
I am displaying a cube using a vertex buffer object (gl.ELEMENT_ARRAY_BUFFER). This allows me to specify vertex indicies, rather than having duplicate vertexes. In the case of displaying a simple cube, this means I only need to have eight vertices total. Opposed to needing three vertices per triangle, times two triangles per face, times six faces. Sound correct so far? My question is, how do I now deal with vertex attribute data such as color, texture coordinates, and normals when reusing vertices using the vertex buffer object? If I am reusing the same vertex data in my indexed vertex buffer, how can I differentiate when vertex X is used as part of the cube's front face versus the cube's left face? In both cases I would like the surface normal and texture coordinates to be different. I understand I could average the surface normal, however I would like to render a cube. Also, this still doesn't work for texture coordinates. Is there a way to save memory using a vertex buffer object while being able to provide different vertex attribute data based on context? (Per-triangle would be idea.) Or should I just duplicate each vertex for each context in which it gets rendered. (So there is a one-to-one mapping between vertex, normal, color, etc.) Note: I'm using OpenGL ES.

• ### Minimum vs Minimal vertex covers

##### - by panicked
I am studying for an exam and one of the sample questions is as follows: Vertex cover: a vertex cover in a graph is a set of vertices such that each edge has at least one of its two end points in this set. Minimum vertex cover: a MINIMUM vertex cover in a graph is a vertex cover that has the smallest number of vertices among all possible vertex covers. Minimal vertex cover a MINIMAL vertex cover in a graph is a vertex cover that does not contain another vertex cover (deleting any vertex from the set would create a set of vertices that is not a vertex cover) Question: A minimal vertex cover isn't always a minimum vertex cover. Demonstrate this with a simple example. Can anyone get their head around this? I am failing to see the distinction between the two. More importantly, I'm having a hard time visualizing it. I seriously hope he's not gonna ask odd questions like this one on the exam!

• ### change the color of a vertex in a vertex shader

##### - by Soubok
Is it possible to set the color of a single vertex using a GLSL vertex shader program, in the same way that gl_Position changes the position of a vertex ?

• ### set the color of a vertex using a GLSL vertex shader

##### - by Soubok
Is it possible to set the color of a single vertex (not a face) using a GLSL vertex shader program (using GL_ARB_shading_language_100 extension) ?

• ### effect and model vertex declaration compatibility

##### - by Vodácek
I have normal model drawing code. When I try to draw model without UV coordinates I got this exception: System.InvalidOperationException: The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing. at Microsoft.Xna.Framework.Graphics.GraphicsDevice.VerifyCanDraw( Boolean bUserPrimitives, Boolean bIndexedPrimitives) at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType primitiveType, Int32 baseVertex, Int32 minVertexIndex, Int32 numVertices, Int32 startIndex, Int32 primitiveCount) at Microsoft.Xna.Framework.Graphics.ModelMeshPart.Draw() at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw() ... I know what cause the exception, but is possible to avoid it? Is possible to check model before drawing it with current shader for vertex declaration compatibility?

• ### Vertex 2 SSD is running faster than my Vertex 3 SSD?

##### - by Kairan
I used Acronis Disk Director to do a direct clone of my C:\ windows 7 x64 drive from my Vertex 2 to my new Vertex 3 SSD (Just to show the drive software winstall everything is identical.) I ran a performance test on Windows using the Windows Experience Index. The rating I am receiving when booting on the Vertex 2 is 7.5 While I am getting only a rating for the Vertex 3 of 6.9 My understanding is that the read/write speeds of the Vertex 2 is only up to 250MB/sec while the Vertex 3 is up to 500MB/sec. Copying a single file (3GB in size) from the Vertex 3 to itself was getting speed of approx 70-80MB/sec This speed is no better (maybe worse) than what I got from the Vertex 2 I am connected via the SATA 3 port on the motherboard, using an SATA 3 cable Is this issue caused by the drive cloning? Do I have a bad SSD?

• ### Memory allocation strategy for the vertex buffers (DirectX 10/11)

##### - by Alex
I have the following question. I write CAD system. So I have a 3D scene and there are many different objects (walls, doors, windows and so on). User can add or delete some objects. The question is: how can I organise the keeping of vertices for all my objects. I can create vertex buffer for every object. But I think drawing/switching from one buffer to another would have performance penalty. Another way - I can create several big buffers for every object type. But I don't understand how to update such buffers. It is too big to update whole buffer (for example buffer for all walls). What I need to do if I want to delete the object from the middle of the buffer? Actually I have the similar question: http://stackoverflow.com/questions/5515700/how-to-properly-update-vertex-buffers-in-directx-10 Most examples I've found work with very static models. Therefore, they tend to create a single vertex buffer with their list of points, and then are just manipulated by matrix transformations. I, on the other hand, will be updating the scene very often.

• ### What is the practical use of IBOs / degenerate vertex in OpenGL?

##### - by 0xFAIL
Vertices in 3D models CAN get cut in the process of optimizing 3D geometry, (degenerate vertices) by 3D graphics software (Blender, ...) when exporting because they aren't needed when reusing a vertex for multiple triangles. (In the current case 3D data is exported from Blender as .ply and read by a simple application that displays the 3D model) Every vertex has a few attributes like position, color, normal, tangent,... But the data for each vertex that is cut through the vertex sharing is lost and is missing in the vertex shader. Modern shader techniques like Bump or Normal mapping require normals/tangents per vertex which are also cut. To use complex shader techniques IBOs must not be used? Or is there a way to use IBOs and retain the data per vertex that was origionally lost?

• ### Vertex Normals, Loading Mesh Data

##### - by Ramon Johannessen
My test FBX mesh is a cube. From what I surmise, it seems that the cube is on the extreme end of this issue, but I believe that the same issue would be able to occur in any mesh: Each vertex has 3 normals, each pointing a different direction. Of course loading in any type of mesh, potentially ones having thousands of vertices, I need to use indices and not duplicate shared verts. Currently, I'm just writing the normals to the vertex at the index that the FBX data tells me they go to, which has the effect of overwriting any previous normal data. But for lighting calculations I need more info, something that's equivalent to a normal per face, but I have no idea how this should be done. Do I average the 3 different verts' normals together or what?

• ### Using raw vertex information for sprites rather than SpriteBatch in XNA

##### - by The Communist Duck
I have been wondering whether using SpriteBatch is the best option. Obviously for prototyping or small games it works well. However, I've been wanting to apply techniques such as shaders and lighting to my game. I know you can use shaders to some extent with SpriteSortMode.Immediate, but I'm not sure if you lose power using that. The other major thing is that you cannot store your vertex data in the graphics memory with buffers. In summary, is there an advantage of using VertexTextureNormal (or whatever they're called) structs for vertex data for 2D sprites, or should I stick with SpriteBatch, provided I wish to use shaders?

• ### Mapping a Vertex Buffer in DirectX11

##### - by judeclarke
I have a VertexBuffer that I am remapping on a per frame base for a bunch of quads that are constantly updated, sharing the same material\index buffer but have different width/heights. However, currently right now there is a really bad flicker on this geometry. Although it is flickering, the flicker looks correct. I know it is the vertex buffer mapping because if I recreate the entire VB then it will render fine. However, as an optimization I figured I would just remap it. Does anyone know what the problem is? The length (width, size) of the vertex buffer is always the same. One might think it is double buffering, however, it would not be double buffering because it only happens when I map/unmap the buffer, so that leads me to believe that I am setting some parameters wrong on the creation or mapping. I am using DirectX11, my initialization and remap code are: Initialization code D3D11_BUFFER_DESC bd; ZeroMemory( &bd, sizeof(bd) ); bd.Usage = D3D11_USAGE_DYNAMIC; bd.ByteWidth = vertCount * vertexTypeWidth; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; //bd.CPUAccessFlags = 0; bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; D3D11_SUBRESOURCE_DATA InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = vertices; mVertexType = vertexType; HRESULT hResult = device->CreateBuffer( &bd, &InitData, &m_pVertexBuffer ); // This will be S_OK if(hResult != S_OK) return false; Remap code D3D11_MAPPED_SUBRESOURCE resource; HRESULT hResult = deviceContext->Map(m_pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); // This will be S_OK if(hResult != S_OK) return false; resource.pData = vertices; deviceContext->Unmap(m_pVertexBuffer, 0);

• ### Beginner question about vertex arrays in OpenGL

##### - by MrDatabase
Is there a special order in which vertices are entered into a vertex array? Currently I'm drawing single textures like this: glBindTexture(GL_TEXTURE_2D, texName); glVertexPointer(2, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, coordinates); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); where vertices has four "xy pairs". This is working fine. As a test I doubled the sizes of the vertices and coordinates arrays and changed the last line above to: glDrawArrays(GL_TRIANGLE_STRIP, 0, 8); since vertices now contains eight "xy pairs". I do see two textures (the second is intentionally offset from the first). However the textures are now distorted. I've tried passing GL_TRIANGLES to glDrawArrays instead of GL_TRIANGLE_STRIP but this doesn't work either. I'm so new to OpenGL that I thought it's best to just ask here :-) Cheers!

• ### AndEngine Physics Editor loading level

##### - by Khawar Raza
I have created a .pes file using PhysicsEditor and imported as xml and have added to my project. When I parsed it and created bodies, it is showing strange behavior. The mapping of bodies that I created in PhysicsEditor is totally different what I see in my application means the shapes I draw in PhysicsEditor are rendering differently in my app. Here is my xml and code to parse and add bodies to scene. PhysicsEditor XML file: <?xml version="1.0" encoding="UTF-8"?> <!-- created with http://www.physicseditor.de --> <bodydef version="1.0"> <bodies numBodies="1"> <body name="car_path" dynamic="false" numFixtures="1"> <fixture density="2" friction="1" restitution="0" filter_categoryBits="1" filter_groupIndex="0" filter_maskBits="65535" isSensor="false" type="POLYGON" numPolygons="20" > <polygon numVertexes="6"> <vertex x="277.0000" y="152.0000" /> <vertex x="356.0000" y="172.0000" /> <vertex x="413.0000" y="194.0000" /> <vertex x="476.0000" y="223.0000" /> <vertex x="173.0000" y="232.0000" /> <vertex x="174.0000" y="148.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="1556.0000" y="221.0000" /> <vertex x="1142.0000" y="94.0000" /> <vertex x="1255.0000" y="-15.0000" /> <vertex x="1554.0000" y="-14.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="-192.0000" y="177.0000" /> <vertex x="-888.0000" y="139.0000" /> <vertex x="-549.0000" y="-125.0000" /> </polygon> <polygon numVertexes="6"> <vertex x="1762.0000" y="24.0000" /> <vertex x="1862.0000" y="27.0000" /> <vertex x="1927.0000" y="68.0000" /> <vertex x="2078.0000" y="222.0000" /> <vertex x="1643.0000" y="212.0000" /> <vertex x="1642.0000" y="38.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="-1150.0000" y="146.0000" /> <vertex x="-1776.0000" y="140.0000" /> <vertex x="-1476.0000" y="-25.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="-2799.0000" y="103.0000" /> <vertex x="-2684.0000" y="223.0000" /> <vertex x="-3112.0000" y="256.0000" /> <vertex x="-3108.0000" y="98.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="3112.0000" y="255.0000" /> <vertex x="2422.0000" y="222.0000" /> <vertex x="3120.0000" y="-71.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="1142.0000" y="94.0000" /> <vertex x="1556.0000" y="221.0000" /> <vertex x="709.0000" y="226.0000" /> <vertex x="911.0000" y="93.0000" /> </polygon> <polygon numVertexes="6"> <vertex x="-2111.0000" y="89.0000" /> <vertex x="-2067.0000" y="94.0000" /> <vertex x="-2002.0000" y="139.0000" /> <vertex x="-2344.0000" y="223.0000" /> <vertex x="-2196.0000" y="112.0000" /> <vertex x="-2153.0000" y="91.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="105.0000" y="233.0000" /> <vertex x="-94.0000" y="178.0000" /> <vertex x="69.0000" y="106.0000" /> <vertex x="91.0000" y="104.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="-2002.0000" y="139.0000" /> <vertex x="-2067.0000" y="94.0000" /> <vertex x="-2032.0000" y="110.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="-1150.0000" y="146.0000" /> <vertex x="105.0000" y="233.0000" /> <vertex x="-2344.0000" y="223.0000" /> <vertex x="-2002.0000" y="139.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="413.0000" y="194.0000" /> <vertex x="356.0000" y="172.0000" /> <vertex x="376.0000" y="176.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="105.0000" y="233.0000" /> <vertex x="-192.0000" y="177.0000" /> <vertex x="-94.0000" y="178.0000" /> </polygon> <polygon numVertexes="4"> <vertex x="105.0000" y="233.0000" /> <vertex x="-1150.0000" y="146.0000" /> <vertex x="-888.0000" y="139.0000" /> <vertex x="-192.0000" y="177.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="3112.0000" y="255.0000" /> <vertex x="-3112.0000" y="256.0000" /> <vertex x="-2684.0000" y="223.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="3112.0000" y="255.0000" /> <vertex x="1556.0000" y="221.0000" /> <vertex x="1643.0000" y="212.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="709.0000" y="226.0000" /> <vertex x="173.0000" y="232.0000" /> <vertex x="476.0000" y="223.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="3112.0000" y="255.0000" /> <vertex x="2078.0000" y="222.0000" /> <vertex x="2422.0000" y="222.0000" /> </polygon> <polygon numVertexes="3"> <vertex x="3112.0000" y="255.0000" /> <vertex x="105.0000" y="233.0000" /> <vertex x="173.0000" y="232.0000" /> </polygon> </fixture> </body> </bodies> <metadata> <format>1</format> <ptm_ratio></ptm_ratio> </metadata> </bodydef> And here is my code: private void loadLevel() { // TODO Auto-generated method stub AssetManager assetManager = getAssets(); try { InputStream stream = assetManager.open("tmx/path1.xml"); if(stream != null) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setIgnoringComments(false); dbf.setIgnoringElementContentWhitespace(true); dbf.setNamespaceAware(true); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); Document document = db.parse(stream); Element root = document.getDocumentElement(); NodeList bodiesNodeList = root.getElementsByTagName("bodies"); for(int i = 0; i < bodiesNodeList.getLength(); i++) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.fixedRotation = true; Element bodiesElement = (Element)bodiesNodeList.item(i); NodeList bodyList = bodiesElement.getElementsByTagName("body"); for(int j = 0; j < bodyList.getLength(); j++) { Element bodyElement = (Element)bodyList.item(j); Body body = mPhysicsWorld.createBody(bodyDef); NodeList fixtureList = bodyElement.getElementsByTagName("fixture"); for(int k = 0; k < fixtureList.getLength(); k++) { Element fixtureElement = (Element)fixtureList.item(k); FixtureDef fixtureDef = new FixtureDef(); if(fixtureElement != null) { String density = fixtureElement.getAttribute("density"); String friction = fixtureElement.getAttribute("friction"); String restitution = fixtureElement.getAttribute("restitution"); fixtureDef = PhysicsFactory.createFixtureDef(Float.parseFloat(density), Float.parseFloat(friction), Float.parseFloat(restitution)); } NodeList polygonList = fixtureElement.getElementsByTagName("polygon"); if(polygonList != null && polygonList.getLength() > 0) { for(int m = 0; m < polygonList.getLength(); m++) { PolygonShape polyShape = new PolygonShape(); Element polygonElement = (Element)polygonList.item(m); NodeList vertexList = polygonElement.getElementsByTagName("vertex"); if(vertexList != null && vertexList.getLength() > 0) { Vector2 [] vectors = new Vector2[vertexList.getLength()]; for(int n = 0; n < vertexList.getLength(); n++) { Element vertexElement = (Element)vertexList.item(n); if(vertexElement != null) { float x = Float.parseFloat(vertexElement.getAttribute("x")); float y = Float.parseFloat(vertexElement.getAttribute("y")); vectors[n] = new Vector2(x/PIXEL_TO_METER_RATIO_DEFAULT, y/PIXEL_TO_METER_RATIO_DEFAULT); } } polyShape.set(vectors); fixtureDef.shape = polyShape; } body.createFixture(fixtureDef); } } } mScene.attachChild(bgSprite); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(bgSprite, body, false, false)); } } } catch(Exception e) { e.printStackTrace(); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Any idea where I am going wrong?

• ### Something other than Vertex Welding with Texture Atlas?

##### - by Tim Winter
What options (in C# with XNA) would there be for texture usage in a procedural generated 3D world made of cubes to increase performance? Yes, it's like Minecraft. I've been doing a texture atlas and rendering faces individually (4 vertices per face), but I've also read in a couple places about using texture wrapping with two 1D atlases to merge adjacent faces with the same texture. If two or more adjacent faces share the same image, it'd be quite easy to wrap in this way reducing vertices by a large amount. My problem with this is having too many textures, swapping too often, and many image related things like non-power of 2 images. Is there a middle ground option between the 1D texture atlas trick and rendering 4 vertices per cube face? This is a picture of what I have currently (in wireframe). 4 vertices per face seems extremely inefficient to me.

• ### XNA 4.0 Point Vertex Rendering

##### - by luis
I have a buffer of about 134 million particles and a very powerful computer to render them smoothly but I am getting an error when trying to render them as primitive lines it says I cannot render more than around 1 million. I wonder how can I do this, also if is there a better way to render this other than with lines, I'm comfortable with having 1 pixel points or anything as long as the vertices are shown all the time. I'm basically just plotting the points. thanks.

• ### Per-vertex position/normal and per-index texture coordinate

##### - by Boreal
In my game, I have a mesh with a vertex buffer and index buffer up and running. The vertex buffer stores a Vector3 for the position and a Vector2 for the UV coordinate for each vertex. The index buffer is a list of ushorts. It works well, but I want to be able to use 3 discrete texture coordinates per triangle. I assume I have to create another vertex buffer, but how do I even use it? Here is my vertex/index buffer creation code: // vertices is a Vertex[] // indices is a ushort[] // VertexDefs stores the vertex size (sizeof(float) * 5) // vertex data numVertices = vertices.Length; DataStream data = new DataStream(VertexDefs.size * numVertices, true, true); data.WriteRange<Vertex>(vertices); data.Position = 0; // vertex buffer parameters BufferDescription vbDesc = new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = VertexDefs.size * numVertices, StructureByteStride = VertexDefs.size, Usage = ResourceUsage.Default }; // create vertex buffer vertexBuffer = new Buffer(Graphics.device, data, vbDesc); vertexBufferBinding = new VertexBufferBinding(vertexBuffer, VertexDefs.size, 0); data.Dispose(); // index data numIndices = indices.Length; data = new DataStream(sizeof(ushort) * numIndices, true, true); data.WriteRange<ushort>(indices); data.Position = 0; // index buffer parameters BufferDescription ibDesc = new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = sizeof(ushort) * numIndices, StructureByteStride = sizeof(ushort), Usage = ResourceUsage.Default }; // create index buffer indexBuffer = new Buffer(Graphics.device, data, ibDesc); data.Dispose(); Engine.Log(MessageType.Success, string.Format("Mesh created with {0} vertices and {1} indices", numVertices, numIndices)); And my drawing code: // ShaderEffect, ShaderTechnique, and ShaderPass all store effect data // e is of type ShaderEffect // get the technique ShaderTechnique t; if(!e.techniques.TryGetValue(techniqueName, out t)) return; // effect variables e.SetMatrix("worldView", worldView); e.SetMatrix("projection", projection); e.SetResource("diffuseMap", texture); e.SetSampler("textureSampler", sampler); // set per-mesh/technique settings Graphics.context.InputAssembler.SetVertexBuffers(0, vertexBufferBinding); Graphics.context.InputAssembler.SetIndexBuffer(indexBuffer, SlimDX.DXGI.Format.R16_UInt, 0); Graphics.context.PixelShader.SetSampler(sampler, 0); // render for each pass foreach(ShaderPass p in t.passes) { Graphics.context.InputAssembler.InputLayout = p.layout; p.pass.Apply(Graphics.context); Graphics.context.DrawIndexed(numIndices, 0, 0); } How can I do this?

• ### Loading Wavefront Data into VAO and Render It

##### - by Jordan LaPrise
I have successfully loaded a triangulated wavefront(.obj) into 6 vectors, the first 3 vectors contain the locations for vertices, uv coords, and normals. The last three have the indices stored for each of the faces. I have been looking into using VAO's and VBO's to render, and I'm not quite sure how to load and render the data. One of my biggest concerns is the fact that indexed rendering only allows you to have one array of indices, meaning I somehow have to make all of the first three vectors the same size, the only way I thought of doing this, is to make 3 new vertex's of equal size, and load in the data for each face, but that would completely defeat the purpose of indexing. Any help would be appreciated. Thanks in advance, Jordan

• ### Vertex data split into separate buffers or one one structure?

##### - by kiba2
Is it better to have all vertex data in one structure like this: class MyVertex { int x,y,z; int u,v; int normalx, normaly, normalz; } Or to have each component (location, normal, texture coordinates) in separate arrays/buffers? To me it always seemed logical to keep the data grouped together in one structure because they'd always be the same for each instance of a shared vertex and that seems to be true for things like character models (ex: the normal should be an average of adjacent normals for smooth lighting). One instance where this doesn't seem to work is other kinds of meshes like say a cube where the texture coordinates for each may be the same but that causes them to be different where the vertices are shared. Does everybody normally keep them separate? Won't this make them less space efficient if there needs to be an instance of texture coordinates and normals for each triangle vertex (They won't be indexed)? Can OpenGL even handle this mixing of indexed (for location) vs non-indexed buffers in the same VBO?

• ### Clipplanes, vertex shaders and hardware vertex processing in Direct3D 9

##### - by Igor
Hi, I have an issue with clipplanes in my application that I can reproduce in a sample from DirectX SDK (February 2010). I added a clipplane to the HLSLwithoutEffects sample: ... D3DXPLANE g_Plane( 0.0f, 1.0f, 0.0f, 0.0f ); ... void SetupClipPlane(const D3DXMATRIXA16 & view, const D3DXMATRIXA16 & proj) { D3DXMATRIXA16 m = view * proj; D3DXMatrixInverse( &m, NULL, &m ); D3DXMatrixTranspose( &m, &m ); D3DXPLANE plane; D3DXPlaneNormalize( &plane, &g_Plane ); D3DXPLANE clipSpacePlane; D3DXPlaneTransform( &clipSpacePlane, &plane, &m ); DXUTGetD3D9Device()->SetClipPlane( 0, clipSpacePlane ); } void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) { // Update the camera's position based on user input g_Camera.FrameMove( fElapsedTime ); // Set up the vertex shader constants D3DXMATRIXA16 mWorldViewProj; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; mWorld = *g_Camera.GetWorldMatrix(); mView = *g_Camera.GetViewMatrix(); mProj = *g_Camera.GetProjMatrix(); mWorldViewProj = mWorld * mView * mProj; g_pConstantTable->SetMatrix( DXUTGetD3D9Device(), "mWorldViewProj", &mWorldViewProj ); g_pConstantTable->SetFloat( DXUTGetD3D9Device(), "fTime", ( float )fTime ); SetupClipPlane( mView, mProj ); } void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // If the settings dialog is being shown, then // render it instead of rendering the app's scene if( g_SettingsDlg.IsActive() ) { g_SettingsDlg.OnRender( fElapsedTime ); return; } HRESULT hr; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration ); pd3dDevice->SetVertexShader( g_pVertexShader ); pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( D3DXVECTOR2 ) ); pd3dDevice->SetIndices( g_pIB ); pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 ); V( pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_dwNumVertices, 0, g_dwNumIndices / 3 ) ); pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, 0 ); RenderText(); V( g_HUD.OnRender( fElapsedTime ) ); V( pd3dDevice->EndScene() ); } } When I rotate the camera I have different visual results when using hardware and software vertex processing. In software vertex processing mode or when using the reference device the clipping plane works fine as expected. In hardware mode it seems to rotate with the camera. If I remove the call to RenderText(); from OnFrameRender then hardware rendering also works fine. Further debugging reveals that the problem is in ID3DXFont::DrawText. I have this issue in Windows Vista and Windows 7 but not in Windows XP. I tested the code with the latest NVidia and ATI drivers in all three OSes on different PCs. Is it a DirectX issue? Or incorrect usage of clipplanes? Thanks Igor

• ### How do I morph between meshes that have different vertex counts?

##### - by elijaheac
I am using MeshMorpher from the Unify wiki in my Unity project, and I want to be able to transform between arbitrary meshes. This utility works best when there are an equal number of vertices between the two meshes. Is there some way to equalize the vertex count between a set of meshes? I don't mean that this would reduce the vertex count of a mesh, but would rather add redundant vertices to any meshes with smaller counts. However, if there is an alternate method of handling this (other than increasing vertices), I would like to know.

• ### Computing pixel's screen position in a vertex shader: right or wrong?

##### - by cubrman
I am building a deferred rendering engine and I have a question. The article I took the sample code from suggested computing screen position of the pixel as follows: VertexShaderFunction() { ... output.Position = mul(worldViewProj, input.Position); output.ScreenPosition = output.Position; } PixelShaderFunction() { input.ScreenPosition.xy /= input.ScreenPosition.w; float2 TexCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1); ... } The question is what if I compute the position in the vertex shader (which should optimize the performance as VSF is launched significantly less number of times than PSF) would I get the per-vertex lighting insted. Here is how I want to do this: VertexShaderFunction() { ... output.Position = mul(worldViewProj, input.Position); output.ScreenPosition.xy = output.Position / output.Position.w; } PixelShaderFunction() { float2 TexCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1); ... } What exactly happens with the data I pass from VS to PS? How exactly is it interpolated? Will it give me the right per-pixel result in this case? I tried launching the game both ways and saw no visual difference. Is my assumption right? Thanks. P.S. I am optimizing the point light shader, so I actually pass a sphere geometry into the VS.