I’ve committed the first bits of my Google Summer of Code project (http://wiki.blender.org/index.php/User:Moguri/GSoC2010_BGE_Shaders)  to my Blender branch (http://svn.blender.org/svnroot/bf-blender/branches/soc-2010-moguri). Here is my message from the commit log:

Getting a start on my gsoc project:
* bf_gpu can now use custom shaders
* filenames for the shaders are currently being stored on the material
* RNA has access to the filenames of the custom shaders
* I’ve added a quick ui to the custom shaders for experimenting, it can be found in the material panel
* I’ve added stuff for geometry shaders as well, but they currently aren’t working right.
Here is a screenshot where I use a simple toon shader:
Me using a toon shader
Here is the vertex shader:
#version 120

varying vec3 varnormal, varpos;

void main()
{
	gl_Position = ftransform();
	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
	varnormal = (gl_NormalMatrix * gl_Normal);
	varpos = (gl_ModelViewMatrix * gl_Vertex).xyz;
}
And the fragment shader:
#version 120

varying vec3 varnormal, varpos;

void main()
{
	vec3 n, lightDir;
	float intensity, factor;

	vec4 colorMap = vec4(0.0, 0.0, 0.8, 1.0);

	n = normalize(varnormal);
	lightDir = normalize(gl_LightSource[0].position.xyz - varpos);
	intensity = max(dot(n, lightDir), 0.0);

	if (intensity > 0.60)
		factor = 1.0;
	else if (intensity > 0.25)
		factor = 0.7;
	else
		factor = 0.0;

	gl_FragColor = colorMap * vec4(factor, factor, factor, 1);

}
And the only material settings I used were the newly added custom shader options. 🙂
Advertisements