Friday, January 29, 2010

Multi-tone car paint

I'm currently doing a little boat racing game for xbox 360 with a couple of friends, and so i temporarily left the wonders of Ogre3d, and started tackling with the XNA library. I'm currently very disapointed, i was thinking i would go from a render engine to another, but XNA is more of a graphics framework than a proper 3d render engine. It made me value Ogre even more. It's not just the material system (but that one is the one that hurts me more, damn), but nothing is structured there. There isn´t even a fucking Camera class or a Scene Graph structure. Bah. It has a really cool and strong community though. Anyway, i recently developed a car paint shader for the game. It has multi-tone (3 tones) fresnel interpolation, Flecks layer and environment mapping. I would really like to include also a wavy reflection normal mapping, i had it working, but somehow along the way i managed to screw it up, and this was already long overdue. Because of the fresnel nature this shader will work better on a curvy model, more thann a very perpendicular one, like the boat model we used (shiiiit).
So there you are, enjoy the pics, and the fx file.


























And Here is the link to the Fx file

Thursday, December 17, 2009

Fresnel

And now, ladies and gentlemen, the crown of glory, the combination of all the previous effects, chromatic dispersion refraction blended with reflection with the fresnel coefficient. Gives this crystal like effect, really cool, check it. This new stuff was only possible due to my recent aquisition, an Asus g72 Gamer Edition with a monstrous Nvidia 250GTX Graphics Card, Fuck Yeah!!


























Link for fresCode ---------> Ahere

Refraction

Once again it's on, a new shader simulating the refraction effect. In addition to this, i updated the previous links because i found some issues on the code.





























The link to the code ----> ZiLink

Tuesday, November 17, 2009

Reflections

Another bad-ass shader, now reflections are in order. I had a bad time doing this shader, because my shitty gpu started giving brain farts and doing wacko shit that i simply couldn´t understand, but when i switched to a proper nVidia 9600 Gt Card everything went smoothly, so watch out for this if you runnning this on crappy integrated intel hardware.


Screenshots for the ladies























And of couse hardcore, brutal, and yet extremely elegant (?) code

Wednesday, November 04, 2009

And now -- Spotlight effect

Fuck yeah, spotLight effect also rocking. I've added a new model to my batch, a simple, 4 vertex plane. I was thinking this would be the perfect model to test the new spotlight effect however, this showed a side-effect of the per-vertex lighting with this kind of lighting, because of the 4 vertex-only nature of the model, if the 4 vertex are not inside the light cone it goes completly dark. It's pretty obvious, because the calculations are going to be made only on the vertexes.
I think i'm stopping pasting the code blocks here and just giving the link to zip file with all the shaders and scripts, i'm not explaining the code anyways (if you want a really cool explanation of the code, go to the excellent cg tutorial free e-book).

The code ---> here

Here are some cool pics







Tuesday, November 03, 2009

Extending the Basic Lighting Function - Attenuation

Following the cg tutorial chapter on lighting i introduced now some light attenuation. This makes the effect that an object is brighter when the light is close and darker when the light is far. It depends on basically four parameters: Range, and constant, linear and quadratic fall-off.







struct Material
{
float4 Ka;
float4 Ke;
float4 Kd;
float4 Ks;
float shininess;
};

struct Light
{
float3 position; // Light Position
float4 diffuseColor; // Diffuse Color
float4 specularColor; // Specular Color
float range; // Light Range
float Kc; // Constant Attenuation Coefficient
float Kl; // Linear Attenuation Coefficient
float Kq; // Quadratic Attenuation Coefficient
};

float attenuationFunction(
float3 position,
Light light)
{
float d = distance(position, light.position);
return 1 / (light.Kc + light.Kl * d +
light.Kq * d * d);
}

float4 lighting(Material material,
Light light,
float4 globalAmbient,
float4 position,
float3 normal,
float3 eyePosition)
{
//Normalize the normal
normal = normalize(normal);

//Compute the ambient light
float4 ambient = globalAmbient * material.Ka;

//Compute the emissive term
float4 emissive = material.Ke;

//Compute the attenuation function
float attenuation = attenuationFunction(position, light);

//Compute the diffuse term
float3 lightVector = normalize(light.position - position);
float diffuseLight = max(dot(normal, lightVector), 0);
float4 diffuse = attenuation * material.Kd * light.diffuseColor * diffuseLight;

//Compute the specular term
float3 viewVector = normalize(eyePosition - position);
float3 halfAngleVector = normalize(lightVector + viewVector);
float specularLight = pow(max(dot(normal, halfAngleVector), 0), material.shininess);
if(diffuseLight <= 0) specularLight = 0; float4 specular = attenuation * material.Ks * light.specularColor * specularLight; return ambient + emissive + diffuse + specular; }



I'm also attaching a zip file with some sample shaders using the library, and the rest of ogre related material files ------> Here

Check the effect (the light is attached to the camera)