Tag Info

Hot answers tagged

17

Yes, you can implement Gaussian blur in one pass, by sampling all n^2 pixels in the kernel (for kernel width n). It's usually faster to run it on the rows and columns in two passes, since then you have O(n) pixels to sample rather than O(n^2). This is not an approximation, since Gaussian blur is mathematically separable.


14

For perfectly reflective surfaces Phong-model makes sense. However, where does the n in (R.V)^n of Phong-model for approximating rougher surfaces come from? Where is the theory that you have to raise the result of the dot product to the power except that it just appears to empirically give the proper result? For Blinn-model there's physically based ...


13

I think everybody's giving way too complicated solutions to this problem.. So first, we have the card (or whatever you want to draw), depicted here by (a). Next, we take a copy of it, fill it in black and run a gaussian blur on it (b). All of this happens in photoshop or whatever your favorite art tool is. Next, in-game, when we want to draw the card, ...


11

Graphics hardware can perform early depth-based culling of fragments before computing their color value (in other words, before running your fragment shader). Consequently, if you utilize any features that would affect that, such as discard, alpha-testing, or manipulating gl_FragDepth the hardware's ability to do that optimization will be compromised since ...


9

These functions will perform very badly. I suggest using functions that are written with the GPU in mind. Here are mine: vec3 rgb2hsv(vec3 c) { vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - ...


8

To answer your question let's look at how the typical OpenGL pipline works. Vertex Shader -> Geometry Shader (Optional) -> Clipping -> Rasterization -> Pixel Shader ---------------> Fragments Merge. I want to stress the fact that one pixel is not necessarily one fragment, multiple fragment can be combined to make one pixel, other fragments are discarded ...


6

Taking your example, you have a step function of the distance, which produces a perfectly hard (aliased) edge. A simple way to antialias the circle would be to turn that into a soft threshold, like: float distFromEdge = 1.0 - dist; // positive when inside the circle float thresholdWidth = 0.01; // a constant you'd tune to get the right level of softness ...


6

Unfortunately no. You cannot read from the current render target in a shader. You have two basic options: If the operation you would do with the read fragment color is simple enough that you can achieve it using blend state operations, you can use those. You can pass the color data you need into shader via some other resource, for example, a texture ...


6

What you are probably looking for is a form of edge detection before, after, or even before and after your Gaussian blur. Maybe a version of Sobel Edge Detection could work. I know your game is 2D but if the wiki page is too rough here's a tutorial on how to get it working in the UDK that might translate over better. Your edge detection only really has to ...


5

BlendState.AlphaBlend uses premultiplied blending so check out this for why you can a value of 0 for alpha and still have the pixel not be transparent (especially the last paragraph). So I believe what you need is in your shader is (I'm bad with shaders so take this with a grain of salt). c.a = clamp(c.a - 0.05, 0, 1); c.r = c.r * c.a; c.g = c.g * c.a; c.b ...


5

First of all, I think you meant to ask whether a 2-bit texture will be 16 times faster than a 32-bit texture, not slower. The answer is: sometimes. Performance of graphics hardware is a complex topic. It is a concurrent, pipelined system that contains many different processes operating simultaneously and passing data to one another. In general, the speed ...


5

SV_Position gives you the position in screen coordinates, not in a [0,1] range though but basically in pixel coordinates. The range will correspond to the D3D11_VIEWPORT you set, possibly something along the lines of: D3D11_VIEWPORT viewport = {0}; viewport.Width = 1280; viewport.Height = 720; So in order to get a [0,1] range again, for the colors, you ...


5

You can achieve the effect you are looking for by setting the color value to non-pure red. In the picture below I have drawn a circle with additive blending multiple times with small offsets. On the left the color is pure red (255, 0, 0) and on the right it is (255, 20, 5). From these you can calculate that to get full yellow, you need 255/20=13 overlapping ...


5

There are two problems here: You're including the center texel twice in the filter. You first initialize final as final = Texel(tex, texcoord.xy).rgb; but the same texel also gets sampled in the loop when i and j are both zero. That accounts for why you can still see the image of the unblurred circle mixed in with the blur. You're not doing a Gaussian ...


5

Actually, I think you yourself listed the reasons why Blinn is the default over Phong. Each reason you listed there is, in fact, an area where Blinn proves superior to Phong. Taken as a whole, all of these lead to Blinn being a better default than Phong. Is Blinn perfect? Is it better than Phong? No. But it is a reasonable default. Feel free to ...


4

I've not touched DX11, but in the shader you seem to expect sampler 0 to be the diffuse, with sampler 1 to be the normal map. When you set the textures on the C++ side, you seem to have the slots reversed from what I can see.


4

Maybe. The problem you'll likely run into with replacing math functions with a texture lookup is precision and range. The texture can only be so large, and you have to decide what region of the function's domain it's going to cover and how finely subdivided in the domain it needs to be. Then, with standard texture formats you have only 8 bits to encode ...


4

Since grayscale is a post-process effect it is very easy to integrate. You just have to make sure that before drawing the scene you set a rendertarget. This means that everything is being drawn to someplace in the videocard memory and not directly to the screen. After that you save the texture you get from the rendertarget and draw that as a full screen quad ...


4

Let's provide a complete answer. First: texture2D(TextureUnit, vec2(gl_TexCoord[0])) Since we're talking about RGTC, we're in GL 3.x+ land. You shouldn't be using texture2D anymore; just use texture. That way, if you change the type of TextureUnit, everything will still work. But that's minor. Also, vec(gl_TexCoord[0]) is better spelled ...


4

CG (as your tags indicate) supports the WPOS semantic in some profiles, for example this one. An input parameter bound to the WPOS semantic will get the window position (with the origin in the lower-left) of the fragment. Other languages, like GLSL, have similar predefined uniforms or inputs (gl_FragCoord for example), although the specifics of their value ...


4

You can't draw with multiple vertex or pixel shaders at the same time. GPUs don't work that way. To render objects with different shaders, you sequentially set one shader, draw the objects for it, set another shader, draw its objects, etc. for each (vertex, pixel) shader pair: set vertex shader in the device context set pixel shader in the device ...


4

A fragment pipe is a portion of the pixel pipeline that processes fragments. The more you have, the more you can parallelize fragment rendering. More is better, but like many things you get diminishing returns. You can learn more about the graphics pipeline here. The pixel pipeline is what's responsible for creating what goes in each pixel on screen, ...


4

After you bind your program (2 shaders) with useProgram function, shaders are run at every drawElements or drawArrays call. You can call those functions at every frame, 1000 times per frame, or once an hour. You can also examine the "work at the server" during the single drawElements call. Vertex (or fragment) shader should be run for every vertex (or ...


4

Missed mentioning that my intention is for clusters of point sprites with the same pigment (red) to additive blend to yellow and white. That right there is indicative of your problem. You cannot take a color value of (0.25, 0, 0), and add it to itself and get anything besides more red. It will not magically become yellow, then white. It will always be ...


4

You can, with a suitably recent version of GL, use the query objects support. See glGenQueries and glBeginQuery for documentation on their use. With this, you can use GL_SAMPLES_PASSED as the query type. Assuming you aren't doing anything to disable early-Z, this should get you close to what you're looking for, enough for performance measurements at the ...


4

You can do it easily with a couple of saturates: newValue = saturate(HSV.z * 2.0); //double value 0.0 to 0.5 => 0.0 to 1.0 newSaturation = (1.0 - (saturate(HSV.z - 0.5) * 2.0)) * HSV.y; The first line is relatively simple to understand. Saturate will clamp the result to the 0-1 range so values bigger than 0.5 will end up as 1.0 which is exactly what ...


4

You don't need to calculate the vector direction, you don't need this line vec3 incident = normalize ( lightPos - IN . worldPos ); Instead just pass the direction(incident) vector as a uniform variable, because direction light doesn't have a position (actually it's supposed to be positioned at infinity), so you pass it as a uniform so it's doesn't change ...


4

Here's how I would do this. First, make sure you have the object's UVs or world coords (which you can pass through from your vertex shader) available to you. If it's just a background, you could also just use fragment coords (gl_FragCoord). For instance, let's say we're using UV coords. A fragment shader with only: gl_FragColor = vec4(vec3(uv.x),1.0); will ...


3

Might I suggest that the simplest (and so probably the best) solution is not to use a custom shader at all. Simply have two sprites. The first sprite can be your "base" layer containing parts of the unit common to all teams. This can be colour with an alpha channel. And the second layer would contain only the team-coloured elements in grayscale with an ...


3

You should apply your shader AFTER your sprite has been rotated. If the whole scene has not been shaded yet and your sprites are actually pixelated, what you need is some kind of post-FX filter for your whole scene. Averaging regions of pixels will work ok. It's not exactly what you intend (it'll look kinda dithered when moving/rotating) but it might do the ...



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