Esempio n. 1
0
void SE_Geometry::writeEffect(SE_BufferOutput& output)
{
    SE_Spatial::writeEffect(output);
        //save this spatial light status
    if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::LIGHTING))
    {
        output.writeInt(1);//this spatial need lighting

        //write light para
        std::vector<SE_Light*> dirlight;
        std::vector<SE_Light*> pointlight;
        std::vector<SE_Light*> spotlight;

        getCurrentAttachedSimObj()->getMesh()->getSurface(0)->getDirLights(dirlight);
        getCurrentAttachedSimObj()->getMesh()->getSurface(0)->getPointLights(pointlight);
        getCurrentAttachedSimObj()->getMesh()->getSurface(0)->getSpotLights(spotlight);

        //write dir light
        output.writeInt(dirlight.size()); //write dirlight count
        for(int i = 0; i < dirlight.size(); ++i)
        {
            //write dir light info
            SE_Light* light = dirlight[i];
            SE_Vector3f dir = light->getLightDir();
            std::string name = light->getLightName();
            SE_Vector3f color = light->getLightColor();
            float dirstrength = light->getDirLightStrength();
            output.writeVector3f(dir);
            output.writeString(name.c_str());
            output.writeVector3f(color);
            output.writeFloat(dirstrength);


        }

        //write point light
        output.writeInt(pointlight.size()); //write point light count
        for(int i = 0; i < pointlight.size(); ++i)
        {
            //write dir light info
            SE_Light* light = pointlight[i];
            SE_Vector3f pos = light->getLightPos();
            float constAttr = light->getConstantAttenuation();
            float linearAttr = light->getLinearAttenuation();
            float quatAttr = light->getQuadraticAttenuation();
            std::string name = light->getLightName();
            SE_Vector3f color = light->getLightColor();

            output.writeVector3f(pos);
            output.writeFloat(constAttr);
            output.writeFloat(linearAttr);
            output.writeFloat(quatAttr);
            output.writeString(name.c_str());
            output.writeVector3f(color);
        }

        //write spot light
        output.writeInt(spotlight.size()); //write spot light count
        for(int i = 0; i < spotlight.size(); ++i)
        {
            //write dir light info
            SE_Light* light = spotlight[i];

            SE_Vector3f pos = light->getLightPos();
            SE_Vector3f spotdir = light->getLightDir();

            float constAttr = light->getConstantAttenuation();
            float linearAttr = light->getLinearAttenuation();
            float quatAttr = light->getQuadraticAttenuation();
            
            float cutoff = light->getSpotLightCutOff();
            float soptexp = light->getSpotLightExp();
            std::string name = light->getLightName();
            SE_Vector3f color = light->getLightColor();

            output.writeVector3f(pos);
            output.writeVector3f(spotdir);

            output.writeFloat(constAttr);
            output.writeFloat(linearAttr);
            output.writeFloat(quatAttr);

            output.writeFloat(cutoff);
            output.writeFloat(soptexp);
            output.writeString(name.c_str());
            output.writeVector3f(color);
        }
    }
    else
    {
        output.writeInt(0);//do not lighting
    }

    //write shadow generator status
    if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::SHADOWGENERATOR))
    {
        if(SE_Application::getInstance()->SEHomeDebug)
        LOGI("spatial[%s] is shadow generator!\n",getSpatialName());
        output.writeInt(1);
        SE_Camera* s = SE_Application::getInstance()->getHelperCamera(SE_SHADOWCAMERA);
        SE_Vector3f loc = s->getLocation();
        SE_Vector3f target = s->getTarget();
        SE_Vector3f up = s->getUp();
        float neara = s->getFrustum()->getNear();
        float fara = s->getFrustum()->getFar();
        float fov = s->getFovDegree();
        output.writeVector3f(loc);
        output.writeVector3f(target);
        output.writeVector3f(up);
        output.writeFloat(neara);
        output.writeFloat(fara);
        output.writeFloat(fov);

    }
    else
    {
        //do not generate shadow
        output.writeInt(0);
    }

    //write shadow render status
    if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::SHADOWRENDER))
    {
        if(SE_Application::getInstance()->SEHomeDebug)
        LOGI("spatial[%s] is shadow render!\n",getSpatialName());
        output.writeInt(1);
    }
    else
    {
        //do not render shadow
        output.writeInt(0);
    }

    //write mirror generator
    if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::MIRRORGENERATOR))
    {
        output.writeInt(1);
        output.writeString(mMirrorInfo.c_str());
        output.writeInt((int)mMirrorPlane);
    }
    else
    {
        output.writeInt(0);
    }

    //write mirror render
    if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::MIRRORRENDER))
    {
        output.writeInt(1);
        float alpha = this->getAlpha();
        output.writeFloat(alpha);
    }
    else
    {
    output.writeInt(0);
    }

    //write mipmap info
    if(mGenerateMipMap)
    {
        output.writeInt(1);
    }
    else
    {
        output.writeInt(0);
    }
    float alpha = this->getAlpha();
    output.writeFloat(alpha);
    SE_Vector4f mspatialData = this->getEffectData();
    output.writeVector4f(mspatialData);

    unsigned int effectstate = this->getEffectState();
    output.writeInt(effectstate);

}