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]