Freitag, 28. Februar 2014

Tangent Space Normal Mapping without storing Tangents

After experimenting with the tangent space normal maps, it turned out that its possible to compute the tangent space in the vertex shader quite fast, which saves memory and bandwidth for rendering. Since the light computation is in camera space, tangent and co-tangent can be approximated as follows in the vertex shader:

VS

normal = normalize((gl_ModelViewMatrix* vec4(gl_Normal.xyz,0.0)).xyz);
tex_tan = cross(normal.xyz,vec3(0,-1,0));
tex_cotan = cross(normal.xyz,tex_tan);
tex_uv = gl_MultiTexCoord0.xy;

For the fragment shader, we need to first get the direction of the texturing by using the derivatives before we can compute the pertubed normal vector as follows:

FS

vec3 bump=vec3(-1.0,-1.0,-1.0)+2.0*texture2D(texBump,tex_uv).xyz;
vec2 tdx=normalize(dFdx(tex_uv));  // tex coord derivative in x
vec2 tdy=normalize(dFdy(tex_uv));  // tex coord derivative in y
vec3 n =bump.z*normal              // Z-direction of the normalmap
       +bump.x*(tdx.x*tex_tan+tdx.y*tex_cotan) // X-direction 
       +bump.y*(tdy.x*tex_tan+tdy.y*tex_cotan);// Y-direction 
n=normalize(n);

Its obviously an approximation, but so far I am satisfied with the result.
Note that mirrored UV's will need special treatment which is not included above.

Update: Using the geometry shader for computing the (tdx.x*tex_tan+tdx.y*tex_cotan) terms might improve the performance.


Mittwoch, 26. Februar 2014

On the Run

Jogging through the mountain scape


Montag, 24. Februar 2014

Protagonist in the Scene

After rewriting the skinning (now GPU skinning) and adding light & texturing (not yet shadows though), the protagonist is in the scene! Some of you might recognize ;)

The previous MD5 skinning had the drawback not all modeling environments were supported well. The new version is now OGRE based. It has the advantage that the exporter is open source and always kept up to date for new versions of Maya, Blender and more due to its active community.


Mittwoch, 12. Februar 2014

Skeletal Animation

Next important step tackled: Character Animation. Skinning works, bump & shading need to be added.




Samstag, 8. Februar 2014

High Detail for Close Geometry

Using multiple texture layers, also close geometry can be very detailed. Thanks to ClipMaps, it is not necessary to use any tessellation or any raycasting based mapping technique as it inherently provides sufficient details.









Donnerstag, 6. Februar 2014

Cubic Texture Sampling, Walkthru Mode and Skybox

Few updates:
  • 1st person walkthru mode
  • Skybox
  • Cubic heightmap sampling, so closeup geometry remains smooth
  • Cubic texure sampling, so snow does not have aliasing anymore
  • More fine details for the heightmap



Samstag, 1. Februar 2014

Textured Procedural DLA Terrain [Demo included]

First screenshot using textures. Its based on the Tutorial code below. I have increased the detail, therefore the framerate is lower than the sample. Will still take a while until it can be integrated into the voxel engine though.
You can fetch the demo here: [-DOWNLOAD-] (64MB)
Update: Bugfix for glsl.h line 35( thx Aransentin ) & Added multitexturing for closeup details.