# Tag Info

25

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

22

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.

21

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

17

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

15

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

14

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

7

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

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

6

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

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

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

6

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.

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

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

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

There is, in the fragment shader, a variable called gl_FragCoord. This contains the coordinates of the currently executing fragment shader. Note that (by default) a pixel at pixel coordinates (x,y) will have gl_FragCoordinates of (x+0.5,y+0.5)

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

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

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

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

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