Is it possible to convert GLSL -> ARB_*

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
BadKarma
Posts: 5
Joined: Mon Jul 03, 2006 12:38 am

Is it possible to convert GLSL -> ARB_*

Post by BadKarma »

Greetings fellow Irrlicht(ers?).

First let me say that I've been around the block once or twice with numerous game and rendering enignes and Irrlicht just plain knocks the socks off anything I've used to date! =)

On to the point:

I have a very simple shader, consisting of a vert and fragment shader generated in Rendermonkey.

The application I'm currently building is OpenGL 1.5, which, as some of you may know, doesn't support GLSL, which is what Rendermonkey puts out.

Does anyone know of a way to convert these...

Code: Select all

// Vertex Shader
// --------------------------------------------------------------

uniform vec3 fvLightPosition;
uniform vec3 fvEyePosition;

varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
   
void main( void )
{
   gl_Position = ftransform();
   Texcoord    = gl_MultiTexCoord0.xy;
    
   vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;
   
   ViewDirection  = fvEyePosition - fvObjectPosition.xyz;
   LightDirection = fvLightPosition - fvObjectPosition.xyz;
   Normal         = gl_NormalMatrix * gl_Normal;
   
}

// Fragment Shader
// --------------------------------------------------------------
uniform vec4 fvAmbient;
uniform vec4 fvSpecular;
uniform vec4 fvDiffuse;
uniform float fSpecularPower;

uniform sampler2D baseMap;

varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;

void main( void )
{
   vec3  fvLightDirection = normalize( LightDirection );
   vec3  fvNormal         = normalize( Normal );
   float fNDotL           = dot( fvNormal, fvLightDirection ); 
   
   vec3  fvReflection     = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection ); 
   vec3  fvViewDirection  = normalize( ViewDirection );
   float fRDotV           = max( 0.0, dot( fvReflection, fvViewDirection ) );
   
   vec4  fvBaseColor      = texture2D( baseMap, Texcoord );
   
   vec4  fvTotalAmbient   = fvAmbient * fvBaseColor; 
   vec4  fvTotalDiffuse   = fvDiffuse * fNDotL * fvBaseColor; 
   vec4  fvTotalSpecular  = fvSpecular * ( pow( fRDotV, fSpecularPower ) );
  
   gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular );
       
}
...into a viable format for Irrlicht/ OpenGL 1.5?

Thanks in advance for any pointers. =)
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

GLSL would work on nvidia (fx range and above) cards but if u want opengl shaders then assembler shaders are the way to go.

there seem to be converters from hlsl to dx assembler

but i cant find a glsl to assembler converter
if anyone encounters one then please reply here
BadKarma
Posts: 5
Joined: Mon Jul 03, 2006 12:38 am

Post by BadKarma »

I'm definitely looking to convert to OpenGL assembly (ARB_vertex_program & ARB_fragment_program respectively).

Unfortunately, there don't appear to be any tools available to convert GLSL -> assembly... which sucks since I really need the cross-platform capabilities of OpenGL.

Ironically, I could get an assembly version of an HLSL shader rather easily. Pfffft. =\
BadKarma
Posts: 5
Joined: Mon Jul 03, 2006 12:38 am

Post by BadKarma »

This is going to take more research on my part, but I'll post my results when find the time to try this.

Here's the possible pipeline:

Rendermonkey -> HLSL -> DX Assembly -> OpenGL Assembly

Got this idea when I realized that this tool was available from Nvidia.

[Edit]

Now that I look again, I see that it converts for the NV_vertex_program extension, which I'd assume is proprietary... unlike ARB_vertex_program.

Never- friggin - mind. >(

[Edit #2]

I'm now researching the following:

HLSL-> CG Compiler -> ARB_*

We'll see...
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

The route over Cg is more promising for sure. Though still Cg is not known for creating superior code. If all you want to do is to convert your shader to arbvp1/fp1, then I'd go through the errant to convert it by hand. Else there is always Cg.

What cards do you want to support, which don't yet support the GLSL extension? GLSL is available not only since OpenGL 2.0
No offense :)
BadKarma
Posts: 5
Joined: Mon Jul 03, 2006 12:38 am

Post by BadKarma »

I want the widest card support can get for this.

To be clear, the project is not shader intensive, but they play an integral role in the asthetic I'm shooting for, which is an odd blend of NPR techniques.

Obviously, I'll read from the card during execution and shut off shaders for those with non-programmable GPU's, but for those with, I want everything to work as well as possible - which means OpenGL for cross-platform compatibility and ARB_frag/ vert programs for shaders - which gets me all the way back to GF2 era GPU's.

Clear as mud?

The issue with converting by hand is that I just don't know, nor do I clearly understand the assembly side of things - I have no experience with shaders (this is my "experiment" to familiarize myself with their use, I'm not looking to become a shader guru or anything, just be able to employ them in code).

Having said that, writing to assembly is a heck of a lot more difficult/ intimidating than just having Rendermonkey generate seomthing I can copy and paste. (C;
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

Geforce2 doesn't support arbvp/fp1. The best you can get there is GL_NV_register_combiners and you probably don't want that. ;)

Anyway, with no shader experience I don't see how you can convert your shader. GLSL is (unlike HLSL) not compiled to assembler before application, but the driver uploads the compiled machine code directly to the graphics card without an intermediate step.

Cg is really your best bet here imho, but still not easily done without shader knowledge. You had to convert your shader from GLSL to Cg, which is rather easily done. And then downgrade a bit probably, because IIRC some operations like normalize() are not supported for arbfp1. Anyway to Cg is much easier than to arbfp1 directly. So learn a bit and take this route. :)
No offense :)
Post Reply