33

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.


28

A general outline: Create a depth map of your scene without the shield. You can get this effectively for free, since transparent objects are often rendered in a later pass anyway. Otherwise, you can create the depth map by rendering the scene sans shield onto an RTT with a depth shader. Render your scene normally, pass the depth map to your shield shader. ...


24

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 ...


22

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 - ...


18

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

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 ...


10

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 ...


10

To achieve this effect my friend has created a custom sprite, we played around with all sorts of sprites and you can customize this part to your liking. The shader I've written for this effect, takes in the sprite, makes the sprite grayscale, uses the color to make a colored version and uses the grayscale version together with the colored version to color ...


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 ...


7

The trick for rapid Gaussian blurring with GLSL is to take advantage of the fact that the GPU provides linear interpolation in hardware. Therefore, you can effectively sample four 2D pixels with a single prefetch or eight 3D voxels. By deciding where to sample you can weight the output. The definitive reference is Sigg and Hadwiger's "Fast Third-Order ...


7

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 ...


7

Set the filterMode of your textures to FilterMode.Point. This will use nearest-neighbor interpolation, which will result in blocky rendering. Note: Your Texture2D must also have a suitable graphicsFormat. The default is R8G8B8A8_UNorm which does not work with filterMode set to FilterMode.Point for some reason. TextureFormat.RGBA32 and other 32bit formats ...


7

Use several constant buffers and group variables together based on how often they change. If your variables are fairly static ( or just huge ) you may be better off converting values into a texture and extracting them in the shader.


6

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 ...


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 ...


6

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 ...


6

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 ...


6

Do I understand correctly that you want an effect somewhat like this? (If I'm way off, you may need to edit your question to include more description of what you're trying to do and why) Here I have a monochrome blue background image, and a cube with a material that displays a colour version of the same image, using screenspace UV coordinates. (Textures ...


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

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 gl_TexCoord[0].xy....


5

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 red, ...


5

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 ...


5

It's just using the depth map. It renders the world then renders the shield and takes a difference between the shield's rendered z value and the depth buffer z value to tint the pixel more white.


5

The calculation falls apart like so: If every one of those 3 million polygons rasterizes to at least one pixel on average, then doing the operation in the fragment shader still results in it being evaluated (up to) 3 million times, even if your screen or output buffer has only 2 million pixels. If each one rasterizes to two pixels on average, then you might ...


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

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

From the shader's perspective, a block-compressed texture like BC4/RGTC1 behaves just like any other texture; the GPU hardware automatically handles the block decompression and filtering on your behalf. BC4 is a single-channel texture, so you are correct: use texture2D() -- or texture() in more recent GL versions -- and the data you want will be in the ...


4

I've decided to go with a fragment shader approach via discontinuity filtering of the depth buffer. Reasons for this are: World vertex count is very, very high due to immense view distances, even with mesh LoD; I am doing a number of other fragment shader operations, such as DoF blur which can benefit by the same structures (box or gaussian sampling/...


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