Hi guys
Blender 2.6 are bringing to us many new features, one of that is the possibility of get the pure GLSL code of one Blender material with the command “gpu.export_shader(Scene,mat)”. It´s a really great tool if you want to use the Amazing BGE material editor and export it for another game engine. Or if you’re just curious
Its a simple command but it can be more simple for a end-user. So i did a little add-on to export the materials as GLSL (vert and frag) code.
Its really simple to use:
Turn On the Add on in the Preferences Panel ( File/User Preferences):
It will add a new panel in Material Properties:
Select one of this Three Options:
-> Active Material: Export Just the active material of this object
-> Selected Objects Materials : Export all materials of the selected objects
-> All Materials : Export all materials datablocks ( even it not linked to a object)
So click in Export
It will open the file browser, select the directory and click in Export.
It make two files per material: .frag to fragment shader and .vert to vertex shader
Names are not necessary. it always name the files with mat_<material_name>
A exemple with the default Material and one light in scene:
Vertex Shader
varying vec3 varposition;
varying vec3 varnormal;
void main()
{
vec4 co = gl_ModelViewMatrix * gl_Vertex;
varposition = co.xyz;
varnormal = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ProjectionMatrix * co;
}
The fragment is too long to post here so i did it in pastall
http://www.pasteall.org/25417
The bad news is: now we can see how messy it is
Especially if you add more lamps in the scene, i just hope the GLSL compiler make a good job to optimize it
DOWNLOAD
OBS: Only for blender 2.6 or above so use a graphicall build or the 2.6 RC
Tracker:
http://projects.blender.org/tracker/index.php?func=detail&aid=28839&group_id=153&atid=467
Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Game_Engine/Export_GLSL
This is it, if there is some doubts just say. Suggestions are welcome too