Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

109 Neutral

About Mohanddo

  • Rank
  1. Mohanddo

    [DX11] Tile map performance

    Thanks, im going to implement all that you have said soon but first i have to make a decision on what is a sprite and an entity so i can conveniently change texture and buffer states. I guess that's a design problem. Anyway many thanks to everyone that helped
  2. Mohanddo

    [DX11] Tile map performance

    Thanks for the suggestions. I pre transform my sprites on load and any time the map is moved now which gave me a decent fps boost (~30 fps). Unfortunately im not using sprite sheets and i have a separate image for each entity to keep it simple. Later i can create a system where my individual sprites would be compiled into a large image when i create a map editor. Also what is NN sampling?
  3. Hi I have been working on 2d tile map loading and rendering and im noticing very bad performance with my simple approach. Basically i have a 2d array which specify the tiles in the map using a number to represent each type of tile (water, rock etc.) Each of these are a sprite of its own with a vertex buffer and a texture. All tiles are 32x32. This is the render function of the map: XMMATRIX VPMatrix = g_Game->GetViewProjectionMatrix(); ID3D11Buffer* MVPBufferHandle = g_Game->GetMVPBuffer(); ID3D11DeviceContext* D3DContext = g_Game->GetContext(); XMMATRIX world = GetWorldMatrix(); for(int i = 0; i < m_TileList.size(); i++) { for(int j = 0; j < m_TileList.size(); j++) { XMMATRIX offset = XMMatrixMultiply(world, XMMatrixTranslation(j * m_TileSize, i * m_TileSize, 0.0f)); XMMATRIX mvp = XMMatrixMultiply(offset, VPMatrix); mvp = XMMatrixTranspose(mvp); D3DContext->UpdateSubresource(MVPBufferHandle, 0, 0, &mvp, 0, 0); D3DContext->VSSetConstantBuffers(0, 1, &MVPBufferHandle); m_SpriteList[m_TileList[j]].Render(); } } Simply put i get the pointer for my constant buffer to send my final matrix to the shader, I multiply the location of each tile by the location of the map and the projectionview matrix and send it off for rendering. The render function of a sprite just binds the vertex buffer and the texture resource and renders a quad(using triangle list). As an example i tried to render 100 tiles with only 2 types of sprites. without map = 500 fps; with map = ~250 fps; This looks to me like very bad performance probably due to my approach but i have no idea how i can couple things together to save draw calls or texture binds Can anyone guide me on how i can increase the performance? Thanks
  4. Mohanddo

    Deferred shading - confusion

    Ok i think i have enough info to implement it now, thanks alot for your help and patience
  5. Mohanddo

    Deferred shading - confusion

    Yes i already understand all this except about the sunlighting. Do you mean to calculate phong directional light just as you would in a forward pass renderer and do all lighting calculations on that instead? If so, is there an advantage to this compared to a full screen quad at lighting stage? Ok but in the case which the object i am rendering does not have a texture of its own, the material diffuse will be in this buffer i presume?
  6. Mohanddo

    Deferred shading - confusion

    Thanks, i think im starting to understand now. So let me get this right. 1. The albedo texture should be a combo of the material diffuse property and the objects texture? 2. No ambient material should be needed since it is usually the same as the diffuse property. Later i can add SSAO 3. And now there will be no emissive or specular color but instead a factor that will be multiplied by the light properties? Only question that remains for me now is if the materials are now like this, will the light sources properties be similar or do they still retain their RGBA values
  7. Mohanddo

    Deferred shading - confusion

    I see but then what is the values that i store in my gbuffer for lighting? and how can i compute them? ([size=2]specular intensity, power, emissiveness) If i understand correctly, specular intensity is calculated based on light direction and viewpoint so then how can i compute this when i am in my first pass? Shouldnt light properties only be available at the lighting stage? As you can probably tell i am very confused by all this
  8. Mohanddo

    Deferred shading - confusion

    Thanks for the reply. I have only written shaders for the simple phong shading using full rgba values for material properties. What equations do i need to use to compute shading using only those 3 values form the g-buffer? Is there some resources that can teach me this? You also mention that in the lighting stage i need the material properties but how can i pass these to my lighting shader if they are not stored in my g-buffer? thanks
  9. Mohanddo

    Deferred shading - confusion

    Thank you very much for your answers Good resources thanks. The only thing i still dont understand is how to pack an RGBA value into 1 component. My render targets are of the format GL_RGBA16F so how can i pack and unpack them into this format in GLSL? So in the deferred pass stage the output will be the diffuse color?
  10. Hi. I am trying to implement deferred shading in my engine and i am slightly confused. I have already set up multiple render targets and this is what i have so far: 1. Bind deferred shader and fill 3 textures with: position, normal and texture color. 2. Bind lighting shader and fbo textures, multi textures available in my fragment shader and i can output the various textures. An image of how my textures look from rendering a simple terrain and an axe is attached: Is there anything wrong with them? (top right is just ambient property) So to actually implement the lighting i have a few questions that i would be glad if anyone could clarify for me. 1. Do i output the scene once in the deferred pass and then blend the lighting pass to it or is all of the fragment output done in the lighting pass? 2. In the lighting pass, what do i have to draw? For a point light, do i have to use a cone 'proxy shape' or i can compute shading for each pixel based on the light area of effect? 3. Where do materials come in in deferred shading? Do i have to render to a texture the material properties ambient - diffuse - specular - emissive of every object for every pixel? In addition is there any resources on deferred shading that you can recommend. I have read the major ones (guerrilla-games, nvidia, gamedev image space lighting). Thanks in advance
  11. Mohanddo

    Usage of shaders

    Ok so I have been learning openGL with GLSL during the last few weeks and now that I have come to writing shaders and implementing lighting, textures etc. I am slightly confused. How are shaders supposed to be used and combined? If I want directional lightning, spot lights and point lights to affect all of a scene do I write one shader with the implementation of all lights? Or should they be implemented in different shaders. How do i combine shaders for different effects all in one scene? What i am basically asking is what should constitute as one shader? Any help on understanding this would be great. Thanks
  12. Mohanddo

    Can't render 2 textures

    I have fixed the problem now. The texture parameters are per texture and should be specified after binding every texture when loading them. For some reason i thought they followed the state system like how you would use glEnable().
  13. Mohanddo

    Can't render 2 textures

    Thanks for your reply. Correct me if im wrong on this but i am not rendering anything before sending my uniforms, just making opengl ready for the render phase( Just binding vertex attrib to my buffer data - vertex co-ordinates, color, and uv co-ordinates and binding the texture ID) I believe the rendering starts from the DrawArray call. Just to make sure i tried sending uniforms before anything else and i still had the same result.
  14. I have been trying to render two different objects with 2 different textures. I'm using GLSL and VBOs. Everything works fine except the first texture is not displaying for some reason. I am totally stumped, ive looked at my code many times and I cant figure it out so i would appreciate any help. I load my textures from an SDL surface like this: glGenTextures(1, &m_textureID); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_textureID); SDL_Surface* tmpsurface; tmpsurface = IMG_Load("test.jpg"); GLenum bpp = GL_RGB; if(tmpsurface->format->BytesPerPixel == 4) { bpp = GL_RGBA; } glTexImage2D(GL_TEXTURE_2D, 0, bpp, tmpsurface->w, tmpsurface->h, 0, bpp, GL_UNSIGNED_BYTE, tmpsurface->pixels); glGenTextures(1, &m_textureID2); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_textureID2); SDL_Surface* tmpsurface2; tmpsurface2 = IMG_Load("okay.jpg"); bpp = GL_RGB; if(tmpsurface2->format->BytesPerPixel == 4) { bpp = GL_RGBA; } glTexImage2D(GL_TEXTURE_2D, 0, bpp, tmpsurface2->w, tmpsurface2->h, 0, bpp, GL_UNSIGNED_BYTE, tmpsurface2->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); SDL_FreeSurface(tmpsurface); SDL_FreeSurface(tmpsurface2); Then I render the scene like this: float modelviewMatrix[16]; float projectionMatrix[16]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glPushMatrix(); glLoadIdentity(); glBindBuffer(GL_ARRAY_BUFFER, m_bufferID); glBindTexture(GL_TEXTURE_2D, m_textureID); glVertexAttribPointer((GLuint)2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(28)); glVertexAttribPointer((GLuint)1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(12)); glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0)); glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix); glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix); m_GLSLProgram->SendUniform("modelview_matrix", modelviewMatrix); m_GLSLProgram->SendUniform("projection_matrix", projectionMatrix); m_GLSLProgram->SendUniform("texture0", 0); glDrawArrays(GL_TRIANGLE_FAN, 0, 6); glBindBuffer(GL_ARRAY_BUFFER, m_bufferID2); glBindTexture(GL_TEXTURE_2D, m_textureID2); glVertexAttribPointer((GLuint)2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(28)); glVertexAttribPointer((GLuint)1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(12)); glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 5); glPopMatrix(); What i get as a result is the first draw call being rendered with a 'plain black' texture. And the second call being rendered correctly. The weird thing is that if I switch the loading order of the 2 textures, then the first draw call is textured and the second with a black texture. Does anyone have any idea of why this might be happening? Thanks
  15. Mohanddo

    Too many calls

    Quote:Original post by freeworld I wouldn't think that tiny bit of code would really cause your app to slow down... if you're that worried you can store a point to the m_setup and use that instead of using the function call. Thanks for your reply. Correct me if im wrong but the time given is also depending on how many times its called. Also thanks for the pointer idea! i will try it. I think its better to try pointers and caching at the same time to reduce calls. Quote:Original post by rip-off Are you profiling in Release mode or Debug mode? The only way I could see that function causing trouble is if you call it unnecessarily, for example not caching the return value in a local variable if you are invoking it multiple times: *** Source Snippet Removed *** This isn't primarily an optimisation, this is making the code more readable. You can see clearly in the second version that frobnicate() is intended to receive the same second parameter every invocation, whereas the first example requires one to examine (at least) the implementation of EngineSetup::baz() to determine this. Also, if you move such a short function into the header file the compiler might be more willing to inline it for you. I was using debug mode. Although originally the sample time was 5s but i only counted the first thread and presumed the others were from other things like visual studio debugger. Thanks for your suggestion in caching. This is what i meant in number 1 about having a variable inside the method to take the values and use that instead of calling them each time in calculations. This will definetly speed things up but is there any other way to make these variables more global? The methods are called alot and there are also numerous other methods and objects that use these values. I guess it would be a bad idea to make a global variable outside the classes and set them to the values? Maybe im going too far into optimization ... I dont exactly know what you mean by the last sentance... do you mean in the .h file or by header you mean something else? And what would be the benefits of that? Thanks for your time!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!