• 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
HenriqueRocha

Some Triangles are Disapearing with IndexBuffer

3 posts in this topic

Hello Everybody!

I had a bug few hours ago and I solved it without knowing how to [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] .


[img]http://img641.imageshack.us/img641/7259/88866365.jpg[/img]

I am using VertexBuffer and IndexBuffer, it's not the first time that I am using them, but this time I was forced to use DynamicIndexBuffer with some frustrating trial & error.

It stays about 1 second right then everything goes wrong.

With DrawUserIndexedPrimitives it works nice (but slower), DynamicIndexBuffer works nice and just with IndexBuffer it's what happens in the picture.

I know that using DynamicIndexBuffer is slower, but do have any choice? What is happening?

It seems like gpu memory corruption.

Thanks ;-)
0

Share this post


Link to post
Share on other sites
this is the effect file:

[CODE]
struct VertexToPixel
{
float4 Position : POSITION;
float2 TextureCoords : TEXCOORD1;
float4 Position3D : TEXCOORD2;
float4 Normal3D : TEXCOORD3;
float Texture[3] : TEXCOORD4;
};
//------- Constants --------
float4x4 xView;
float4x4 xProjection;
float4x4 xWorld;
float3 xLightDirection;
float xAmbient;
float3 xCameraPosition;
float xFogStart;
float xFogEnd;
float xFogEnabled;
float4 xFogColor;
float2 xWaterPosition;
//------- Texture Samplers --------
Texture xTexture0,xNormal0; // WATER
Texture xTexture1,xNormal1; // SAND
Texture xTexture2,xNormal2; // GRASS
sampler TextureSampler[3]{
{ texture = <xTexture0>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;},
{ texture = <xTexture1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;},
{ texture = <xTexture2>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;}
};
sampler NormalSampler[3]{
{ texture = <xNormal0>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;},
{ texture = <xNormal1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;},
{ texture = <xNormal2>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;}
};
//-----------------------------------------------------------------------------
// Compute fog factor
//-----------------------------------------------------------------------------
float ComputeFogFactor(float d){
return clamp((d - xFogStart) / (xFogEnd - xFogStart), 0, 1) * xFogEnabled;
}

//------- Technique: Terrain --------
VertexToPixel MultiTextureVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 coord : TEXCOORD,short tex : COLOR){
VertexToPixel Output = (VertexToPixel)0;

// === USE THIS FOR PHONG ===
Output.Normal3D = mul(inNormal, xWorld);
Output.Position3D = mul(inPos, xWorld);
// === MATRIX AND TRANSFORMS ===
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
// === TEXTURE COORDINATES ===
Output.TextureCoords = coord;
// === TEXTURED VERTEX ===
if(tex==0) Output.Texture[0] = 1;
if(tex==1) Output.Texture[1] = 1;
if(tex==2) Output.Texture[2] = 1;
return Output;
}
//------- Technique: Water --------
VertexToPixel WaterVS( float4 inPos : POSITION, float3 inNormal: NORMAL,float2 coord : TEXCOORD){
VertexToPixel Output = (VertexToPixel)0;
// === USE THIS FOR PHONG ===
Output.Normal3D = mul(inNormal, xWorld);
Output.Position3D = mul(inPos, xWorld);
// aldrabating
inPos.y = 0;
// === MATRIX AND TRANSFORMS ===
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
// === TEXTURE COORDINATES ===
Output.TextureCoords = coord + xWaterPosition;
Output.Texture[0] = 1;
return Output;
}

