PDA

View Full Version : convert almost any shader to arb vertex and fragment shaders



noeska
18-01-2008, 09:22 PM
It is possible to convert almost any shader format to arb vertex and fragment shaders. This is possible with the ati ashli viewer available at: http://ati.amd.com/developer/ashli.html . It converts from:
- Renderman Shaders
- HLSL Shaders (directx)
- GLSL Shaders (directx)
to ARB vertex and ARB fragment shaders.
At first i thought is was fixed to the examples supplied, but you can add your own scenes and shaders.
For Renderman shaders you need to modify: ashliViewerListRMan.dat
For GLSL Shaders you need to modify: ashliViewerListGLSL.dat
For HLSL Shaders you need to modify: ashliViewerListHLSL.dat
You will find these files in: C:\Program Files\ATI Technologies\Ashli Viewer 1.7.0\bin if you installed the ashli viewer in the default location.
The format for adding your own scene is:


program Ambient
shader basic.glsl
shader ambient.glsl
scene ambientduckie.scn


The program is the entry in the treeview and the sader and scene are showed when click on the + in the treeview. Each program needs to be seperated by a blank line.

The .glsl files and .scn file need to be in the ShadersGLSL subfolder.
Used textures need to be in the Textures subfolder and should be in .tga format.
Used models need to be in the Models subfolder and are in a custom format that should easy to understand:


Object("room") {
Specular3f(1.0, 1.0, 1.0);
// unique vertices: 9445
Normal3f(-0.000015, 0.997051, -0.076735);
Color3f(0.615686, 0.000000, 0.000000);
TexCoord2f(0, -30.370804, -12.178762);
Vertex3f(105.282875, 56.890732, -192.224258);

etc ...

// faces: 11785
// material Material #124
UseMaterial("simple");
Triangle(5491,5492,543);
Triangle(5494,5495,5496);

etc ...

Triangle(9364,9369,9362);
ObjectFit(2,1.0);
} /* end of object sofa */


But for the moment i am confused by how the triangle indices work.
More important are the material names as you can assign shaders to them in the .scn file. So for now i name my material after an material available in an object.

Setting up a scene with materials is done like this:


object rubberduckie
background ramp
rotate x 280
rotate z 45
translate z -3

material duckie
shader ambient.glsl
float Ka 1.0
float intensity1 1
color lightcolor1 1 1 1

vshader basic.glsl

lightparams
1 intensity1 lightcolor1
end

First you need to specify the model you want to use
Next a background (don't know where these are specified)
Next you specify how the object is positioned
Now we need to specify the materials
As you can see you can set default values for globals in the glsl shader. Also using one shader you can make multiple materials if your shader is flexible enough. The above is an basic scene. But things can get complicated.
Finaly you need to setup some lights.

On opening the scene you can compile arb fragment and vertex shaders that you can view and copy and post for use with your opengl application.
You can optimize shaders for nvidia and or ati video cards.

Oh before i forget you can also compile to directx shaders.

Ok this should get you started converting shaders to something less readeable... (be sure to keep your original :wink: )

chronozphere
19-01-2008, 12:41 PM
Cool... so you can actually "port" shaders to different shader languages :shock: :P ?



Oh before i forget you can also compile to directx shaders.


Do you mean that you can convert GLSL and Renderman shaders to HLSL shaders? That'd be awesome. :D

Thanx for sharing this!

noeska
19-01-2008, 03:31 PM
No it does not work that way. It creates assemby like shaders. So in the end result you see a lot of mov dp4 and such. It does convert renderman, hlsl and glsl to 'low level' shaders whilst keeping functionality. It does not convert between those formats. It works like a compiler that omits the binary step.

However ati is having a hlsl2glsl conversion tool at: http://sourceforge.net/projects/hlsl2glsl . But that only seems to convert from hlsl to glsl.

For creating renderman shaders i use shaderman version 7: http://www.dream.com.ua/thetool.html that is the previous version available at: http://www.dream.com.ua/theoldtool.html (and it supposed to be written in delphi!).

JSoftware
19-01-2008, 03:43 PM
I've heard somewhere that you could simply load the shader in whatever way it should be loaded in OpenGL and then read it with either the vertex or fragment program functions.

LoadGLSLShader('Shader.fp');
glGetProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, p, len);
I don't know if it actually works, it might be that it's only rumors or you'll have to call glGetProgramStringARB with other parameters or something :P

chronozphere
19-01-2008, 04:03 PM
No it does not work that way. It creates assemby like shaders. So in the end result you see a lot of mov dp4 and such. It does convert renderman, hlsl and glsl to 'low level' shaders whilst keeping functionality. It does not convert between those formats. It works like a compiler that omits the binary step.

Ok... but it does compile to DirectX :D That's a good thing!

noeska
21-01-2008, 09:32 PM
This might even be better:
conversion between glsl and hlsl should be possible using nvidia's cg available at: http://developer.nvidia.com/object/cg_toolkit.html

the following commands can be used (have not tested it yet):
cgc -oglsl -profile fp30unlimited some_wicked_shader.frag
cgc -oglsl -profile vp30 some_wicked_shader.vert
to create assembly like shaders, but hlsl and glsl are also targets, so conversion from glsl to hlsl should also be possible