Search code examples
openglogre3dcg

Solution to "function 'floor' not support in this profile" in Ogre3D cg fragment shader


I am reading the book "Ogre3D 1.7 Beginngers guide".I writed a cg fragment shader but encountered the complier complain, "function 'floor' not support in this profile".

The fragment shader definition is here:

   fragment_program MyFragmentShader8 cg
{
    source Ogre3DBeginnersGuideShaders.cg
    entry_point MyFragmentShader8
    profiles ps_1_1 arbfp1
}

The implementation is here:

void MyFragmentShader8(float2 uv    :TEXCOORD0,
    out float4 color    :COLOR,
    uniform sampler2D texture)
{
    float num = 50;
    float stepsize = 1.0 / num;
    float2 fragment = float2(stepsize * floor(uv.x * num), stepsize * floor(uv.y * num));
    color = tex2D(texture, fragment);
}

Solution

  • You can replace this line:

    float2 fragment = float2(stepsize * floor(uv.x * num), stepsize * floor(uv.y * num));
    

    with these 3 lines:

    int tmp1 = uv.x * num;
    int tmp2 = uv.y * num;
    float2 fragment = float2(stepsize * tmp1, stepsize * tmp2);
    

    The conversion to int is an implicit floor().