예제 #1
0
    void CurveEditor::NotifyPointMove(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
    {
        if (_id != MyGUI::MouseButton::Left)
            return;

        if (!CheckPosition(_left, _top))
            return;

        auto pos = MyGUI::IntPoint(_left, _top) - _sender->getCroppedParent()->getAbsolutePosition();
        auto value = GetValue(pos.left, pos.top);

        pos.left -= 7;
        pos.top -= 7;
        _sender->setPosition(pos);

        DiString str;
        str.Format("%.3g", value.x);
        mEditTimeEditBox->setCaption(str.c_str());
        str.Format("%.3g", value.y);
        mEditValueEditBox->setCaption(str.c_str());

        std::sort(mButtons.begin(), mButtons.end(),
            [](MyGUI::Button* a, MyGUI::Button* b) {
            return a->getPosition().left < b->getPosition().left;
        });

        RefreshCurve();
    }
예제 #2
0
    void DiLight::CreateShadowTextures(DiSceneManager* sm)
    {
        mShadowTextures.resize(mShadowConfig.size());
        mShadowCameras.resize(mShadowConfig.size());
        
        for (size_t i = 0; i < mShadowConfig.size(); ++i)
        {
            static int st = 0;
            DiString camname;
            camname.Format("_shad_cam_%d", st);
            DiString name;
            name.Format("_shad_tex_%d", st++);
            
            mShadowTextures[i] = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiTexture>(name);
            mShadowTextures[i]->SetDimensions(mShadowConfig[i].width, mShadowConfig[i].height);
            mShadowTextures[i]->SetFormat(mShadowConfig[i].format);
            mShadowTextures[i]->SetUsage(TU_RENDER_TARGET);
            mShadowTextures[i]->SetAddressing(AM_CLAMP);
            mShadowTextures[i]->CreateTexture();
            auto rt = mShadowTextures[i]->GetRenderTarget();
            
            rt->SetFlippingUV(true);
            rt->SetClearColor(DiColor::White);
            
            DiCamera* cam = sm->CreateCamera(camname);
			cam->SetAspectRatio((float)mShadowConfig[i].width / (float)mShadowConfig[i].height);
            mShadowCameras[i] = cam;
        }
    }
예제 #3
0
 void CurveEditor::SetAttribute(DiAttributeCurved& rhs)
 {
     rhs.CopyTo(&mCurvedAttr);
     
     mSplineButton->setStateSelected(mCurvedAttr.GetInterpolationType() == IT_SPLINE);
     
     // delete all buttons
     for (auto i : mButtons)
         mCanvasWidget->_destroyChildWidget(i);
     mButtons.clear();
     
     auto& pts = mCurvedAttr.GetControlPoints();
     float minVal = 0;
     float maxVal = 10;
     
     // calculate the range
     for (auto p : pts)
     {
         minVal = DiMath::Min(minVal, p.y);
         maxVal = DiMath::Max(maxVal, p.y);
     }
     
     float defaultRangeMin = 0;
     float defaultRangeMax = 10;
     
     if(minVal < 0)
     {
         int v = minVal / 10 - 1;
         minVal = v * 10;
     }
     
     if(maxVal > 10)
     {
         int v = maxVal / 10 + 1;
         maxVal = v * 10;
     }
     
     DiString temp;
     temp.Format("%g", minVal);
     mRangeMinEditBox->setCaption(temp.c_str());
     
     temp.Format("%g", maxVal);
     mRangeMaxEditBox->setCaption(temp.c_str());
     
     RefreshRange();
     
     // add buttons
     for (auto p : pts)
     {
         auto point = GetButtonPoint(p);
         AddButton(point.left, point.top);
     }
 }
예제 #4
0
    void CurveEditor::RefreshNumbers()
    {
        DeleteNumbersY();

        auto size = mCurveCanvasWidget->getSize();
        auto width = size.width;
        auto height = size.height;

        auto inteveralX = width / (gridNumX + 2);
        auto inteveralY = height / (gridNumY + 2);

        float step = (mValueRange.y - mValueRange.x) / gridNumY;
        
        for (auto i = 0; i <= gridNumY; i += 2)
        {
            MyGUI::TextBox* text = mCurveCanvasWidget->createWidget<MyGUI::TextBox>("TextBox",
                MyGUI::IntCoord(3, i * inteveralY + 5, 30, 15), MyGUI::Align::Default);
            text->setFontHeight(14);
            text->setTextShadow(true);
            text->setTextShadowColour(MyGUI::Colour::Black);
            DiString s;
            s.Format("%.1f", step*(gridNumY - i) + mValueRange.x);
            text->setCaption(s.c_str());
            mNumbersY.push_back(text);
        }
    }
예제 #5
0
 DiString DiEditorManager::GenerateControllerName(const DiString& type)
 {
     static int id = 0;
     DiString ret;
     ret.Format("%s_%d", type.c_str(), id++);
     return ret;
 }
예제 #6
0
 DiString DiEditorManager::GenerateRefModelName()
 {
     static int id = 0;
     DiString ret;
     ret.Format("Model_%d", id++);
     return ret;
 }
예제 #7
0
 DiString DiEditorManager::GenerateElementName()
 {
     static int id = 0;
     DiString ret;
     ret.Format("Element_%d", id++);
     return ret;
 }
예제 #8
0
 DiString DiEditorManager::GenerateSystemName()
 {
     static int id = 0;
     DiString ret;
     ret.Format("ParticleSystem_%d", id++);
     return ret;
 }
예제 #9
0
    void DiFoliageLayer::CreateMaterial()
    {
        DiString uniqueStr;
        static int uq = 0;
        uniqueStr.Format("_fol_mat_%d",uq++);

        DiCompileDesc desc;
        desc.entryName = "vs_main";
        desc.profile = DiShaderProgram::GetDefaultVsProfile();

        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_ALPHA"        ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_GROW"        ,"1"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_ALPHA_GROW","2"));

        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_LIGHTING"        ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_ANIMATE"        ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_BLEND"            ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_TECH"        ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_RENDER_TECH"    ,"0"));

        mMaterial = DiAssetManager::GetInstance().CreateManualAsset<DiMaterial>(uniqueStr);

        mMaterial->SetBlendMode(BLEND_ALPHA);
        mMaterial->SetCullMode(CULL_NONE);

        mMaterial->LoadVertexShader("grass.vsh");
        mMaterial->LoadPixelShader("unlighting_diffuse_color.psh");

        mNeedUpdateMaterial = true;
    }
예제 #10
0
파일: Info.cpp 프로젝트: wangyanxing/Demi3D
    void DiInfo::Update(float delta)
    {
        //Change("FPS", 1.0f / delta);

        if (mInfo != nullptr)
        {
            //std::ostringstream stream;
            //for (MyGUI::VectorStringPairs::iterator iter = mParams.begin(); iter != mParams.end(); ++iter)
            //{
            //    if (iter != mParams.begin())
            //        stream << "\n";
            //    stream << iter->first << " :\t" << iter->second;
            //}

            //mInfo->setCaption(stream.str());
            DiString info = DiProfiler::GetInstancePtr()->GetData();
            DiString fps;
            fps.Format("\nFPS: %f", 1.0f / delta);
            info += fps;
            mInfo->setCaption(info.c_str());

            DI_PROFILE_BEGIN_INTERVAL

            MyGUI::ISubWidgetText* text = mInfo->getSubWidgetText();
            if (text != nullptr)
            {
                const MyGUI::IntSize& size = text->getTextSize() + mInfo->getSize() - text->getSize();
                const MyGUI::IntSize& size_view = MyGUI::RenderManager::getInstance().getViewSize();
                mInfo->setCoord(10, 10, size.width, size.height);
            }
        }
    }
예제 #11
0
    void CurveEditor::InitGrid()
    {
        auto size = mCurveCanvasWidget->getSize();
        auto width = size.width;
        auto height= size.height;

        auto inteveralX = width / (gridNumX + 2);
        auto inteveralY = height / (gridNumY + 2);

        MyGUI::Colour dark(0.1f, 0.1f, 0.1f);
        MyGUI::Colour light(0.2f, 0.2f, 0.2f);

        std::vector<MyGUI::Colour> colors;
        std::vector<MyGUI::FloatPoint> lines;
        for (auto i = 1; i <= gridNumX+1; ++i)
        {
            lines.push_back(MyGUI::FloatPoint(i*inteveralX, 3));
            lines.push_back(MyGUI::FloatPoint(i*inteveralX, height-4));

            colors.push_back(i == 1 ? dark : light);
            colors.push_back(i == 1 ? dark : light);
        }

        lines.push_back(MyGUI::FloatPoint(inteveralX - 1, 3));
        lines.push_back(MyGUI::FloatPoint(inteveralX - 1, height - 4));
        colors.push_back(dark);
        colors.push_back(dark);

        for (auto i = 1; i <= gridNumY + 1; ++i)
        {
            lines.push_back(MyGUI::FloatPoint(3, i*inteveralY));
            lines.push_back(MyGUI::FloatPoint(width - 4, i*inteveralY));

            colors.push_back(i == gridNumY + 1 ? dark : light);
            colors.push_back(i == gridNumY + 1 ? dark : light);
        }

        lines.push_back(MyGUI::FloatPoint(3, (gridNumY + 1)*inteveralY + 1));
        lines.push_back(MyGUI::FloatPoint(width - 4, (gridNumY + 1)*inteveralY + 1));
        colors.push_back(dark);
        colors.push_back(dark);

        mCurveLines->setPoints(lines, true);
        mCurveLines->setColors(colors);

        for (auto i = 1; i <= gridNumX + 1; i += 2)
        {
            MyGUI::TextBox* text = mCurveCanvasWidget->createWidget<MyGUI::TextBox>("TextBox",
                MyGUI::IntCoord(i * inteveralX + 2, height - 19, 30, 15), MyGUI::Align::Default);
            text->setFontHeight(14);
            text->setTextShadow(true);
            text->setTextShadowColour(MyGUI::Colour::Black);
            DiString s;
            s.Format("%.1f", (i - 1) / (float)gridNumX);
            text->setCaption(s.c_str());
            mNumbersX.push_back(text);
        }
    }
예제 #12
0
 void DiEditorManager::SetCurrentFileName(const DiString& name)
 {
     mFxFileName = name;
     
     DiString title = "Hon Fxer";
     if(!name.empty())
         title.Format("Hon Fxer - %s",name.ExtractFileName().c_str());
     
     DiBase::Driver->GetMainRenderWindow()->GetWindow()->SetTitle(title.c_str());
 }
예제 #13
0
    DiInstanceBatchPtr DiInstanceManager::BuildNewBatch(const DiString& materialName, bool firstTime)
    {
        DiSubMesh::IndexMap &idxMap = mMeshReference->GetSubMesh(mSubMeshIdx)->GetBlendIndexToBoneIndexMap();
        //idxMap = idxMap.empty() ? mMeshReference->sharedBlendIndexToBoneIndexMap : idxMap;

        DiMaterialPtr mat = DiAssetManager::GetInstance().GetAsset<DiMaterial>( materialName );

        InstanceBatchVec &materialInstanceBatch = mInstanceBatches[materialName];

        DiInstanceBatchPtr batch;

        DiString name;
        name.Format("%s_InstanceBatch_%d",mName.c_str(),mIdCount++);

        switch( mInstancingTechnique )
        {
        case INSTANCE_SHADER_BASED:
            batch = make_shared<DiInstanceBatchShader>( this, mMeshReference, mMotionReference, mat, mInstancesPerBatch,
                &idxMap, name );
            break;
        case INSTANCE_HARDWARE_BASED:
            batch = make_shared<DiInstanceBatchHardware>(this, mMeshReference, mat, mInstancesPerBatch,
                name );
            break;
        default:
            DI_ERROR("Unsupported instanced technique.");
            break;
        }

        if( !firstTime )
        {
            batch->BuildFrom( mMeshReference->GetSubMesh(mSubMeshIdx) );
        }
        else
        {
            const size_t maxInstPerBatch = batch->CalculateMaxNumInstances( mMeshReference->
                GetSubMesh(mSubMeshIdx) );
            mInstancesPerBatch = DiMath::Min( maxInstPerBatch, mInstancesPerBatch );
            batch->SetInstancesPerBatch( mInstancesPerBatch );

            batch->Build( mMeshReference->GetSubMesh(mSubMeshIdx) );
        }

        //const BatchSettings &batchSettings = mBatchSettings[materialName];
        //batch->SetCastShadows( batchSettings.setting[CAST_SHADOWS] );

        DiCullNode *sceneNode = mSceneManager->GetRootNode()->CreateChild();
        sceneNode->AttachObject( batch );

        materialInstanceBatch.push_back( batch );

        return batch;
    }
예제 #14
0
    DiMaterialPtr DiMaterial::QuickCreate( const DiString& vs, const DiString& ps , uint64 flag)
    {
        static int quickcreateID = 0;
        DiString name;
        name.Format("quick_%d", quickcreateID++);
        DiMaterialPtr mat = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiMaterial>(name);

        mat->SetShaderFlag(flag);
        mat->LoadShader(vs,ps);

        return mat;
    }
예제 #15
0
    void RenderWindowControl::updateInfo()
    {
        auto model = HonViewerApp::GetViewerApp()->GetModelViewer();
        if (!model)
            return;

        int numVerts = model->GetNumVertices();
        int numFaces = model->GetNumFaces();
        int numSubMods = model->GetNumSubModels();
        int numBones = model->GetNumBones();

        DiString info;
        info.Format("%d\n%d\n%d\n%d", numVerts, numFaces, numSubMods, numBones);
        mInfo->setCaption(info.c_str());
    }
예제 #16
0
void DiFileLogger::OutputLog(const char* szMessage, const char* levelInfo,
                           const char* fileName, long line)
{
    DiString datetime = DiTimer::GetCurrentTime();

    DiString log;
    log.Format( "[%s] %s%s", datetime.c_str(), levelInfo, szMessage);
    mFile << log.c_str();

    if (fileName)
    {
        DiString file = fileName;
        file = file.ExtractFileName();
        mFile << ", " << file.c_str() << "(" << line << ")";
    }

    mFile << std::endl;
}
예제 #17
0
 void DiEditorManager::OpenFx(const DiString& fxFileName)
 {
     DiString base = fxFileName.ExtractFileName();
     if(!DiAssetManager::GetInstance().HasArchive(base))
     {
         DiString message;
         message.Format("Cannot find the effect file(%s) in our media folders!", base.c_str());
         MyGUI::Message::createMessageBox("Message", "Error", message.c_str(),
                                          MyGUI::MessageBoxStyle::Ok|MyGUI::MessageBoxStyle::IconError);
         
         return;
     }
     
     DiFxTokensParser parser;
     
     auto stream = DiAssetManager::GetInstance().OpenArchive(base);
     shared_ptr<DiXMLFile> xmlfile(DI_NEW DiXMLFile());
     xmlfile->Load(stream->GetAsString());
     DiXMLElement root = xmlfile->GetRoot();
     
     if (!root.CheckName("Effects"))
     {
         DI_WARNING("Bad effect file: %s", base.c_str());
         return;
     }
     
     auto child = root.GetChild();
     while (child)
     {
         if (child.CheckName("ParticleSystem"))
         {
             auto ps = parser.ReadSystem(child);
             LoadParticleSystem(ps);
         }
         else if(child.CheckName("ReferenceModel"))
         {
             LoadRefModel(child);
         }
         
         child = child.GetNext();
     }
     
     SetCurrentFileName(fxFileName);
 }
예제 #18
0
파일: Logger.cpp 프로젝트: redkaras/Demi3D
void DiFileLogger::OutputLog(const char* szMessage, const char* levelInfo,
                           const char* fileName, long line)
{
    DiString datetime = DiTimer::GetCurrentDateTime();

    DiString logPre;

    DiString file = fileName;
    file = file.ExtractFileName();
    DiString log;
    log.Format(
        "%s %s(%d)\r\n"
        "[%s] : %s\r\n\r\n", 
        datetime.c_str(),
        file.c_str(), line,
        levelInfo, szMessage);

    log = logPre + log;

    mFile << log.c_str();
}
예제 #19
0
void ModelConverter::WriteSubMesh( DiSubMesh* subMod, const Ogre::SubMesh* s )
{
	switch(s->operationType)
	{
	case RenderOperation::OT_LINE_LIST:
		subMod->SetPrimitiveType(D3DPT_LINELIST);
		break;
	case RenderOperation::OT_LINE_STRIP:
		subMod->SetPrimitiveType(D3DPT_LINESTRIP);
		break;
	case RenderOperation::OT_POINT_LIST:
		subMod->SetPrimitiveType(D3DPT_POINTLIST);
		break;
	case RenderOperation::OT_TRIANGLE_FAN:
		subMod->SetPrimitiveType(D3DPT_TRIANGLEFAN);
		break;
	case RenderOperation::OT_TRIANGLE_LIST:
		subMod->SetPrimitiveType(PT_TRIANGLELIST);
		break;
	case RenderOperation::OT_TRIANGLE_STRIP:
		subMod->SetPrimitiveType(D3DPT_TRIANGLESTRIP);
		break;
	}

	VertexData* vertexData = nullptr;
	if (mMesh->sharedVertexData)
	{
		vertexData = mMesh->sharedVertexData;
	}
	else
	{
		vertexData = s->vertexData;
	}

	int numFaces = 0;
	switch(s->operationType)
	{
	case RenderOperation::OT_TRIANGLE_LIST:
		// triangle list
		numFaces = s->indexData->indexCount / 3;

		break;
	case RenderOperation::OT_LINE_LIST:
		numFaces = s->indexData->indexCount / 2;

		break;
	case RenderOperation::OT_TRIANGLE_FAN:
	case RenderOperation::OT_TRIANGLE_STRIP:
		// triangle fan or triangle strip
		numFaces = s->indexData->indexCount - 2;

		break;
	default:
		OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
			"Unsupported render operation type", 
			__FUNCTION__);
	}

	subMod->SetPrimitiveCount(numFaces);
	subMod->SetVerticeNum(vertexData->vertexCount);

	// material name
	DiString matName;
	matName.Format("%s_%d.mtl",subMod->GetParentMesh()->GetName().c_str(),subMod->GetIndex());
	subMod->SetMaterialName(matName);

	bool use32BitIndexes = (!s->indexData->indexBuffer.isNull() && 
		s->indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_32BIT);

	// Write each face in turn
	unsigned int* pInt = 0;
	unsigned short* pShort = 0;
	HardwareIndexBufferSharedPtr ibuf = s->indexData->indexBuffer;

	// index data
	if (use32BitIndexes)
	{
		pInt = static_cast<unsigned int*>(
			ibuf->lock(HardwareBuffer::HBL_READ_ONLY)); 
	}
	else
	{
		pShort = static_cast<unsigned short*>(
			ibuf->lock(HardwareBuffer::HBL_READ_ONLY)); 
	}

	void* indata = subMod->CreateIndexData(s->indexData->indexCount,use32BitIndexes?TRUE:FALSE);
	if (use32BitIndexes)
	{
		memcpy(indata,pInt,sizeof(unsigned int)*s->indexData->indexCount);
	}
	else
	{
		memcpy(indata,pShort,sizeof(unsigned short)*s->indexData->indexCount);
	}

	ibuf->unlock();

	// vertex declaration
	VertexDeclaration* decl = vertexData->vertexDeclaration;
	VertexBufferBinding* bind = vertexData->vertexBufferBinding;

	VertexBufferBinding::VertexBufferBindingMap::const_iterator b, bend;
	bend = bind->getBindings().end();
	// iterate over buffers
	int bindCount = 0;
	for(b = bind->getBindings().begin(); b != bend; ++b,++bindCount)
	{
		const HardwareVertexBufferSharedPtr vbuf = b->second;
		unsigned short bufferIdx = b->first;
		// get all the elements that relate to this buffer			
		VertexDeclaration::VertexElementList elems = decl->findElementsBySource(bufferIdx);
		VertexDeclaration::VertexElementList::iterator i, iend;
		iend = elems.end();

		unsigned short nuDemiureCoords = 0;
		for (i = elems.begin(); i != iend; ++i)
		{
			VertexElement& elem = *i;

			D3DDECLTYPE type = ConverteVertType(elem.getType());
			D3DDECLUSAGE usage;
			bool texcoord = false;
			switch(elem.getSemantic())
			{
			case VES_POSITION:
				usage = D3DDECLUSAGE_POSITION;
				break;
			case VES_NORMAL:
				usage = D3DDECLUSAGE_NORMAL;
				break;
			case VES_TANGENT:
				usage = D3DDECLUSAGE_TANGENT;
				break;
			case VES_BINORMAL:
				usage = D3DDECLUSAGE_BINORMAL;
				break;
			case VES_DIFFUSE:
			case VES_SPECULAR:
				usage = D3DDECLUSAGE_COLOR;
				break;
			case VES_TEXTURE_COORDINATES:
				usage = D3DDECLUSAGE_TEXCOORD;
				++nuDemiureCoords;
				texcoord = true;
				break;
			default:
				DI_ERROR("Unsupported semantic");
			}

			subMod->GetVertexElements().AddElement(bindCount,type,usage,texcoord?nuDemiureCoords-1:0);
		}

		int stride = subMod->GetVertexElements().GetStreamElementsSize(bindCount);
		void* vertData = subMod->CreateSourceData(bindCount,vertexData->vertexCount,stride);

		unsigned char* pVert = static_cast<unsigned char*>(
			vbuf->lock(HardwareBuffer::HBL_READ_ONLY));
		memcpy(vertData,pVert,vertexData->vertexCount*stride);
		vbuf->unlock();
	}

	// vertex weight
	if (mMesh->hasSkeleton())
	{
		LogManager::getSingleton().logMessage("Exporting dedicated geometry bone assignments...");

		if(const_cast<SubMesh*>(s)->getBoneAssignments().empty())
		{
			SubMesh::BoneAssignmentIterator bi = mMesh->getBoneAssignmentIterator();
			while (bi.hasMoreElements())
			{
				const VertexBoneAssignment& assign = bi.getNext();
				if (assign.weight > 0.0f)
				{
					subMod->AddWeight(assign.vertexIndex,assign.boneIndex,assign.weight);
				}
			}
		}
		else
		{
			SubMesh::BoneAssignmentIterator bi = (const_cast<SubMesh*>(s))->getBoneAssignmentIterator();
			while (bi.hasMoreElements())
			{
				const VertexBoneAssignment& assign = bi.getNext();
				if (assign.weight > 0.0f)
				{
					subMod->AddWeight(assign.vertexIndex,assign.boneIndex,assign.weight);
				}
			}
		}
		
		subMod->RationaliseBoneWeights();
	}
}
예제 #20
0
void InitScene()
{
    DiSceneManager* sm = DiBase::Driver->GetSceneManager();
    sm->SetAmbientColor(DiColor(0.6f, 0.6f, 0.6f));
    
    float scale = 0.5f;
    DiDirLightPtr dirlight;
    dirlight = make_shared<DiDirLight>();
    DiCullNode* dirNode = sm->GetRootNode()->CreateChild();
    dirNode->AttachObject(dirlight);
    dirlight->SetColor(DiColor(0.8f,0.8f,0.8f));
    dirlight->SetDirection(DiVec3(0.3f,-0.7f,0.4).normalisedCopy());
    //dirlight->InitForShadowCasting(sm, ShadowTextureConfig(1024,1024,PF_A32B32G32R32F));
    
    auto pos = DiVec3(150,275,130)*2;
    dirNode->SetPosition(pos);
    
    DiCullNode* spotNode = sm->GetRootNode()->CreateChild();
    DiSpotLightPtr sptLt = make_shared<DiSpotLight>();
    spotNode->AttachObject(sptLt);
    //spotNode->SetPosition(50, 100, 40);
    spotNode->SetPosition(pos);
    sptLt->SetDirection((-pos).normalisedCopy());
    sptLt->SetRange( DiDegree(80), DiDegree(90) );
    sptLt->InitForShadowCasting(sm, ShadowTextureConfig(1024,1024,PF_A32B32G32R32F));
    
    sptLt->mShadowCameraNear = 50;
    sptLt->mShadowCameraFar = 200;
    sptLt->mShadowCameraFov = 50;
    sptLt->_UpdateShadowCamera();
    
    DiDebugHelperPtr dbghelper;
    auto mat = DiMaterial::QuickCreate("lambert_v", "lambert_p", SHADER_FLAG_SHADOW_RECEIVER);
    mat->SetAmbient(DiColor(0.8f, 0.8f, 0.8f));
    mat->SetDiffuse(DiColor(0.8f, 0.8f, 0.8f));

    dbghelper = make_shared<DiDebugHelper>();
    sm->GetRootNode()->AttachObject(dbghelper);
    DiMaterialPtr helpermat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR);
    helpermat->SetDepthCheck(false);
    dbghelper->SetMaterial(helpermat);
    //dbghelper->AddFrustum(dirlight->GetShadowCamera(0), DiColor::Red);

    hp = dbghelper.get();
    lt = sptLt.get();

