Ticket #1920: NoSortTrees.patch

File NoSortTrees.patch, 9.6 KB (added by wraitii, 10 years ago)
  • binaries/data/mods/public/art/materials/basic_trans_wind.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<material>
    3     <shader effect="model_transparent"/>
     3    <shader effect="model_transparent_nosort"/>
    44    <alpha_blending/>
    55    <define name="USE_TRANSPARENT" value="1"/>
    66    <renderquery name="sim_time"/>
  • binaries/data/mods/public/shaders/effects/model_transparent_nosort.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<effect>
     3
     4    <technique>
     5        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     6        <require shaders="arb"/>
     7        <pass shader="arb/model_solid_tex">
     8            <define name="REQUIRE_ALPHA_GEQUAL" value="0.4"/>
     9        </pass>
     10    </technique>
     11
     12    <technique>
     13        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     14        <require shaders="glsl"/>
     15        <pass shader="glsl/model_solid_tex">
     16            <define name="REQUIRE_ALPHA_GEQUAL" value="0.4"/>
     17        </pass>
     18    </technique>
     19
     20    <technique>
     21        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     22        <require shaders="fixed"/>
     23        <define name="USE_PLAYERCOLOR" value="0"/>
     24        <define name="USE_OBJECTCOLOR" value="0"/>
     25        <pass shader="fixed:model_solid_tex">
     26            <alpha func="gequal" ref="0.4"/>
     27        </pass>
     28    </technique>
     29
     30
     31
     32    <!--
     33        CRenderer::RenderSilhouettes skips alpha-blended models for
     34        MODE_SILHOUETTEDISPLAY, so do a dummy non-blended behaviour here to
     35        make it obviously buggy if CRenderer is changed to render these models.
     36    -->
     37    <technique>
     38        <require context="MODE_SILHOUETTEDISPLAY || MODE_WIREFRAME"/>
     39        <require shaders="arb"/>
     40        <pass shader="arb/model_solid_player"/>
     41    </technique>
     42
     43    <technique>
     44        <require context="MODE_SILHOUETTEDISPLAY || MODE_WIREFRAME"/>
     45        <require shaders="glsl"/>
     46        <pass shader="glsl/model_solid_player"/>
     47    </technique>
     48
     49    <technique>
     50        <require context="MODE_SILHOUETTEDISPLAY || MODE_WIREFRAME"/>
     51        <require shaders="fixed"/>
     52        <define name="USE_PLAYERCOLOR" value="1"/>
     53        <define name="USE_OBJECTCOLOR" value="0"/>
     54        <pass shader="fixed:model_solid"/>
     55    </technique>
     56
     57
     58
     59    <technique>
     60        <require context="USE_ALPHATEST"/>
     61        <require shaders="arb"/>
     62        <pass shader="arb/model_common">
     63            <define name="USE_TRANSPARENT" value="1"/>
     64            <define name="REQUIRE_ALPHA_GEQUAL" value="0.4"/>
     65        </pass>
     66    </technique>
     67
     68    <technique>
     69        <require context="USE_ALPHATEST"/>
     70        <require shaders="glsl"/>
     71        <pass shader="glsl/model_common">
     72            <define name="USE_TRANSPARENT" value="1"/>
     73            <define name="REQUIRE_ALPHA_GEQUAL" value="0.4"/>
     74        </pass>
     75    </technique>
     76
     77    <technique>
     78        <require context="USE_ALPHATEST"/>
     79        <require shaders="fixed"/>
     80        <pass shader="fixed:model">
     81            <alpha func="gequal" ref="0.4"/>
     82        </pass>
     83    </technique>
     84
     85
     86
     87    <technique>
     88        <require context="ALPHABLEND_PASS_OPAQUE"/>
     89        <require shaders="arb"/>
     90        <pass shader="arb/model_common">
     91            <define name="USE_TRANSPARENT" value="1"/>
     92            <define name="REQUIRE_ALPHA_GEQUAL" value="0.6375"/>
     93        </pass>
     94    </technique>
     95
     96    <technique>
     97        <require context="ALPHABLEND_PASS_OPAQUE"/>
     98        <require shaders="glsl"/>
     99        <pass shader="glsl/model_common">
     100            <define name="USE_TRANSPARENT" value="1"/>
     101            <define name="REQUIRE_ALPHA_GEQUAL" value="0.6375"/>
     102        </pass>
     103    </technique>
     104
     105    <technique>
     106        <require context="ALPHABLEND_PASS_OPAQUE"/>
     107        <require shaders="fixed"/>
     108        <pass shader="fixed:model">
     109            <alpha func="gequal" ref="0.6375"/>
     110        </pass>
     111    </technique>
     112
     113
     114   
     115    <technique>
     116        <require context="ALPHABLEND_PASS_BLEND"/>
     117        <require shaders="arb"/>
     118        <pass shader="arb/model_common">
     119            <define name="USE_TRANSPARENT" value="1"/>
     120            <define name="REQUIRE_ALPHA_GEQUAL" value="0.05"/>
     121            <blend src="src_alpha" dst="one_minus_src_alpha"/>
     122            <depth func="less" mask="false"/>
     123        </pass>
     124    </technique>
     125
     126    <technique>
     127        <require context="ALPHABLEND_PASS_BLEND"/>
     128        <require shaders="glsl"/>
     129        <pass shader="glsl/model_common">
     130            <define name="USE_TRANSPARENT" value="1"/>
     131            <define name="REQUIRE_ALPHA_GEQUAL" value="0.05"/>
     132            <blend src="src_alpha" dst="one_minus_src_alpha"/>
     133            <depth func="less" mask="false"/>
     134        </pass>
     135    </technique>
     136
     137    <technique>
     138        <require context="ALPHABLEND_PASS_BLEND"/>
     139        <require shaders="fixed"/>
     140        <pass shader="fixed:model">
     141            <define name="USE_TRANSPARENT" value="1"/>
     142            <alpha func="gequal" ref="0.05"/>
     143            <blend src="src_alpha" dst="one_minus_src_alpha"/>
     144            <depth func="less" mask="false"/>
     145        </pass>
     146    </technique>
     147
     148</effect>
  • source/graphics/Material.cpp

     
    5353    m_Samplers.push_back(texture);
    5454    if (texture.Name == str_baseTex)
    5555        m_DiffuseTexture = texture.Sampler;
     56    else if (texture.Name == CStrIntern("normTex"))
     57        m_NormalTexture = texture.Sampler;
     58    else if (texture.Name == CStrIntern("specTex"))
     59        m_SpecularTexture = texture.Sampler;
     60    else if (texture.Name == CStrIntern("aoTex"))
     61        m_AOTexture = texture.Sampler;
    5662}
    5763
    5864void CMaterial::AddRenderQuery(const char* key)
  • source/graphics/Material.h

     
    4848    bool UsesAlphaBlending() { return m_AlphaBlending; }
    4949
    5050    const CTexturePtr& GetDiffuseTexture() const { return m_DiffuseTexture; }
     51    const CTexturePtr& GetSpecularTexture() const { return m_SpecularTexture; }
     52    const CTexturePtr& GetNormalTexture() const { return m_NormalTexture; }
     53    const CTexturePtr& GetAOTexture() const { return m_AOTexture; }
    5154
    5255    void SetShaderEffect(const CStr& effect);
    5356    CStrIntern GetShaderEffect() const { return m_ShaderEffect; }
     
    8285    // This pointer is kept to make it easier for the fixed pipeline to
    8386    // access the only texture it's interested in.
    8487    CTexturePtr m_DiffuseTexture;
     88    // these other pointers are for easier comparison when batching
     89    CTexturePtr m_SpecularTexture;
     90    CTexturePtr m_NormalTexture;
     91    CTexturePtr m_AOTexture;
    8592   
    8693    SamplersVector m_Samplers;
    8794   
  • source/renderer/ModelRenderer.cpp

     
    296296        if (b->GetMaterial().GetDiffuseTexture() < a->GetMaterial().GetDiffuseTexture())
    297297            return false;
    298298
     299        if (a->GetMaterial().GetSpecularTexture() < b->GetMaterial().GetSpecularTexture())
     300            return true;
     301        if (b->GetMaterial().GetSpecularTexture() < a->GetMaterial().GetSpecularTexture())
     302            return false;
     303
     304        if (a->GetMaterial().GetNormalTexture() < b->GetMaterial().GetNormalTexture())
     305            return true;
     306        if (b->GetMaterial().GetNormalTexture() < a->GetMaterial().GetNormalTexture())
     307            return false;
     308
     309        if (a->GetMaterial().GetAOTexture() < b->GetMaterial().GetAOTexture())
     310            return true;
     311        if (b->GetMaterial().GetAOTexture() < a->GetMaterial().GetAOTexture())
     312            return false;
     313
    299314        return a->GetMaterial().GetStaticUniforms() < b->GetMaterial().GetStaticUniforms();
    300315    }
    301316};
     
    403418     * For each material bucket we then look up the appropriate shader technique.
    404419     * If the technique requires sort-by-distance, the model is added to the
    405420     * 'sortByDistItems' list with its computed distance.
    406      * Otherwise, the bucket's list of models is sorted by modeldef+texture+uniforms,
     421     * Otherwise, the bucket's list of models is sorted by modeldef+textures+uniforms,
    407422     * then the technique and model list is added to 'techBuckets'.
    408423     *
    409424     * 'techBuckets' is then sorted by technique, to improve batching when multiple
     
    523538            }
    524539            else
    525540            {
    526                 // Sort model list by modeldef+texture, for batching
    527                 // TODO: This only sorts by base texture. While this is an OK approximation
    528                 // for most cases (as related samplers are usually used together), it would be better
    529                 // to take all the samplers into account when sorting here.
     541                // Sort model list for more efficient batching
     542                // this sorts by model def and the 4 basic textures
     543                // (diffuse, normal, specular and AO)
     544                // TODO: this should probably be made more generic.
    530545                std::sort(it->second.begin(), it->second.end(), SMRBatchModel());
    531546
    532547                // Add a tech bucket pointing at this model list
     
    644659                {
    645660                    CModel** models = techBuckets[idx].models;
    646661                    size_t numModels = techBuckets[idx].numModels;
     662
    647663                    for (size_t i = 0; i < numModels; ++i)
    648664                    {
    649665                        CModel* model = models[i];