float4 MultiTexturePS(VertexToPixel Input) : COLOR {
float4 Color = (float4)0;
float3 tex2DNormal= (float3) 0;
float NdotL, rotH, rotV;
float3 normalVector;
// === MULTI-TEXTURE SPLATING ===
if(Input.Texture[0]){ Color += tex2D(TextureSampler[0], Input.TextureCoords)*Input.Texture[0]; tex2DNormal += tex2D(NormalSampler[0], Input.TextureCoords)*Input.Texture[0]; }
if(Input.Texture[1]){ Color += tex2D(TextureSampler[1], Input.TextureCoords)*Input.Texture[1]; tex2DNormal += tex2D(NormalSampler[1], Input.TextureCoords)*Input.Texture[1]; }
if(Input.Texture[2]){ Color += tex2D(TextureSampler[2], Input.TextureCoords)*Input.Texture[2]; tex2DNormal += tex2D(NormalSampler[2], Input.TextureCoords)*Input.Texture[2]; }
// === READ NORMAL MAP ===
tex2DNormal = tex2DNormal*2.0-1.0;
normalVector = normalize(float3(tex2DNormal.x, tex2DNormal.z,tex2DNormal.y));
normalVector = normalize(normalVector + Input.Normal3D);
// === DO DIRTY JOB ===
Color.rgb *= saturate(dot(normalVector, -xLightDirection)) + xAmbient;
float fogFactor = ComputeFogFactor(length(xCameraPosition - Input.Position3D));
float3 eyeVector = normalize(xCameraPosition - Input.Position3D);
float3 reflectionVector = reflect(-xLightDirection ,normalVector);
NdotL = dot(normalize(reflectionVector), normalize(eyeVector));
if(NdotL<0){
float specular = pow(NdotL, 16);
Color.rgb += specular*0.2;
}
Color.rgba = lerp(Color.rgba, xFogColor, fogFactor);
return Color;
}


technique ERATech
{
pass Pass0
{
VertexShader = compile vs_3_0 MultiTextureVS();
PixelShader = compile ps_3_0 MultiTexturePS();
}
pass Pass1
{
VertexShader = compile vs_3_0 WaterVS();
PixelShader = compile ps_3_0 MultiTexturePS();
}
}
[/CODE]

this is my vertex declaration:

[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ERA_XNA.Core
{
public struct VertexMultiTexture : IVertexType
{
public Vector3 Position, Normal, Tangent, Binormal;
public Vector2 TextureCoordinate;
public short TextureID;

public static readonly Random _rand = new Random();
VertexDeclaration IVertexType.VertexDeclaration
{
get { return VertexDeclaration; }
}
public VertexMultiTexture(Vector3 position, Vector3 normal, Vector2 coordinates, short tex, Vector3 tangent, Vector3 binormal)
{
TextureID = tex;
Position = position;
Normal = normal;
TextureCoordinate = coordinates;
Tangent = tangent;
Binormal = binormal;
}
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(
new VertexElement(sizeof(float) * 0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementUsage.Normal,0),
new VertexElement(sizeof(float) * 6, VertexElementFormat.Vector3, VertexElementUsage.Tangent,0),
new VertexElement(sizeof(float) * 9, VertexElementFormat.Vector3, VertexElementUsage.Binormal,0),
new VertexElement(sizeof(float) * 12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate,0),
new VertexElement(sizeof(float) * 14, VertexElementFormat.Short2, VertexElementUsage.Color,0)
);
}
}
[/CODE]

and where I create Buffers:

[CODE]
// INIT BUFFER
_vertexBuffer = new VertexBuffer(graphics,VertexMultiTexture.VertexDeclaration, _vertices.Length, BufferUsage.WriteOnly);
// SEND VERTEXS TO BUFFER
_vertexBuffer.SetData<VertexMultiTexture>(_vertices);
// INIT BUFFER

// if _indexBuffer = new DynamicIndexBuffer(...) it works, why?

_indexBuffer = new IndexBuffer(graphics,IndexElementSize.ThirtyTwoBits, pos, BufferUsage.WriteOnly);
// SEND INDEXS TO BUFFER
_indexBuffer.SetData<int>(_indices);
[/CODE]

btw, the "normalVector = normalize(normalVector + Input.Normal3D);" in my Pixel Shader is wrong, given Binormal and Tangent what should I do now do have normal map working correctly? Edited by hdlopesrocha
0

Share this post


Link to post
Share on other sites
Good news! I solved the problem!

[CODE]
"public short TextureID ;" && "new VertexElement(sizeof (float)*14,VertexElementFormat.Short2,VertexElementUsage.Color,0)"
[/CODE]


I changed short to int and there is no problem now!
But I think int is too big for a textureID Edited by hdlopesrocha
0

Share this post


Link to post
Share on other sites
[quote name='hdlopesrocha' timestamp='1339480733' post='4948413']
But I think int is too big for a textureID
[/quote]
GPU's have a hard time dealing with odd types like short/bool and prefer when data is aligned properly, especially in highly regular structures like vertex arrays, so unless you have a really good reason to optimize this I wouldn't worry about it too much. Remember that premature optimization isn't a good habit to have - just make it work first, make it work [i]fast[/i] later.
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