Archive for category Shader Code Snippet

BitField in Shaders (SM 3 and before)

Sometimes we need to encode lots of boolean flags in a texture channel and recover it in a shader. I found that shader model 3 and before dont have bitwise operations (they only support floats … that dont have this …) !!!
Fortunately i found some help on the old good float math and i managed to solve this even on SM 2.
Leia o resto desse post »

, , ,

51.130 Comentários

Phong Tessellation with Geometry Shader

First of all, implementing Phong Tessellation using Geometry Shader is NOT a good idea at all since now we have the Directx 11 Tessellator unit !!!!
But when i implemented this we did not. And after all, the DirectX 11 implementation uses almost the same shaders idea showed in this post.

Leia o resto desse post »

, ,

23.856 Comentários

Code Snippet : Fog Shader

In this code snippet we are going to show some simple ways to create a fog like effect in 3D games.
The fog effect is a post process (operates on a full screen quad) that recieves the framebuffer texture (the one with the game rendered content) and a depth texture as main parameters.
The depth texture (used normally in deferred shading) contains the post projected Z/W coordinate of all objects (the Z buffer content actually =P).

Leia o resto desse post »

, , ,

20.549 Comentários

Code Snipped: Night Vision Shader

This post effect is pretty cool and simple to build.
We tried to achieve two things, make the green like effect and add some random noise to the final image.

Different from almost all Code Snipped, we will try to explain this effect in a simple way.

Leia o resto desse post »

, , ,

39.984 Comentários

Code Snipped : Thermal Vision

This is a simple pixel shader. We recover the texture information and apply a simple transformation. We can reach a good result with this shader. We don´t reach physical results but good ones. Leia o resto desse post »

47.317 Comentários

Spot Light with Soft Shadow Shader

This post shows some shaders used to create a Shadow effect using the classic technic Shadow Mapping. The objective of this post is not to explaint how shadows are calculated, we are only going to show the shaders, the creation of the render targets for example will not be shown. Leia o resto desse post »

16.916 Comentários

Code Snipped: Contrast Shader

This simple post effect shows how to change the constrast of an image.
We just recover the texture color and apply a simple approximated Contrast equation.

This approach is very simple and give good results

Leia o resto desse post »


34.404 Comentários

Code Snippet: Radial Blur shader

This short code snipped will show how to make a simple radial blur as a post effect pass. The effect is cool and the code is preeeetty simple.
Leia o resto desse post »


18.824 Comentários

Code Snippet: HSV to RGB and Vice versa in Shader

This Code snipped will show two custom operation that we normally need to use in our post effect shaders. They are the conversion between the RGB space to HSV and vice versa.

The shader is pretty simple and is shown below (this code is used inside a post effect, you can grab the HSVtoRBG and the RGBtoHSV functions and use at your own):

Leia o resto desse post »

, ,

30.220 Comentários

Code Snippet: Classic Effects (Bump, Specular and Paralax) in Shader [HLSL]

This code snippet will show how to combine some classical effects like Bump Mapping, Specular Mapping and Paralax Mapping (the simple one, not the Paralax Occlusion Mapping) in a single shader.

Pay attention that we are not being ” very careful”, some parts can be correted to be more “Mathematical perfect”.

Leia o resto desse post »

, , , , ,

35.925 Comentários