Hot answers tagged

44

The attenuation function you've got, att = 1.0 / (1.0 + 0.1*dist + 0.01*dist*dist) is a fairly common one in computer graphics - or, more generally, 1.0 / (1.0 + a*dist + b*dist*dist)) for some tweakable parameters a and b. To understand how this curve works it's helpful to play with the parameters interactively. This curve is nice because it approaches ...


24

Your problem isn't moving the camera in full-pixel increments. It's that your texel-to-pixel ratio is slightly non-integer. I'll borrow some examples from this similar question I answered on StackExchange. Here's two copies of Mario - both are moving across the screen at the same rate (either by the sprites moving right in the world, or the camera moving ...


19

This article gives some useful explainations, even if that's before 4.3 came out: If you’re going for the “pixel art” look then the camera’s orthographic size is of critical importance; this is the trickiest part of nailing 2D in Unity. The orthographic size expresses how many world units are contained in the top half of the camera projection. ...


17

There's a number of options: Do as you do. You've already said it doesn't look smooth. There are some flaws with your current method though. For x, you could use the following: tempx += speed * dt while (tempx > 0.5) move sprite to x+1 tempx -= 1 while (tempx < -0.5) move sprite to x-1 tempx += 1 this should be better. I've switched the if ...


14

One way in which many old-skool games solved (or hid) this problem was to animate the sprite. That is, if your sprite was going to move less than one pixel per frame (or, especially, if the pixels/frame ratio was going to be something odd like 2 pixels in 3 frames), you could hide the jerkiness by making an n frame animation loop that, over those n frames, ...


13

Found a solution from some resource. Go to Global Game Settings, then go to any platform spoiler(for example "Windows" or "Android"), there choose the spoiler titled "Graphics" and toggle "Interpolate colors between pixels" off. Have fun :)


10

The quick-and-dirty solution would be to use a camera filter effect. The color correction curves filter might do what you want. Move the end-points of the R, G and B curve down, but the blue-curve a bit less. If you don't want it to affect some objects (like your GUI, for example), render them with a different camera. But the problem with this is that you ...


9

Talking about the "best choice" is always difficult, as long as you did not specify the task that you intend to perform in all detail. But here are several aspects to consider. First of all: Java is not C. The memory management is completely different, so one has to be very careful when trying to apply insights from one programming environment to another. ...


6

This is called mipmaping, It looks like you are missing out on mipmaping for your textures. this causes a huge impact on visuals. And when it comes to mipmaping Normals, Specular and other "information" textures, it gets quite tricky. the reason for this is that when objects gets further away, the gpu has to take this into account and calculate the ...


6

You can reduce the instruction count by using vector operations: e.g. instead of edr = bool4((w1.x < w2.x) && ir_lv1.x, (w1.y < w2.y) && ir_lv1.y, (w1.z < w2.z) && ir_lv1.z, (w1.w < w2.w) && ir_lv1.w); you can write edr = (w1 < w2) && ir_lv1; Operators in HLSL ...


6

I got this working. It does not use the hqx filter, it uses the xBR filter (which I prefer). For me, this is not a problem. If you require the hqx filter then you'll want to convert the .cg files into their appropriate XNA equivalent. For completeness and searching reasons, I will be editing the question to be more concise and then posting all the relevant ...


6

The sprite's position should be kept as a floating point quantity, and rounded to an integer only just before display. You can also maintain the sprite at super resolution and downsample the sprite before display. If you maintained the sprite at 3x display resolution,you'd have 9 different actual sprites depending on the subpixel position of the sprite.


5

Nobody wants to deal with having to manually scale up every sprite; not only is it a sloppy workspace but it yields to be very unprofessional. I found a solution when turning off interpolation in global game settings didn't work. texture_set_interpolation(false); :) I hope this helps you in your future endeavors.


5

When the sprite is obscured by an object, you could make that object transparent: You can make a sprite transparent in Unity by setting the alpha-value of the sprite color. Color tmp = sprite.GetComponent<SpriteRenderer>().color; tmp.a = 0.5f; tmp.GetComponent<SpriteRenderer>().color = tmp; Another option is to just draw the outlines when the ...


