Page 1 of 1

Bugs with Ogre and Cg->glsles using HLSL2GLSL

Posted: Mon Oct 29, 2012 4:04 pm
by d000hg
I found that none of my Cg shaders were working when using HLSL2GLSLFork. By saving the generated shaders as new glsles versions and examining them, I think I've found a couple of bugs.

Here's a working Cg shader:

Code: Select all

struct vs_out {
    float4 position:POSITION;
};
vs_out test_vs(float4 position: POSITION, uniform float4x4 worldViewProj)
{
    vs_out ret;
    ret.position = mul(worldViewProj, position);
    return ret;
}
Here is what Ogre/HLSL2GLSL has created:

Code: Select all

#version 100
precision mediump int;
precision mediump float;

struct vs_out {
    vec4 position;
};

uniform mat4 worldViewProj;

vs_out test_vs( in vec4 position, mat4 worldViewProj ) {
    vs_out ret;
    ret.position = (worldViewProj * position);
    #line 33
    return ret;
}
uniform mat4 xlu_worldViewProj;
attribute vec4 vertex;

void main() {
    vs_out xl_retval;
    xl_retval = test_vs( vec4(vertex), xlu_worldViewProj);
    gl_Position = vec4( xl_retval.position);
}
So I noticed these weird "xlu_" uniforms being created, the same name as Ogre's auto-vars but with the xlu_prefix. I changed the code to use the ogre versions instead of the xlu_ ones, and suddenly it was working!

So what's the deal here? Am I doing something wrong, or is there a problem with Ogre Vs HLSL2GLSL?

Re: Bugs with Ogre and Cg->glsles using HLSL2GLSL

Posted: Tue Dec 11, 2012 3:05 pm
by oiram
To fix this issue:

Code: Select all


uniform float4x4 worldViewProj;

struct vs_out {
    float4 position:POSITION;
};

vs_out test_vs(float4 position: POSITION)
{
    vs_out ret;
    ret.position = mul(worldViewProj, position);
    return ret;
}
Hope it's helpful. :wink:

Re: Bugs with Ogre and Cg->glsles using HLSL2GLSL

Posted: Tue Dec 11, 2012 3:17 pm
by d000hg
I'll make a note to test this, if it works that would be wonderful :)

Re: Bugs with Ogre and Cg->glsles using HLSL2GLSL

Posted: Fri Mar 01, 2013 4:09 pm
by d000hg
This seems to fix it, that's totally awesome!

I wish Cg didn't have 3 ways (at least) to specify a function though... why do I have to do this?!