Newbie Question: HLSL to GLSL (again)

I know this has been mentioned in a general sense on the forum before, but I have a more specific question about converting HLSL to GLSL shaders.

I’ve found a really nice collection of HLSL shaders on the VVVV site

http://vvvv.org/tiki-index.php?page=User+Shaders&highlight=shaders

…and have been wondering if it would be possible to translate some of them into GLSL for use in Quartz Composer on the Mac.

I’ve downloaded the ATI HLSL to GLSL converter from
http://www.apple.com/downloads/macosx/development_tools/hlsl2glsl.html
and have started with the most basic shader from the VVVV shader tutorial from
http://vvvv.org/tiki-index.php?page=pixelshader_for_newbies_02
(code reproduced below).

The code can’t be converted by HLSL2GLSL: I get an error
‘vs2ps’ : syntax error parse error
every time I try to convert it. I’m wondering if shaders in VVVV are slightly different from standard HLSL shaders. I’ve managed to surmise that items in the ‘Techniques’ section are VVVV-specific (the initialise control-port in/out and default settings, as far as I can tell), but does anyone else have any thoughts on what else might be going wrong here?

Thanks in advance,

alx

PS
If anyone is interested in Quartz Composer (a Mac-specific modular image-processing application, a bit like VVVV, in fact), I have a QC blog. It’s geared towards my work producing realtime effects for the VJ application VDMX, but some might find it interesting.

http://machinesdontcare.wordpress.com

[b]// -------------------------------------------------------------------------
// PARAMETERS:
// -------------------------------------------------------------------------

//transforms
float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (DX9)
float4x4 tP: PROJECTION; //projection matrix as set via Renderer (DX9)
float4x4 tWVP: WORLDVIEWPROJECTION;

//texture
texture Tex <string uiname=“Texture”;>;
sampler Samp = sampler_state //sampler for doing the texture-lookup
{
Texture = (Tex); //apply a texture to the sampler
MipFilter = LINEAR; //sampler states
MinFilter = LINEAR;
MagFilter = LINEAR;
};

//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX <string uiname=“Texture Transform”;>;

//creates a color pin with the default value black with alphachanel set to 1 and with pinname “Color for Hello”
float4 HelloColor : COLOR <string uiname=“Color for Hello”;> = { 0.0, 0.0, 0.0, 1.00000 };

//the data structure: “vertexshader to pixelshader” is used as output data with the VS function and as input data with the PS function

struct vs2ps
{
float4 Pos : POSITION;
float4 TexCd : TEXCOORD0;
};

// -------------------------------------------------------------------------
// VERTEXSHADERS
// -------------------------------------------------------------------------

vs2ps VS(
float4 Pos : POSITION,
float4 TexCd : TEXCOORD0)
{
//inititalize all fields of output struct with 0
vs2ps Out = (vs2ps)0;

//transform position
Out.Pos = mul(Pos, tWVP);

//transform texturecoordinates
Out.TexCd = mul(TexCd, tTex);

return Out;
}

// -------------------------------------------------------------------------
// PIXELSHADERS:
// -------------------------------------------------------------------------

float4 hello_01(vs2ps In): COLOR
{
//texture lookup to access the pixels of the texture
float4 col = tex2D(Samp, In.TexCd);
//if the pixels are white then overwrite them with HelloColor (above input color)
//or do nothing
//then return col
if (col.r == 1 && col.g ==1 && col.b == 1)
{
col = HelloColor;
}
return col;
}

// -------------------------------------------------------------------------
// TECHNIQUES:
// -------------------------------------------------------------------------

technique HelloInPink //name for the technique pin
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 hello_01();
}
}[/b]

This is a FX file. Maybe you need to extract the shader and convert it. Also the shader is simple. Why not convert it manually?


//Vertex shader
uniform mat4 tTex;

void main()
{
   gl_Position = ftransform();

   gl_TexCOord[0] = tTex * gl_MultiTexCoord0;
}

Hi V-Man

thanks for getting back to me.
This particular FX file is very simple, and I chose it for that reason. Some of the ones that are more interesting are also a lot more complicated though, and with my limited knowledge of both GLSL and HLSL, I think converting them manually may be a bit more difficult.

I wonder: is there a list of GLSL equivalents of HLSL functions and data-types? I could probably work out line-by line how to translate HLSL into GLSL, if I had such a list.

Cheers,

alx

Nothing that I am aware of. Also, you can’t convert it line by line
because when you turn it to GLSL, some thing will end up on other lines.

float4 hello_01(vs2ps In): COLOR
{
}

turns into

varying …
varying …

void main()
{
gl_FragColor = …
}

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