Hot answers tagged

50

This looks like the bottom layer of a volume texture that many games these days use to perform color correction. The idea is that the final RGB screen color, after rendering and tonemapping, is used as a texture coordinate to index into this texture, and the color found in the texture replaces the original color. This allows artists to arbitrarily modify ...


42

Internally, GPUs never run one instance of a pixel shader at a time. At the finest level of granularity, they are always running 32-64 pixels at the same time using a SIMD architecture. Within this, the pixels are further organized into 2x2 quads, so each group of 4 consecutive pixels in the SIMD vector corresponds to a 2x2 block of pixels on screen. ...


26

The physical basis of the colors of an oil slick is iridescence, and also related to Newton's rings. Specifically, the thickness of the oil layer is on the order of the wavelength of light. Since light reflects from both the top and bottom surface of the oil, at any given wavelength, at some angles the two reflections will be out of phase and cancel each ...


17

First, it helps to know that GPUs always evaluate fragment/pixel shaders on 2x2 blocks of pixels at a time. (Even if only some of those pixels ultimately need to be drawn, while others are outside the polygon or occluded - the unneeded fragments are masked out instead of being written at the end). The screenspace derivative of a variable (or expression) v ...


17

It looks to me like you want something like this: Shader "Unlit/BrightSpiral" { Properties { _Turns ("Turns", float) = 3 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma ...


14

Actually no, the 'job' of the geometry shader (GS) is primative evaluation. Geometry shaders can tesselate, but they are limited by a) an in-process upper bounds on the number of output elements, and b) execution within a single shader...of course shader instancing aleviates the 2nd issue, but overall geometry shaders are more effective at primative ...


11

Well, a lot of stuff happens between the Vertex and Pixel shaders, but before we get into that, I'm worried that you may be a bit confused about what the Vertex and Pixel shaders do. So let's quickly go through the entire Direct3D 9 programmable pipeline again. This nice chart shows the entire pipeline, and you should print it out for reference. (feel free ...


10

Well, when asked to design any shader, we should start by breaking things down to smaller problems. And just as note the glittering effect doesn't actually makes the shader looks good, but the overall lighting and effect, using only one of them won't look as good. First of all let us state what is not directly part of the shader: The shadowing is not ...


8

Short answer: yes, that formula is correct. Longer answer: if you think of a texture as being a grid of little squares, one for each texel, the actual color value stored in the texture can be thought of as being located at a point at the center of each texel square. So, in UV coordinates where the texture ranges from (0, 0) to (1, 1), the color samples are ...


8

I believe what you are looking for is called Deferred Rendering. It is a rendering technique that scales extremely well with a lot of lights, so well that it can used for dynamic indirect illumination. That means 1000s of lights on the screen. It is basically a technique in which you first render all your geometry data(position, normal, depth) into an ...


8

As far as I know, Unity uses Cg (which is deprecated by NVIDIA since 2012, I have no idea why they still use it) as its shader language (which is really similar to HLSL) instead of HLSL or GLSL as stated here: In Unity, shader programs are written in a variant of HLSL language (also called Cg but for most practical uses the two are the same). Later on, ...


7

There are two ways to set the stencil buffer value in Direct3D 11, one of which is only available in Direct3D 11.3 (and Direct3D 12). I will split this answer into two parts accordingly. Direct3D 11 General As part of the D3D11_DEPTH_STENCIL_DESC you specify what action to take on a stencil test pass and fail. These options boil down to: Keep the current ...


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.


7

it doesn't generate a quad, instead it generates a fullscreen triangle. The outputs end up as: output[0].texcoord = float2(0,0); output[0].position_cs = float4(-1, 1, 0, 1); output[1].texcoord = float2(2,0); output[1].position_cs = float4(3, 1, 0, 1); output[2].texcoord = float2(0,2); output[2].position_cs = float4(-1, -3, 0, 1); It goes beyond the ...


6

You need to make sure that any variable you use within the constant buffer does not cross a 16 byte alignment boundary, or you won't be able to access it from the shader. For example, you could have a constant buffer that looks like this: struct constant_buffer { XMFLOAT4X4 wvp; // 64 bytes -> 16 byte aligned = OK XMFLOAT3 position; // 12 ...


6

The default equation for attenuation f(x) = 1/( distance ^(exponent) ) from the images doesn't seem UDK is doing anything differently.


6

They are very different: smoothstep(x, y, z); basically does saturate((z-x)/(y-x)) and then smoothes the result to start and end smoothly. The result always lies between 0 and 1. lerp(x, y, z); returns z*y+(1-z)*x As long as x lies between 0 and 1 the result lies between x and y. What you want is saturate((z-x)/(y-x)) which gives you the same range as ...


6

Do they even serve any purpose at all? Yes for the user and developer of the shader, semantics conveys information about the intended use of a parameter. So you will know that POSITION is intended to be used as vertex position, NORMAL as vertex normal etc. Think of this as in-code documentation (not strictly the same though). Do semantics carry any ...


6

The key step that you're missing is the implicit slot assignment that occurs when you compile a shader. When you compile an HLSL shader that contains a bindable object (be it a Texture2D, RWStructuredBuffer, or cbuffer), each object must be assigned a slot number. This corresponds to the UINT StartSlot parameter to e.g. VSSetConstantBuffers. You can ...


6

VSSetConstantBuffers stands for VertexShaderSetConstantBuffers. Hence you also got PSSetConstantBuffers for the pixel shader.


6

I can't see anything fundamentally wrong with the shader, but here are a few things I find commonly done wrong with deferred shading that you might be doing. 1: Drawing full screen lights. The beauty of deferred shading is that you can pack your lights into geometry so that you only need to consider a part of the screen when drawing them (Like a cube with 2 ...


5

The tex2D function usually returns a float in the range of [0.0, 1.0]. Think of tex2D as a function that returns a color. Color components (like red, for example) range from 0.0 to 1.0 where the former is the total absence of that color and the latter is full intensity. However, as Nathan Reed and other members have pointed out, texture formats that are ...


5

Not unless you are using features that the target platform does not support. If you want to use Effect files from a previous XNA project or an XNA sample, you'll need to process them with the MonoGame Effect processor to compile them for that specific platform. Some of these use OpenGL rather than DirectX as their graphics API, so the Effect file from XNA ...


5

Anti-aliasing in a deferred shader is a complex topic. WikiPedia lists a number of techniques for doing anti-aliasing in a deferred-compatible way. Typically you'll need to do it after lighting, otherwise you can end up with lighting artifacts. Most approaches I know of do another pass on the scene after the entire deferred pipeline is complete. If you ...


5

With the introduction of programmable blending units, the intuitive meaning of alpha being a measure of opaqueness doesn't always hold. In the two-operand blend you have two contributing fragments: the source (what you're blending, the new fragment), the destination (what already exists in the spot you're blending to). You have two independent blending ...


5

Applying two normal maps is not that bad. Many games apply multiple normal maps already because they're blending between texture layers (e.g. for terrain), so having a normal map representing the larger displacements and another normal map for fine details is pretty reasonable. Check out Blending in Detail by Colin Barré-Brisebois and Stephen Hill for a ...


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