Material & Shaders editor
Posted: Tue May 22, 2012 10:05 am
Hi!
Here's a little tool that lets you edit ".material" and ".fx" files and see the results in (almost) real-time.
The preview is obtained by killing and re-launching a second exe as a child window every time a change is made in the editor.

Download it here: http://keleb.free.fr/codecorner/downloa ... Editor.zip
It contains the sources for the editor (materialEditor.pb) and the preview (materialPreview.pb), the Visual Editor file, icons, etc..
Quite a lot of things are included in the editor's exe via "includeBinary": the preview's exe, a default material with shader and textures, the teapot mesh, some PNGs... All these files are stored in the "included" folder.
For those who don't bother the code and simply want to try it, here's the compiled version (32bits Win):
http://keleb.free.fr/codecorner/downloa ... torExe.zip
Engine3D.dll is included: unzip it in some folder, and it should work (hopefully
).
How to use it:
- cursor keys + pageUp pageDown to move the camera in the preview;
- F5 to refresh the preview.
- The horizontal menu allows to save/load a project. The save files include the meshes, the textures, the shaders files, and the material file; all these are "packed" in the save file, and "unpacked" when loaded.
- The menu also allows to "export" a project: the material and all its dependancies are then unpacked to the target directory along with a short PB source that demonstrates how to use them.
- There are tooltips on every button; please read them if you're confused.
To import an existing material, no automation: you have to use the "import" buttons on each page of the panel gadget.
Example, with the "SphereMap" material in purebasic/examples/3d/data/scripts:
- On the "material" tab, click on the "import" button (first one, with a yellow folder on it) and choose "spheremap.material" => the file's content is loaded into the editor;
- On the "Shader" tab, delete all (this material doesn't use shaders. If it did, they would be referenced after the keyword "source" in the material);
- On the "Textures - meshes" tab, delete all the textures and import the two files used in the "textures units" of the material: "rustySteel.jpg" and "spheremap.png" (they are in purebasic/examples/3d/data/textures);
- Press "F5" to refresh the preview => it should work.
Limitations:
- The editor only manages a single material per ".Material" file, and a single ".Material" file per project. So one project = one material (but there's no limit on the number of meshes, shaders or textures files).
- When you enable the "ground" display, it also activates the shadows in "Modulative" mode, which may be annoying sometimes; I'll add a combo-box to select the type of shading later...
Well, that's it. There are still some bugs and unpractical things, but it is already quite usable and it speeds up the writing, tuning and conversion of materials for PB. I hope it will be useful!
Bonus: Two material projects to load in the editor
http://keleb.free.fr/codecorner/downloa ... iLight.pbm
http://keleb.free.fr/codecorner/downloa ... olcano.pbm
[EDIT] Updated to PB v5.00b2
Here's a little tool that lets you edit ".material" and ".fx" files and see the results in (almost) real-time.
The preview is obtained by killing and re-launching a second exe as a child window every time a change is made in the editor.

Download it here: http://keleb.free.fr/codecorner/downloa ... Editor.zip
It contains the sources for the editor (materialEditor.pb) and the preview (materialPreview.pb), the Visual Editor file, icons, etc..
Quite a lot of things are included in the editor's exe via "includeBinary": the preview's exe, a default material with shader and textures, the teapot mesh, some PNGs... All these files are stored in the "included" folder.
For those who don't bother the code and simply want to try it, here's the compiled version (32bits Win):
http://keleb.free.fr/codecorner/downloa ... torExe.zip
Engine3D.dll is included: unzip it in some folder, and it should work (hopefully

How to use it:
- cursor keys + pageUp pageDown to move the camera in the preview;
- F5 to refresh the preview.
- The horizontal menu allows to save/load a project. The save files include the meshes, the textures, the shaders files, and the material file; all these are "packed" in the save file, and "unpacked" when loaded.
- The menu also allows to "export" a project: the material and all its dependancies are then unpacked to the target directory along with a short PB source that demonstrates how to use them.
- There are tooltips on every button; please read them if you're confused.
To import an existing material, no automation: you have to use the "import" buttons on each page of the panel gadget.
Example, with the "SphereMap" material in purebasic/examples/3d/data/scripts:
- On the "material" tab, click on the "import" button (first one, with a yellow folder on it) and choose "spheremap.material" => the file's content is loaded into the editor;
- On the "Shader" tab, delete all (this material doesn't use shaders. If it did, they would be referenced after the keyword "source" in the material);
- On the "Textures - meshes" tab, delete all the textures and import the two files used in the "textures units" of the material: "rustySteel.jpg" and "spheremap.png" (they are in purebasic/examples/3d/data/textures);
- Press "F5" to refresh the preview => it should work.
Limitations:
- The editor only manages a single material per ".Material" file, and a single ".Material" file per project. So one project = one material (but there's no limit on the number of meshes, shaders or textures files).
- When you enable the "ground" display, it also activates the shadows in "Modulative" mode, which may be annoying sometimes; I'll add a combo-box to select the type of shading later...
Well, that's it. There are still some bugs and unpractical things, but it is already quite usable and it speeds up the writing, tuning and conversion of materials for PB. I hope it will be useful!

Bonus: Two material projects to load in the editor
http://keleb.free.fr/codecorner/downloa ... iLight.pbm
http://keleb.free.fr/codecorner/downloa ... olcano.pbm
[EDIT] Updated to PB v5.00b2