Chernobyl Shaders - converting all shaders to Cg in work...

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

I done new version "01. CGE Plastic". Now avaiable is GLSL mode and HLSL mode :). I add callback source code for this demo in ReadMe. You can download it from:
http://rapidshare.com/files/41942562/0_ ... lastic.rar
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

cool, I'll have a look at it....
Image
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Well, it seems to work for the most parts, but I still have the problem with a wrong shadow...

It does not behave like in your demo...I can bring it to the "front" with a few camera moves...

ImageImage

This isn't right, is it?
Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I was interested in your erosion shader to get a rust effect on the cannon in my game and so i tried converting it to CG for use on PS3 (where i'm now developing the game that used to be an Irrlicht game) but unfortunately it didn't work at all... Could you give me any hints about what the varying parameters are set to in your little demo? Possibly i had those set wrong, think i just tried them all at 1.0. Also i made a few changes to make the shader use functions that i was used to from the other shaders i'd fiddled with or written (only been using shaders for a few months so i'm not hugely knowledgable in them!)
Image Image Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Masterhawk wrote:Well, it seems to work for the most parts, but I still have the problem with a wrong shadow...

It does not behave like in your demo...I can bring it to the "front" with a few camera moves...

ImageImage

This isn't right, is it?
Yes. This is wrong... (You have many cameras in your project?)
JP you need callback source code?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah that's probably where it'd be!
Image Image Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Callback source code for GLSL look that:

Code: Select all

class CGE_Shaders:public video::IShaderConstantSetCallBack
{
public:

	virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
	{
		video::IVideoDriver* driver = services->getVideoDriver();

		core::vector3df LightPosition = core::vector3df(0.0f,0.0f,4.0f);
        services->setVertexShaderConstant("LightPosition", reinterpret_cast<f32*>(&LightPosition), 3);

		video::SColorf Color1(0.2,0.0904,0,1.0);
        services->setVertexShaderConstant("Color1", reinterpret_cast<f32*>(&Color1), 4);

        video::SColorf Color2(0.8,0.8,0.8,1.0);
        services->setVertexShaderConstant("Color2", reinterpret_cast<f32*>(&Color2), 4);

        float Scale = 0.02;
        services->setVertexShaderConstant("Scale", reinterpret_cast<float*>(&Scale), 1);

        float ErosionFactor = 0.35;
        services->setVertexShaderConstant("ErosionFactor", reinterpret_cast<float*>(&ErosionFactor), 1);

        float IntensityFactor1 = 0.75;
        services->setVertexShaderConstant("IntensityFactor1", reinterpret_cast<float*>(&IntensityFactor1), 1);

        float IntensityFactor2 = 1.95;
        services->setVertexShaderConstant("IntensityFactor2", reinterpret_cast<float*>(&IntensityFactor2), 1);
	}
};
I solved your problem? :)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I'll give it a try and let you know!
Image Image Image
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Nadro wrote:Yes. This is wrong... (You have many cameras in your project?)
Yes I do, but in another scenemanager. But also removing the second cam does not fix the problem. It seems the shader interact with the right cam, but in a wrong way....
Does Newton can cause this behaviour?
Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Hmmm.... You try it:

Camera1 - first camera
Camera2 - second camera
Node - ball node

Newton can't change shader behaviour :)

Code: Select all

while(device->run())
{
driver->beginScene(true, true, video::SColor(255,255,0,0));
// Set Active Camera 1 !
node->setMaterialType((video::E_MATERIAL_TYPE)Plastic);
smgr->drawAll();
// Set Active Camera 2 !
node->setMaterialType((video::E_MATERIAL_TYPE)Plastic);
node->render();
driver->endScene();
}
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

No success :(

As long as I don't hit the ball it take a "long" time until I can see this effect. So the shadow tries to keep behind the ball. But when I hit the ball and it's rotating and moving the shadow not even recognizes my cam position. then I can panning an tilting my cam and the shadow stands still.....even when it stopped...then there is no more reaction :(
Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

You use RTT system :)
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

what..? how can I use another system.. :oops:

RTT=Render To Texture?
Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Yes Render To Texture :) or place Your code, so I can help You :)
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

