[solved]Is this a unknown bug?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
moriwo
Posts: 40
Joined: Fri Jul 04, 2008 9:29 pm

[solved]Is this a unknown bug?

Post by moriwo »

I want to draw the shadow on ground.

The material type of the ground node is EMT_TRANSPARENT_ALPHA_CHANNEL.
because it have warter material.

and, The material type of the shadow node is
EMT_TRANSPARENT_ALPHA_CHANNEL, too.

but...the shadow is not drawn sometimes correctly.
what should i do?
[img]
http://3dcg-yotuba.com/uploader/src/up0068.jpg
[/img]

below is test .exe , model files, and image files.
you can find this problem.
http://3dcg-yotuba.com/uploader/src/up0069.zip

and dll was fixed famous zbuffer problem in EDT_DIRECT3D9.
-------------------------------------------------------------------
CD3D9MaterialRenderer.h
class CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public CD3D9MaterialRenderer
/*
((SMaterial&)material).ZWriteEnable = false;
*/
-------------------------------------------------------------------


below is full source code

Code: Select all

#include "windows.h"
#include "irrlicht.h"
#include "ISkinnedMesh.h"

#pragma comment(lib,"irrlicht.lib")

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) 
{ 
	IrrlichtDevice* Device = createDevice(video::EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 16, false, false,true); 
	IVideoDriver *Driver = Device->getVideoDriver(); 
	ISceneManager *Scene = Device->getSceneManager(); 
	IGUIEnvironment* gui = Device->getGUIEnvironment();
	IGUIFont *font = gui->getBuiltInFont();
	ICursorControl* cursor = Device->getCursorControl();

	ICameraSceneNode *camera; 
	camera = Scene->addCameraSceneNode(0, vector3df(0,4,-4), vector3df(0,0,0)); 

	camera->setUpVector(vector3df(0.0f,1.0f,0.0f)); 
	matrix4 projMat; 
	projMat.buildProjectionMatrixPerspectiveFovLH(45.0f,1.3333f,1.0f,20000.0f); 
	camera->setProjectionMatrix(projMat); 

	ILightSceneNode *light1 = Scene->addLightSceneNode(0, vector3df(0,2,0), SColorf(.5f, .5f, .5f), 50.0f);
	light1->getLightData().Type = ELT_DIRECTIONAL;
	light1->getLightData().AmbientColor = SColorf(.5f,.5f,.5f);

	//ground node
	IAnimatedMesh* terraMesh = Scene->getMesh("terra_alp.x");
	ISceneNode* terraNode = Scene->addOctTreeSceneNode(terraMesh->getMesh(0));
	ITriangleSelector* selector= Scene->createOctTreeTriangleSelector(terraMesh,terraNode,32);
	terraNode->setTriangleSelector(selector);
	terraNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL );

	//shadow node (texture alpha)
	IAnimatedMesh* shadowMesh = Scene->getMesh("shadow_alp.x");
	IAnimatedMeshSceneNode* shadowNode = Scene->addAnimatedMeshSceneNode(shadowMesh);
	shadowNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
	shadowNode->getMaterial(0).MaterialTypeParam = 0.01f;
	shadowNode->setDebugDataVisible(1);
/*
	//create shadow node (vertex alpha)
	IAnimatedMesh* shadowMesh = Scene->getMesh("shadow_valp.x");
	IAnimatedMeshSceneNode* shadowNode = Scene->addAnimatedMeshSceneNode(shadowMesh);
	shadowNode->setMaterialType(EMT_TRANSPARENT_VERTEX_ALPHA);
	shadowNode->setMaterialFlag(EMF_LIGHTING,false);
*/
	while(Device->run()) 
	{  
		Driver->beginScene(true, true, SColor(0,0,100,100)); 

		//get mouse intersection
		vector3df out;
		triangle3df tri;
		line3df ray;
		ray = Scene->getSceneCollisionManager()->getRayFromScreenCoordinates(cursor->getPosition(),camera);

		if(Scene->getSceneCollisionManager()->getCollisionPoint(ray,selector,out,tri))
		{
			//alline ground normal with shadow
			shadowNode->setPosition(out + vector3df(0, 0.1f, 0));
			shadowNode->setRotation(tri.getNormal().getHorizontalAngle() + vector3df(90, 0, 0));
		}

		Scene->drawAll(); 
		Driver->endScene();
	} 
    Device->drop(); 
    return 0; 
} 
Last edited by moriwo on Mon Aug 25, 2008 1:08 pm, edited 8 times in total.
moriwo
Posts: 40
Joined: Fri Jul 04, 2008 9:29 pm

Post by moriwo »

I think that I am a problem that the order of drawing causes.

How can I adjust the drawing order in some nodes?
moriwo
Posts: 40
Joined: Fri Jul 04, 2008 9:29 pm

Post by moriwo »

is this a unknown bug of zbuffer?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, it's a problem with the rendering order. You should render the shadow after the terrain has been finished. You can do this by either calling the render method manually after drawAll(), or by creating a custom node which does register to a later stage. Another option is to change the terrain to a solid material and attach all transparent elements in a different mesh.
moriwo
Posts: 40
Joined: Fri Jul 04, 2008 9:29 pm

Post by moriwo »

thanks hybrid.

I tried code below.
but, shadow was not renderd.

I think that I cannot do the rendering of the node after drawAll.
(between beginScene - endScene loop)

Is my idea correct?

Code: Select all

shadowNode->setVisible(false);

Scene->drawAll();

shadowNode->setVisible(true);
shadowNode->render();

Driver->endScene();

hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hmm, yes, you're right. The *Mesh scene nodes do work correct with transparency only if they are called in the transparency pass. So you'd have to render the meshbuffers manually:

Code: Select all

driver->setMaterial(mb->getMaterial());
driver->drawVertexPrimitiveList(...)
moriwo
Posts: 40
Joined: Fri Jul 04, 2008 9:29 pm

Post by moriwo »

thanks.

I get it.

I hope a new version of irrlicht comes to be able to set the rendering priority manually.
Post Reply