#if 0
    DiSimpleShapePtr plane = make_shared<DiSimpleShape>();
    plane->SetShadowCastEnable(false);
    plane->CreatePlane(600, 600);
    plane->SetMaterial(mat);
    plane->GetMaterial()->SetDiffuse(DiColor::White);
    DiCullNode* planeNode = sm->GetRootNode()->CreateChild();
    planeNode->AttachObject(plane);
    planeNode->Translate(0, 0, 0);

    const int size = 1;
    for (int i = -size; i <= size; i++)
    {
        for (int j = -size; j <= size; j++)
        {
            DiMaterialPtr mat = DiMaterial::QuickCreate("lambert_v", "lambert_p", SHADER_FLAG_SKINNED | SHADER_FLAG_SHADOW_RECEIVER);
            mat->SetDiffuse(DiColor(1, 1, 1));
            mat->SetAmbient(DiColor(0.7f, 0.7f, 0.7f));
            
            DiString name;
            name.Format("md_%d_%d", i, j);
            DiAnimModelPtr model = make_shared<DiAnimModel>(name, "robot.model", "robot.motion");
            //DiModelPtr model = make_shared<DiModel>(name, "robot.model");
            model->SetMaterial(mat);
            model->SetShadowCastEnable(true);
            
            model->SetAutoUpdateAnims(true);
            model->GetClipSet()->GetClipController("Walk")->SetEnabled(true);
            
            DiCullNode* cullnode = sm->GetRootNode()->CreateChild();
            cullnode->AttachObject(model);
            cullnode->SetPosition(i * 140.0f, 0, j * 140.0f);
        }
    }
    
#else
    
    DiSimpleShapePtr plane = make_shared<DiSimpleShape>();
    plane->SetShadowCastEnable(false);
    plane->CreatePlane(300, 300);
    plane->SetMaterial(mat);
    plane->GetMaterial()->SetDiffuse(DiColor::White);
    DiCullNode* planeNode = sm->GetRootNode()->CreateChild();
    planeNode->AttachObject(plane);

    DiMaterialPtr m = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_SHADOW_RECEIVER);
    m->SetDiffuse(DiColor(0.9f, 0.9f, 0.9f));
    
    DiSimpleShapePtr box = make_shared<DiSimpleShape>();
    box->SetShadowCastEnable(true);
    box->CreateBox(10);
    box->SetMaterial(m);
    DiCullNode* cullnode = sm->GetRootNode()->CreateChild();
    cullnode->SetPosition(0,5,0);
    cullnode->AttachObject(box);

#endif

    //SetupScene();

    DiCamera* camera = sm->GetCamera();
    camera->SetNearClipDistance(5);
    camera->SetFarClipDistance(5000);
}