What do you mean with that?...I never set my prog up this way....

argh...I'm confused....

code snippets: (beware of garbage, i don't want to miss a detail)

setting up the cam

Code: Select all

Camera = irrSceneMgr->addCameraSceneNode(0,vector3df(0.0f,0.0f,0.0f),vector3df(100.0f,0.0f,0.0f));
OrbCamCtrl = new IOrbitCamCtrl(Camera,GetBodyPos(CurrPlayer->Ball->body),irrDevice);
OrbCamCtrl->setAngularVelocity(params.mousecfg.AngularVelocity);
OrbCamCtrl->setInvertYAxis(params.mousecfg.InvertY);
my main loop

Code: Select all

void CGame::MainLoop()
{  
     
   if(OrbCamCtrl->isEnabled()) 
        irrDevice->getCursorControl()->setPosition(0.5f,0.5f); //Mouse zentrieren
   OrbCamCtrl->PreRender();
   HandleInput();
   
   // Update newton 100 times / second
   if (irrDevice->getTimer()->getTime() > lasttick + 10)
   {	
	 lasttick = irrDevice->getTimer()->getTime();
     NewtonUpdate(nWorld, 0.01f);
   }

   Render();
   
   if(CurrPlayer)
   {
     OrbCamCtrl->UpdateCam(MouseDiff.X,MouseDiff.Y,CamZoom,GetBodyPos(CurrPlayer->Ball->body));
     
     //Sync the VelLine with the cam angle (-PI/2): to kill the offset
     CurrPlayer->ControlLine->SetAngleZ(-(OrbCamCtrl->getTheta()*DEGTORAD)-PI/2);
   }  
   MouseDiff.X=0;
   MouseDiff.Y=0;
   CamZoom=0.f;
   
   
       
}


void CGame::Render()
{  
                    
       irrDriver->beginScene(true, true, SColor(0,200,200,200));
      
       
       if (isBodyNotMoving(CurrPlayer->Ball->body)) //&& Player1 an der Reihe
       {
           HandleFinished();
           
           if(stopped_Time == 0.f) //Init the Delaytime
           {
             stopped_Time = irrDevice->getTimer()->getRealTime();
             DelayTime = 0.f;
           }
           else
             DelayTime = (irrDevice->getTimer()->getRealTime() - stopped_Time)/1000.f;
           
           if(ReadyToSwitch && (DelayTime>2)) //Delaytime: The time the ball stands still
           {
                            
              ReadyToSwitch = false;
              CurrPlayer->setLastPos(GetBodyPos(CurrPlayer->Ball->body));
              lastPos = CurrPlayer->getLastPos(); 
              CurrPlayer = PlayerCtrl->getNextPlayer();
              if(CurrPlayer)
              {
                 CurrPlayer->ControlLine->setVisible(true);
                 CurrPlayer->lockHit(false);
              }
              
              stopped_Time=0.f;
           }
                
           matrix4 mat1;
           irrDriver->setTransform(ETS_WORLD,mat1);
           
           
           
           if(CurrPlayer)
           {                             
              //CurrPlayer->ControlLine->Draw(irrDriver,GetBodyPos(CurrPlayer->Ball->body));//ControlLine->Set
              CurrPlayer->ControlLine->Update(GetBodyPos(CurrPlayer->Ball->body));
           }
           else
             //irrDevice->closeDevice();
             CourseActive = false;
       } 
       
       
       irrSceneMgr->setActiveCamera(OrbCamCtrl->getCamera());
       Camera->updateAbsolutePosition();
       //CurrPlayer->Ball->node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);    
       irrSceneMgr->drawAll();
       
       //Updates the powerbar
       if(CurrPlayer)
          HUD->powerbar_Update(CurrPlayer->ControlLine->GetStrength());   
       
       irrGUIEnv->drawAll();
                
       irrDriver->endScene();
	    
       int fps = irrDriver->getFPS();

       if (lastFPS != fps)
       {
             core::stringw str = L"Minigolf 3D ALPHA #1(Singleplayer) - Masterhawk studios 2007 [";
             str += irrDriver->getName();
             str += "] FPS:";
             str += fps;
             irrDevice->setWindowCaption(str.c_str());
             lastFPS = fps;
       }
       
}
my callback: ( this is your one from the readme)

Code: Select all

public:

  MyShaderCallBack(IrrlichtDevice* aDevice,bool useHighLevelShaders)
  {
          device=aDevice;
          UseHighLevelShaders=useHighLevelShaders;          
  }
  
  virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
  {
      video::IVideoDriver* driver = services->getVideoDriver();

		core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
		invWorld.makeInverse();
		services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);

		core::matrix4 worldViewProj;
		worldViewProj = driver->getTransform(video::ETS_PROJECTION);
		worldViewProj *= driver->getTransform(video::ETS_VIEW);
		worldViewProj *= driver->getTransform(video::ETS_WORLD);
        		services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer() , 16);

		core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
		services->setVertexShaderConstant("Camera_Position", reinterpret_cast<f32*>(&pos), 3);

		video::SColorf col(1.0,0.9031,0.1536,1.0);
		services->setVertexShaderConstant("Color", reinterpret_cast<f32*>(&col), 4);
	}

