woensdag 9 juli 2008

Shader Editor


I started the other night creating a shader editor, because editing the material files by hand, is a tedious job, everything has to be spelled correctly, otherwise textures won't load, fragment programs won't run etc. etc.

On the upper-right there is going to be a realtime preview. there are 3 tabs the most obvious ones on this pic are the vertex & fragment shader, the texture panel is going to be an openGLCanvas where all supported textures can be dropped on so one could choose what kind of texture it is, as well as setting it's properties, of that texture stage, rotation, scaling etc. When pressed 'ok' a new Material file will be generated and added to the list. Which is much nicer, than editing everything by hand, I wanted to start integrating the entity handling events this week, but i will first finish this.

Paul

vrijdag 4 juli 2008

omni lights


WOW:)
Omni lights are working now,

The biggest problem was that i didnt set up the correct(modelview) matrices for the cubemap, i just 'debugged' the code by drawing the 6 frusta of the omni.
What i am doing now is rendering the squared distances of the light into an floating point cubemap, which i use in turn in the shadow shader to see if the fragment is in shadow or not.
here is the fragment shader, needs to be cleaned up still:

uniform sampler2D tex0; //diffusetex
uniform sampler2D tex1; //normaltex
uniform sampler2D tex2; //depth texture
uniform samplerCube tex3; //shadow tex
uniform vec3 lightPos; //light pos
uniform vec3 lightColor; //light color
uniform float lightRadius; //raidus
uniform mat4 invMat; //inv projmv mat
varying vec3 camPos; //camera position
varying vec2 texCoord;
varying vec4 dir;
uniform float lightScale;


void main()
{
vec4 base = texture2D(tex0, texCoord);
vec3 bump = normalize(texture2D(tex1, texCoord).xyz* 2.0 - 1.0);
float depth = texture2D(tex2, texCoord).r;
vec4 worldPos = invMat * vec4( (texCoord*2.0)-1.0, depth * 2.0 - 1.0, 1.0 );
worldPos.xyz /=worldPos.w;
vec3 lDir =(lightPos - worldPos.xyz);
float distanceSqr = dot(lDir, lDir);
float distance = sqrt(distanceSqr);
float att=max(0.0, 1.0 - distance/lightRadius)*lightScale;
lDir = normalize(lDir);
float shadow = textureCube(tex3, -lDir).r;
float shadowColor = ((distanceSqr)>shadow) ? 1.0 : 0.0;
float diff = max(0.0, dot(lDir, bump));
vec4 final_color = vec4(0.0, 0.0, 0.0, 0.0);
if(diff > 0.0)
{
final_color += base * diff * att * vec4(lightColor, 1.0)*lightScale;
}
//vec4 color =
gl_FragColor = final_color*shadowColor;
}