5

It seems like you have 2 questions here: 1. Why doesn't this code change the surface? 2. Is there a way to do this faster? Why doesn't this code work? For me, opening a window, grabbing the screen surface, and writing to the pixels with the function you have there works perfectly fine, so the problem is likely not in your SetPixels function. Instead, it's ...


4

These are all good answers but nobody explained the reason why you need to access the pixels in the way you do. The pixel data is a one dimensional array. For a 10x10 screen, the following is how you can visualize the data being set up. // This is how it is actually setup unsigned int data[100]; // This is how people envision it being setup unsigned int ...


4

Textures mapped onto the surfaces of 3D geometry were developed to represent, well, surface texture. This type of detail usually doesn't align precisely with the grid of screen pixels, due to varying object sizes, distances, orientations, and camera perspectives, so it doesn't include any built-in features to snap the sampled texels to screen pixels. In fact,...


3

The only real solution here is to use bilinear filtering. The idea is to let the GPU compute the value of each pixel based on the four sprite pixels that are overlapping with it. It's a common and effective technique. You simply need to place the sprite on a 2d-plain (a billboard) as a texture; then use the GPU to render these plains. This works well but ...


3

If you want to draw a line "by hand" then you can use Bresenham's Algorithm. The algorythm take two 2d points and draws a line. So given point A and a length L , here is how you compute point B to draw the line from A to B (depending on the axis: x from left to right, y from down to up) point2d B; B.x = cos(Angle) * L + A.x; B.y = sin(Angle) * L + A.y;


3

This was a bad question, i admit it. But for who ever that comes along later i solved the 2nd quesiton like this. var bounds = gameObject.renderer.bounds.max.x;


3

First, I would like to point out that doing rotation for a bitmap image is slightly different from doing it in OpenGL or DirectX because the rendering API will usually take care of a lot of the details. Two reasons why this is the case Using a rotation matrix that have a sin/cos will often result in fractions that cannot be indexed directly in the buffer. ...


3

glOrtho( 0.f, viewWidth, viewHeight, 0.f, 0.f, 1.f ); Assuming that you're starting from an identity matrix, this glOrtho() call will give you a traditional window coordinate system with 0,0 at the top left corner, such that one unit in OpenGL space corresponds exactly to one pixel in the view which contains the OpenGL-rendered image. Man page for glOrtho.


3

I sample image data for my color picker utility. Raycasting will effectively return all objects that were clicked on, regardless if they appear underneath another one. So first, you need to extract the image color data. Color[] Data; SpriteRenderer SpriteRenderer; public int Width { get { return SpriteRenderer.sprite.texture.width; } } public int ...


3

I think you should flood from the outside, start with the bounding box of your snake path and the island and then use the unmarked edge pixels as a seed to flood your "true" outside. Then you can mark the inverse as your island. The issue with flooding from the inside, is that you will have to keep track of which flooded pixel belong to which seed, since ...


3

I have two methods for doing this I will post them both. Code is in VB.net and using sharpDX 3.0.2 Basically you copy your texture data to a staging resource and then write that staging resource to disk using WIC. If I recall I may have pulled this out of the SharpDX.Toolkit, DrawContext is just a wrapper around Device context so it should just be a name ...


3

Instead of texture.SetPixel, use texture.SetPixels var texture = new Texture2D(Screen.width, Screen.height); Color[] pixels = Enumerable.Repeat(color, Screen.width * Screen.height).ToArray(); texture.SetPixels(pixels); texture.Apply(); return texture; Using texture.LoadRawTextureData might be even faster, but this requires that you know more about your ...


3

The thing is, it might be either. 256 colors is not recommended mostly due to it being simply overkill for pixel art, since all we need is usually as fewer colors as possible to imitate visual style of the old consoles. Considering how limited some consoles were, 8 colours for an entire game might be a realistic choice, but in the end it all boils down to ...


Only top voted, non community-wiki answers of a minimum length are eligible