Need help converting from ASM to GLSL

Hi everyone,

I have some legacy code which I am converting/porting to a new framework using Trolltech’s Qt framework. The version from 4.7 also has support for GLSL shaders. I have some shader code in my legacy application which is as follows. It is a fragment shader and not too complex (I think!)


char* szShader = new char[1024]; 
strcpy(szShader, "!!ARBfp1.0
"); 
strcat(szShader, "PARAM c[1] = { { 65535, 0.00390625, 256, 0.0039215689 } };
"); 
strcat(szShader, "TEMP R0;
"); 
strcat(szShader, "TEX R0.x, fragment.texcoord[0], texture[0], 2D;
"); 
strcat(szShader, "MUL R0.x, R0, c[0];
"); 
strcat(szShader, "MUL R0.y, R0.x, c[0];
"); 
strcat(szShader, "ABS R0.z, R0.y;
"); 
strcat(szShader, "FRC R0.z, R0;
"); 
strcat(szShader, "MUL R0.z, R0, c[0];
"); 
strcat(szShader, "FLR R0.y, R0;
"); 
strcat(szShader, "CMP R0.x, R0, -R0.z, R0.z;
"); 
strcat(szShader, "MUL_SAT R0.xy, R0, c[0].w;
"); 
strcat(szShader, "TEX result.color, R0, texture[1], 2D;
"); 
strcat(szShader, "END
\0"); 

I have actually never done any graphic programming and am quite stumped as to how I can convert this to higher level GLSL shader. Unfortunately, Qt does not support ASM shaders and I have been strugglng with this for the past few days.

I would be really grateful if someone can give me some pointers or can help me translate this to GLSL. Is there any free tools that might be available that go from ASM to the shader language of choice? I could not find one on the net.

Many thanks. I appreciate any help you can give me.

Cheers,
Anja


uniform sampler2D texture0;
uniform sampler2D texture1;

varying vec2 texcoord0;

void main(){

vec4 c0 = vec4(65535, 0.00390625, 256, 0.0039215689);

vec4 r0 = texture(texture0,texcoord0);
r0.x *= c0.x;
r0.y = r0.x*c0.x;
r0.z =  abs(r0.y);
r0.z = frac(r0.z);
r0.z = r0.z * c0.z;
r0.y = floor(r0.y);
r0.x = (r0.z < 0.0) ? -r0.z : r0.z;
r0.xy*= c0.ww;
r0.xy = max(r0.xy,vec2(0));
r0.xy = min(r0.xy,vec2(1));
gl_FragColor = texture(texture1,r0.xy);
}

Study from “3.11.5.1 ABS: Absolute Value” downwards from:
http://www.opengl.org/registry/specs/ARB/fragment_program.txt

Hello,

Thanks for the reply. I tried this and got a few compilation error:

"0:0(0): error: function texture' undeclared 0:0(0): error: functionfrac’ undeclared
0:20(14): error: gl_FragColor' undeclared 0:0(0): error: functiontexture’ undeclared

I guess there are some undeclared variables but cannnot understand why texture and frac come as undeclared. I am using OpenGL 1.4…

Many thanks!

/x

GL 1.4? You need at least GL 2.0
I going to code it against GL 2.0 and GLSL 1.10


#version 110
uniform sampler2D texture0;
uniform sampler2D texture1;

varying vec2 texcoord0;

void main()
{

vec4 c0 = vec4(65535.0, 0.00390625, 256.0, 0.0039215689);

vec4 r0 = texture2D(texture0, texcoord0);
r0.x *= c0.x;
r0.y = r0.x*c0.x;
r0.z =  abs(r0.y);
r0.z = fract(r0.z);
r0.z = r0.z * c0.z;
r0.y = floor(r0.y);
r0.x = (r0.z < 0.0) ? -r0.z : r0.z;
r0.xy*= c0.ww;
r0.xy = max(r0.xy, vec2(0.0));
r0.xy = min(r0.xy, vec2(1.0));
gl_FragColor = texture2D(texture1, r0.xy);
}

Hello,

I managed to get OpenGL 2.1 running on my machine. When I compiled the above code, I still got a lot of errors but most of them went away when I replaced texture with texture2D. I am not sure of that is a good thing or not…

I still have a couple of errors and maybe that has to do with the GLSL compiler?? The errors are:

“OpenGL does not define the global function frac” and
“gl_FragColor is not accessible in this profile”.

Unfortunately Qt only supports GLSL and I was wondering if there is a way to wrap my ASM shader around a simple GLSL template, so that I can use it as is…

I would appreciate any help…

Thanks,

xarg

I’d say it’s time for you to study a bit of GLSL, and pay more attention to the answers :slight_smile:

Unfortunately Qt only supports GLSL and I was wondering if there is a way to wrap my ASM shader around a simple GLSL template, so that I can use it as is…

No. And thank God as GLSL is so much better.
You just need to port the ASM and be done with it.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.