creating a shader:

Code: Select all

//Loading shaders
    bool UseHighLevelShaders=true;
    c8* vsFileName = 0; // filename for the vertex shader
	c8* psFileName = 0; // filename for the pixel shader
    
    
    switch(driverType)
	{
	case video::EDT_DIRECT3D9:
		if (UseHighLevelShaders)
		{
			psFileName = "./shaders/Plastic.hlsl";
			vsFileName = psFileName; // both shaders are in the same file
		}
		break;
	case video::EDT_OPENGL:
		if (UseHighLevelShaders)
		{
			psFileName = "./shaders/Plastic.frag";
			vsFileName = "./shaders/Plastic.vert";
		}
		break;
	}
	
	//check if shaders supported
	if (!irrDriver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
		!irrDriver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1))
	{
		irrDevice->getLogger()->log("WARNING: Pixel shaders disabled "\
			"because of missing driver/hardware support.");
		psFileName = 0;
	}
	
	if (!irrDriver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
		!irrDriver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
	{
		irrDevice->getLogger()->log("WARNING: Vertex shaders disabled "\
			"because of missing driver/hardware support.");
		vsFileName = 0;
	}
	
	
	// create materials

	video::IGPUProgrammingServices* gpu = irrDriver->getGPUProgrammingServices();

	newMaterialType1 = 0;
	newMaterialType2 = 0;

	if (gpu)
	{
		MyShaderCallBack* mc = new MyShaderCallBack(irrDevice,UseHighLevelShaders);
	

		// create the shaders depending on if the user wanted high level
		// or low level shaders:

		if (UseHighLevelShaders)
		{
			// create material from high level shaders (hlsl or glsl)

			newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
				vsFileName,	"vertexMain", video::EVST_VS_1_1,
				psFileName, "pixelMain", video::EPST_PS_2_0,
				mc, video::EMT_SOLID);

			newMaterialType2 = gpu->addHighLevelShaderMaterialFromFiles(
				vsFileName,	"vertexMain", video::EVST_VS_1_1,
				psFileName, "pixelMain", video::EPST_PS_2_0,
				mc, video::EMT_TRANSPARENT_ADD_COLOR);
		}
		else
		{
			// create material from low level shaders (asm or arb_asm)

			newMaterialType1 = gpu->addShaderMaterialFromFiles(vsFileName,
				psFileName, mc, video::EMT_SOLID);

			newMaterialType2 = gpu->addShaderMaterialFromFiles(vsFileName,
				psFileName, mc, video::EMT_TRANSPARENT_ADD_COLOR);
		}

		mc->drop();
	}
applying a shader:

Code: Select all

tmp->node = irrSceneMgr->addSphereSceneNode(10.f,32);
	tmp->node->setMaterialTexture(0, irrDriver->getTexture(skin));
	tmp->node->setMaterialFlag(video::EMF_LIGHTING, false);
	
       tmp->node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);

Hope that you can see a mistake....
Image
Post Reply