Ticket #1920: NoSortingForTrees.patch

File NoSortingForTrees.patch, 5.1 KB (added by wraitii, 11 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"/>
  • source/graphics/Material.cpp

     
    5252    m_Samplers.push_back(texture);
    5353    if (texture.Name == CStrIntern("baseTex"))
    5454        m_DiffuseTexture = texture.Sampler;
     55    else if (texture.Name == CStrIntern("normTex"))
     56        m_NormalTexture = texture.Sampler;
     57    else if (texture.Name == CStrIntern("specTex"))
     58        m_SpecularTexture = texture.Sampler;
     59    else if (texture.Name == CStrIntern("aoTex"))
     60        m_AOTexture = texture.Sampler;
    5561}
    5662
    5763void CMaterial::AddRenderQuery(const char* key)
  • source/graphics/Model.cpp

     
    375375    {
    376376        const Prop& prop=m_Props[j];
    377377
    378         CMatrix3D proptransform = prop.m_Point->m_Transform;;
     378        CMatrix3D proptransform = prop.m_Point->m_Transform;
    379379        if (prop.m_Point->m_BoneIndex != 0xff)
    380380        {
    381381            CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex];
  • 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; }
     
    7275    // This pointer is kept to make it easier for the fixed pipeline to
    7376    // access the only texture it's interested in.
    7477    CTexturePtr m_DiffuseTexture;
     78    // these other pointers are for easier comparison when batching
     79    CTexturePtr m_SpecularTexture;
     80    CTexturePtr m_NormalTexture;
     81    CTexturePtr m_AOTexture;
    7582   
    7683    SamplersVector m_Samplers;
    7784   
  • source/renderer/ModelRenderer.cpp

     
    294294        if (b->GetMaterial().GetDiffuseTexture() < a->GetMaterial().GetDiffuseTexture())
    295295            return false;
    296296
     297        if (a->GetMaterial().GetSpecularTexture() < b->GetMaterial().GetSpecularTexture())
     298            return true;
     299        if (b->GetMaterial().GetSpecularTexture() < a->GetMaterial().GetSpecularTexture())
     300            return false;
     301
     302        if (a->GetMaterial().GetNormalTexture() < b->GetMaterial().GetNormalTexture())
     303            return true;
     304        if (b->GetMaterial().GetNormalTexture() < a->GetMaterial().GetNormalTexture())
     305            return false;
     306
     307        if (a->GetMaterial().GetAOTexture() < b->GetMaterial().GetAOTexture())
     308            return true;
     309        if (b->GetMaterial().GetAOTexture() < a->GetMaterial().GetAOTexture())
     310            return false;
     311
    297312        return a->GetMaterial().GetStaticUniforms() < b->GetMaterial().GetStaticUniforms();
    298313    }
    299314};
     
    401416     * For each material bucket we then look up the appropriate shader technique.
    402417     * If the technique requires sort-by-distance, the model is added to the
    403418     * 'sortByDistItems' list with its computed distance.
    404      * Otherwise, the bucket's list of models is sorted by modeldef+texture+uniforms,
     419     * Otherwise, the bucket's list of models is sorted by modeldef+textures+uniforms,
    405420     * then the technique and model list is added to 'techBuckets'.
    406421     *
    407422     * 'techBuckets' is then sorted by technique, to improve batching when multiple
     
    504519            }
    505520            else
    506521            {
    507                 // Sort model list by modeldef+texture, for batching
    508                 // TODO: This only sorts by base texture. While this is an OK approximation
    509                 // for most cases (as related samplers are usually used together), it would be better
    510                 // to take all the samplers into account when sorting here.
     522                // Sort model list for more efficient batching
     523                // this sorts by model def and the 4 basic textures
     524                // (diffuse, normal, specular and AO)
     525                // TODO: this should probably be made more generic.
    511526                std::sort(it->second.begin(), it->second.end(), SMRBatchModel());
    512527
    513528                // Add a tech bucket pointing at this model list
     
    625640                {
    626641                    CModel** models = techBuckets[idx].models;
    627642                    size_t numModels = techBuckets[idx].numModels;
     643
    628644                    for (size_t i = 0; i < numModels; ++i)
    629645                    {
    630646                        CModel* model = models[i];