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


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


20

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


15

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


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

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


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

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

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


6

There's little point in converting your example to DirectCompute. It has no need to share data between pixels, so you are actually much better off doing a global tone-map operator in a Pixel Shader. A more interesting case would be in trying to do a local tone-map operator where pixels need to share data between them (something you can't do in a pixel ...


5

Just half3 result = (original + mycolor) / 2; does what you'd expect because the arithmetic operators are overridden for the half3 type.


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


5

Make sure you right click -> properties on each shader file and set the Shader Type as well. The property right above the shader model in your graphic.


5

Non-array struct members for constant buffers in HLSL are packed on four byte offsets, as many as it can into 16-byte vectors. If a member would straddle a vector boundary, it starts a new vector. You cannot achieve this with just an alignment and pack directive, you need to have explicit padding in your CPU-side structure to emulate the CB layout rules. ...


5

Problem is two-fold: Determine how many pixels the model will take when rendered Replace model with a dot Suggestions: Pick the cut-off distance by eye. So when the model is this big and this far - it should be replaced with a dot. I would make it a property of the ship. Render all models that are closer than their cutoff distance as usual. Do not render ...


5

Your image can be interpreted a couple different ways so I will make a few assumptions up front: The "geometry" you are emulating is meant to look as if it has already been "projected" (if it was plane geometry and ran through MVP matrices it would produce similar output). The planes are flat and not angled. The planes are both 0.5 units away from the ...


4

The specific registers you deal with syntactically will be some form of I/O register. Josh explained excellently what registers are and why they're used on the GPU. The syntax you use to declare variables in specific registers is for transferring data. On the CPU you create an Input Layout (Vertex Array Object in GL) or set uniforms or samplers/textures. ...


4

It was very easy finally. Here is the answer. I am using an external value. half3 original = half3(0.36, 0.74, 0.18); half3 mycolor = half3(1, 0, 0); half value = 0.5; half3 result = original * value + mycolor * (1 - value); You could also use mix(); or lerp(); depending on your platform.


4

You need to write: return float4(1.0f, 0.0f, 0.0f, 1.0f); The float4 is necessary to construct a vector. The way you've written it currently, the compiler is interpreting it as the comma operator. The result is that you only return the last element (the alpha component), which then gets replicated to all four components of the result.


4

First of all, you don't do your render in gamma space to get the same results as in linear, but to have "gamma correct" final image. The topic is a bit complicated, so see the link in the end of the answer if you want to learn about it in-depth. The process of applying gamma correction to your scene follows: (I've seen this in a presentation from a graphics ...


4

If you're using any form of deferred lighting/shading, you'll have problems with multisample antialiasing because pixel shaders normally only run once per pixel. When you do your lighting passes, the depth and normal values within each pixel will get averaged out before being seen by the shader. This will cause problems at edges, where you have very ...


4

For best performance you should avoid changing uniforms as well as shaders by using vertex attributes. Ideally pack all your 2D object textures into 1 single large texture (called an atlas) so you can render all your 2D objects in one call using a single vertex buffer. In your large texture you also put a 4x4 white area and map the texture coordinates of ...


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