Archive for category Shader Code Snippet
BitField in Shaders (SM 3 and before)
Posted by tpastor in Computacao Grafica, Shader Code Snippet on 19 de março de 2013
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 »
Phong Tessellation with Geometry Shader
Posted by tpastor in All Posts, DirectX 11, Shader Code Snippet on 25 de novembro de 2011
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.
Code Snippet : Fog Shader
Posted by tpastor in Shader Code Snippet, XNA on 16 de novembro de 2011
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).
Code Snipped: Night Vision Shader
Posted by tpastor in All Posts, Shader Code Snippet on 1 de outubro de 2011
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.
Code Snipped : Thermal Vision
Posted by bruno.duartec in All Posts, Shader Code Snippet on 23 de setembro de 2011
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 »
Spot Light with Soft Shadow Shader
Posted by tpastor in All Posts, Shader Code Snippet, XNA on 20 de setembro de 2011

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 »
Code Snipped: Contrast Shader
Posted by tpastor in All Posts, Shader Code Snippet on 10 de setembro de 2011
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
Code Snippet: Radial Blur shader
Posted by tpastor in Shader Code Snippet on 5 de setembro de 2011

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 »
Code Snippet: HSV to RGB and Vice versa in Shader
Posted by tpastor in Shader Code Snippet on 26 de julho de 2011
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):
Code Snippet: Classic Effects (Bump, Specular and Paralax) in Shader [HLSL]
Posted by tpastor in All Posts, Computacao Grafica, Shader Code Snippet on 21 de julho de 2011
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”.








