开发者

Ogre material scripts; how do I give a technique multiple lod_indexes?

开发者 https://www.devze.com 2022-12-15 17:46 出处:网络
I have an Ogre material script that defines 4 rendering techniques. 1 using GLSL shaders, then 3 others that just use textures of different resolutions.

I have an Ogre material script that defines 4 rendering techniques. 1 using GLSL shaders, then 3 others that just use textures of different resolutions.

I want to use the GLSL shader unconditionally if the graphics card supports it, and the other 3 textures depending on camera distance otherwise.

At the moment my script is;

material foo
{
lod_distances 1600 2000

technique shaders
{
     lod_index 0
     lod_index 1
     lod_index 2

     //various passes here
}

technique high_res {
     lod_index 0
     //various passes here
}

technique medium_res {
     lod_index 1
     //various passes here
}

technique low_res {
     lod_index 2
     //various passes here
}

Extra information

The Ogre manual says;

Increasing indexes denote lower levels of detail

You can (and often will) assign more than one technique to the same LOD index, what this means is that OGRE will pick 'the best technique of the ones listed at the same LOD index.

OGRE determines which one is 'best' by which one is listed first.

Currently, on a machine supporting the GLSL version I am using, the script behaves as follows;

  • Camera > 2000 : Shader technique
  • Camera >1600 <= 2000 : Medium // Here it is chosing my "texture" technique instead of the shader
  • Camera <= 1600 : High //

If I change the lod order in shader technique to

{
     lod_index 2
     lod_index 1
     lod_index 0
}

Only the latest lod_index is used.


If I change it to

lod_index 0 1 2

It shouts at me

 Compiler error: fewer parameters expected in foo.material(#): lod_index only supports 1 argument

So how do I specify a technique to have 3 lod_indexes?

Duplication works;

technique shaders
{
     lod_index 0
     //Shader passes here
}


technique shaders1
{
     lod_index 1
     //DUPLICATE of shader passses in lod 0
}


technique开发者_StackOverflow社区 shaders2
{
     lod_index 2
     //DUPLICATE of shader passses in lod 0
}

...but it's ugly.


Your approach with different techniques for the different LOD values is indeed the correct one. A complete example file with material LOD usage, would look like this.

Note: You can of course change LOD strategy to fit your needs. All valid strategy values and their behavior are explained in the Ogre manual.

material testLOD
{
lod_strategy screen_ratio_pixel_count
lod_values 0.8 0.6 0.4 0.2

technique red10
{
    pass red
    {
        ambient 0.698039 0.698039 0.698039 1
        diffuse 0.698039 0.698039 0.698039 1
        specular 0.898039 0.898039 0.898039 1 20
        emissive 1 0 0 1
    }
}

technique green20
{
    lod_index 1
    pass green
    {
        ambient 0.698039 0.698039 0.698039 1
        diffuse 0.698039 0.698039 0.698039 1
        specular 0.898039 0.898039 0.898039 1 20
        emissive 0 1 0 1
    }
}

technique cyan100
{
    lod_index 2
    pass cyan
    {
        ambient 0.698039 0.698039 0.698039 1
        diffuse 0.698039 0.698039 0.698039 1
        specular 0.898039 0.898039 0.898039 1 20
        emissive 0 0.945098 0.980392 1
    }
}

technique blue200
{
    lod_index 3
    pass blue
    {
        ambient 0.698039 0.698039 0.698039 1
        diffuse 0.698039 0.698039 0.698039 1
        specular 0.898039 0.898039 0.898039 1 20
        emissive 0 0 1 1
    }
}

technique yellow1000
{
    lod_index 4
    pass yellow
    {
        ambient 0.698039 0.698039 0.698039 1
        diffuse 0.698039 0.698039 0.698039 1
        specular 0.898039 0.898039 0.898039 1 20
        emissive 1 1 0 1
    }
}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号