Archive for category Shader Code Snippet
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 »
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.
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).
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.
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 »
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 »
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
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 »
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):
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”.