Ticket #1771: disable_casting_shadows_on_preview_models.patch

File disable_casting_shadows_on_preview_models.patch, 4.8 KB (added by Eric Bobbitt, 11 years ago)
  • source/graphics/Model.cpp

    From 03dbf52b432f074b0a99edcfbb5e948a97251967 Mon Sep 17 00:00:00 2001
    From: = <eric@hellouser.net>
    Date: Sat, 6 Apr 2013 23:59:56 -0500
    Subject: [PATCH 1/2] Removing casting shadows from preview placement models,
     still need to disable the model from receiving shadows.
    
    ---
     source/graphics/Model.cpp                             |   12 ++++++++++++
     source/graphics/Model.h                               |    2 ++
     source/simulation2/components/CCmpTemplateManager.cpp |    3 +++
     source/simulation2/components/CCmpVisualActor.cpp     |   12 +++++++++++-
     4 files changed, 28 insertions(+), 1 deletion(-)
    
    diff --git a/source/graphics/Model.cpp b/source/graphics/Model.cpp
    index b60fd1a..a82c855 100644
    a b void CModel::AddFlagsRec(int flags)  
    602602            m_Props[i].m_Model->ToCModel()->AddFlagsRec(flags);
    603603}
    604604
     605void CModel::RemoveFlagsRec(int flags)
     606{
     607    m_Flags &= ~flags;
     608
     609    if (flags & MODELFLAG_IGNORE_LOS)
     610        m_Material.AddShaderDefine("IGNORE_LOS", "1");
     611
     612    for (size_t i = 0; i < m_Props.size(); ++i)
     613        if (m_Props[i].m_Model->ToCModel())
     614            m_Props[i].m_Model->ToCModel()->RemoveFlagsRec(flags);
     615}
     616
    605617void CModel::SetMaterial(const CMaterial &material)
    606618{
    607619    m_Material = material;
  • source/graphics/Model.h

    diff --git a/source/graphics/Model.h b/source/graphics/Model.h
    index 77e6224..6b3839b 100644
    a b public:  
    118118    int GetFlags() const { return m_Flags; }
    119119    // add object flags, recursively through props
    120120    void AddFlagsRec(int flags);
     121    // remove object flags, recursively through props
     122    void RemoveFlagsRec(int flags);
    121123
    122124    // recurse down tree setting dirty bits
    123125    virtual void SetDirtyRec(int dirtyflags) {
  • source/simulation2/components/CCmpTemplateManager.cpp

    diff --git a/source/simulation2/components/CCmpTemplateManager.cpp b/source/simulation2/components/CCmpTemplateManager.cpp
    index e87e6a4..f3be24d 100644
    a b void CCmpTemplateManager::CopyPreviewSubset(CParamNode& out, const CParamNode& i  
    525525    if (out.GetChild("Entity").GetChild("Obstruction").IsOk())
    526526        CParamNode::LoadXMLString(out, "<Entity><Obstruction><Active>false</Active></Obstruction></Entity>");
    527527
     528    if (out.GetChild("Entity").GetChild("VisualActor").IsOk())
     529        CParamNode::LoadXMLString(out, "<Entity><VisualActor><DisableShadows/></VisualActor></Entity>");
     530
    528531    if (!corpse)
    529532    {
    530533        // Previews should always be visible in fog-of-war/etc
  • source/simulation2/components/CCmpVisualActor.cpp

    diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
    index b9a3088..ea91e07 100644
    a b public:  
    117117                    "<empty/>"
    118118                "</element>"
    119119            "</optional>"
     120            "<optional>"
     121                "<element name='DisableShadows' a:help='Used internally; if present, shadows will be disabled'>"
     122                    "<empty/>"
     123                "</element>"
     124            "</optional>"
    120125            "<element name='SilhouetteDisplay'>"
    121126                "<data type='boolean'/>"
    122127            "</element>"
    void CCmpVisualActor::InitModel(const CParamNode& paramNode)  
    535540
    536541                if (paramNode.GetChild("SilhouetteDisplay").ToBool())
    537542                    modelFlags |= MODELFLAG_SILHOUETTE_DISPLAY;
    538 
    539543                if (paramNode.GetChild("SilhouetteOccluder").ToBool())
    540544                    modelFlags |= MODELFLAG_SILHOUETTE_OCCLUDER;
    541545
    void CCmpVisualActor::InitModel(const CParamNode& paramNode)  
    544548                    modelFlags |= MODELFLAG_IGNORE_LOS;
    545549
    546550                model.ToCModel()->AddFlagsRec(modelFlags);
     551
     552                if (paramNode.GetChild("DisableShadows").IsOk()) {
     553                    modelFlags = 0;
     554                    modelFlags |= MODELFLAG_CASTSHADOWS;
     555                    model.ToCModel()->RemoveFlagsRec(modelFlags);
     556                }
    547557            }
    548558
    549559            // Initialize the model's selection shape descriptor. This currently relies on the component initialization order; the
  • source/simulation2/components/CCmpVisualActor.cpp

    -- 
    1.7.10.4
    
    
    From f532ca9148120f7e07d1a30fcffaceb762cf30db Mon Sep 17 00:00:00 2001
    From: = <eric@hellouser.net>
    Date: Sun, 7 Apr 2013 22:01:48 -0500
    Subject: [PATCH 2/2] now preview placement models do not receive shadows
    
    ---
     source/simulation2/components/CCmpVisualActor.cpp |    2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
    index ea91e07..8b8f89d 100644
    a b void CCmpVisualActor::InitModel(const CParamNode& paramNode)  
    552552                if (paramNode.GetChild("DisableShadows").IsOk()) {
    553553                    modelFlags = 0;
    554554                    modelFlags |= MODELFLAG_CASTSHADOWS;
     555                    model.ToCModel()->GetMaterial().AddShaderDefine("USE_SHADOW", "false");
     556                    model.ToCModel()->GetMaterial().AddShaderDefine("DISABLE_RECEIVE_SHADOWS", "1");
    555557                    model.ToCModel()->RemoveFlagsRec(modelFlags);
    556558                }
    557559            }