Hot answers tagged graphics-programming
103
"Memory" and "efficiency" are commonly misused terms, so I'll give you an answer for four different elements that may affect the performance of your game.
I will be oversimplifying way too many things to keep it short and concise, but there are tons of inaccuracies in this text below, so take it with a pinch of salt. However, the main concepts should be ...
58
A strong argument for using spritesheets is that the number of available textures on a graphic card can be limited. Therefore your graphics library would constantly have to remove texture and re-allocate textures on the GPU. It's much more efficient to just allocate a large texture once.
Also consider that texture sizes are usually power of 2. So if you ...
32
I'd say the arguement to use would be the ability to render multiple things in a single draw call. Take for example font rendering, without a spritesheet you'd need to render each character with a separate texture swap followed by a draw call. Throw them into a spritesheet and you can render entire sentences with a single draw call (the difference characters ...
29
A quick and easy way - though not 100% precise one - is to consider just the five extreme points white, black, red, green and blue.
First, let's transform RGB into linear space. Officially this is usually done by this formula (assuming the source data is in sRGB, which is the default for most graphic card operations on 8-bit data and nearly every image you ...
25
A wide-angle lens should not behave differently than other regular lens models. They just have a larger FOV (in the D3DXMatrixPerspectiveFovLH sense -- I'm assuming you use DirectX), or larger left/right and bottom/top values (in the OpenGL glFrustum sense).
I believe the really interesting part lies in modeling the fisheye lens. There's Fisheye Quake that ...
23
The simplest way to achieve the effect is to draw a bunch of particles in Additive mode, so when they are superimposed their color values are added up, becoming brighter.
Some samples:
http://www.youtube.com/watch?v=_sx0KDO-ZbA
http://www.youtube.com/watch?v=-OZOdQHLiiI
19
I think you will understand their purpose better with a sample. By reading the comments you will understand how VAOs are used.
// BEGIN INITIALIZATION
// Define some vertex data
struct Vertex {
GLfloat position[3];
GLfloat texcoord[2];
};
Vertex vertexdata[NUM_VERTS] = { ... };
GLubyte indexdata[NUM_INDICES] = { 0, 1, 2, ... };
// Create and bind a ...
19
I don't buy the argument that it's easier to start with the fixed-function stuff. It might be the case that the fixed-function lets you do certain things with less code - in fixed-function OpenGL, for instance, you can get some very basic lighting/shading going by doing glEnable(GL_LIGHTING) and a few other calls. The trouble is that as soon as you want ...
18
Are there important cases when one needs to know how to program sort algorithms in game programming?
I'm going to say yes, to your question as phrased, but with important caveats.
Yes, you need to know how to sort things in programming game development. There's lots of sorting goes on, in a wide variety of situations. No, you don't need to know the details of how all (or even many) the various sorting algorithms work, it's almost always sufficient to look ...
17
Everything, really.
The only benefit to object-space normals is simplicity. They're easier to use.
Tangent-space normals require a tangent-space basis, but offer:
The ability to use the same texture for different surfaces. Object-space normal maps can only ever be used on the surface for which they were created. By regularizing normals in tangent-space, ...
16
Once an image is loaded off the disk and is formatted for rendering, it will use the same amount of memory regardless of whether that image was saved to disk using PNG, JPEG, or GIF.
General rule of thumb: JPEG is a lossy format, and will degrade image quality in order to make the image smaller on disk. PNG, on the other hand, is a lossless image format, ...
15
My friend is working on a side-scrolling shooter in XNA that uses similar effects (here's a video of an early test). He wrote a blog post about the technique that you might find helpful.
He's also usually hanging out in the #graphicschat IRC channel on irc.afternet.org (name's Drilian) and could probably help you out.
12
If you are using OpenGL, the OpenGL FAQ section 9: Transformations covers exactly how to do this. And no, it doesn't involve raytracing, as that's understandably a very inefficient (but high quality) way to accomplish this.
9.170 How do I render a mirror?
Here is essentially what the FAQ entry says, and the example code demonstrates:
Set up a reflected ...
12
Broadly, the answer is "it depends." The way one would send particle updates is quite a bit different than the way you would send a series of GPU-skinned models.
Vertex/Index Buffers
In the general sense, though, everything these days is done with a VBO (vertex buffer object). The old immediate-mode API (glBegin/glEnd) is probably just implemented as a ...
11
Examples for these kind of things is pretty much what the GPU Gems series covers.
Books 1,
2, and 3 are available for free on nVidia's website.
11
Each draw call has a certain amount of overhead. By using sprite sheets you can batch the drawing of things that aren't using the same frame of an animation (or more generally, everything that's on the same material) greatly enhancing performance. This may not matter too much for modern PCs depending on your game, but it definitely matters on, say, the ...
11
It's probably a bad idea to create new classes for each type of geometry you're going to support. It's not very scalable or maintainable. Additionally, the class design you appear to want now seems to conflate the tasks of managing the geometry itself and the instance data for that geometry.
Here's an approach you can take:
Create two classes, Mesh and ...
10
In my OpenGL ES 2.X engine, i compute the MVP matrix (Model View Projection) on CPU Side
and inject it in vertex shader.
The Orthogonal projection is a 4*4 matrix. When i have the MVP, i inject it in the
vertex shader with:
mMvpLoc = getUniformLocation("uMvp");
glUniformMatrix4fv(mMvpLoc, 1, false, mMvp.pointer());
The mMvp is my matrix 4*4 on CPU ...
10
The number of polygons to render a "good looking" 500x500px sphere with a single draw call is trivial for GPUs to handle on most platforms, especially if there isn't much else in the scene. There's also some notes about texturing spheres to avoid texel distortion; make sure to use a cube map.
10
In such highly dynamic environment,
such as computer game scene is, what
is the point of using VBOs, if the
VBOs would need to be constructed on
per-frame basis anyway?
If you are reconstructing the vertex data for every object every frame, you're doing it wrong. Or at least, you're probably doing it inefficiently.
Moving objects in a scene ...
10
Draw your entire scene, except highlighted objects.
Draw the objects you want to highlight, in pure color, sorted from back to front, and with a small scale applied (1.05f - 1.1f).
Draw the final objects, again, from back to front.
For extra eye-candy, try drawing the contour pass to a separate render target and apply a small blur, then blend this texture ...
10
Short answer: No. You can "be" an indie game developer without knowing anything about graphics.
More practically, it depends on the kind of graphics you want in your game.
If you want "fancy" graphics, meaning graphics that require whatever knowledge you're referring to, then someone has to know it. You either know it yourself and write the code, or you ...
10
I'm currently making a game that has to run on a wide variety of display sizes and aspect ratios, and it hasn't been a very easy process. In addition, if you're making things in pixel art, and you want to keep the pixel art feeling while supporting many resolutions, you're walking into a world of pain, so be prepared.
In my opinion, there are several things ...
9
Difficult to tell from the video exactly what you mean, but the simplest method of doing a sprite-based motion blur would just be to render the sprite several times, with some form of translucency.
You could buffer the previous positions for use as the trail, or you could use a small time-step in the animation to render sub-frames.
From the video in ...
9
FastLSM is sorta like what you're after.
Alec has also made 2D game engine based on deforming lattice (instead of voxels as in FastLSM). It's called Physical. Look at the demo asteroids style game to see what can be done and the performance.
Alec also built a full game using physical called Sopwith IV.
I never played Sopwith IV, but I spent plenty of ...
9
There's really no need to store memory for every particle and animate each particle separately. You can do it procedurally by reconstructing the particle position during drawing by using the classic physics equation. s = ut + 1/2.a.t^2
A simple example (without constant acceleration of particles):
void drawExplosion(ExplosionParameters& s)
{
Random rng;
...
9
From a mathematical point of view, it depends on in which order you are multiplying the vectors with the matrix.
Using a row-vector (v) and multiplying it with a matrix (A) as v∙A, then the rows will act as the axes.
Using a column-vector (v) and multiplying a matrix (A) with it as A∙v, then the columns will act as the axes.
9
If you're relatively new to graphics programming, the most important thing for a lot of special effects is to understand alpha blending, and blending modes in general.
For glows, explosions, and particle effects, additive blending is your best friend.
Once you understand the effect of adding or multiplying colours, and the ways in which you can use alpha ...
9
You're probably thinking of motion blur.
Edit for more content: Here's a bit from GPU gems on motion blur:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html
One of the best ways to simulate speed in a video game is to use motion blur. Motion blur can be one of the most important effects to add to games, especially racing games, because it ...
9
Anything I can say on the subject is said better here: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter03.html, but I'll give you my best shot anyway.
The idea behind hardware instancing is that you reduce the amount of GPU draw calls by sending each mesh only once, together with a list of transforms. This offloads some of the work done by the CPU ...
Only top voted, non community-wiki answers of a minimum length are eligible
