Jump to content

Issue with Refraction and LEO/Framework


Rimerdal
 Share

Recommended Posts

Hey guys,

 

I am fairly new to Leadwerks (Just for the engine a couple days ago) and started going through the tutorials to figure some stuff out. I decided to do them with LEO/Framework that way I would have to do some figuring out to get the tutorials to work and it wasn't just read and type what I see. Well this worked great up until the Transparency and Refraction tutorial. I got Transparency working correctly, but Refraction I have run into somewhat of a roadblock.

 

Basically the Refraction tutorial uses buffers and passes those to the materials shader, but all of the rendering of the worlds and lighting occur in the framework and so I am not sure where or how I would use those buffers... I am sure its something simple I am just missing but any help you can offer would be greatly appreciated. The code is kind of a compilation of a bunch of tutorials thrown together, which is why there is 200 random barrels in the level also.

 

//	====================================================================
//	This file was generated by Leadwerks ProjectWizard
//	http://www.leadwerks.com
//	====================================================================

#include "leo.h"
using namespace LEO ;

inline float rnd( float min=0.0, float max=1.0 ) {
return min + ((float)rand()/RAND_MAX)*(max-min);
}

#if defined( _WINDOWS )
void ErrOut( const char* pstrMessage ) { MessageBoxA(0, pstrMessage, "Error", 0 ); }
int WINAPI WinMain( HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPSTR lpCmdLine,
					int nShowCmd ) 
#else
#include <string>
void ErrOut( const std::string& message ) { puts( message.c_str()); }
int main( int argn, char* argv[] )
#endif
{
   // Set graphics mode        
Engine engine("Leadwerks_Testing",1680,1050);        
if( !engine.IsValid() )        
{                
	ErrOut( "Failed to set graphics mode.");
	return 1;        
}        
RegisterAbstractPath( "C:/Leadwerks Engine SDK" ) ;

// Create framework object and set it to a global object so other scripts can access it        
Framework fw;        
fw.Create();                
if( NULL == fw )        
{               
	ErrOut( "Failed to initialize engine." );
	return 1;        
}        

// Set Lua framework object        
engine.SetObject( "fw", fw );                

// Set Lua framework variable        
Lua lua;        
lua.Create();        
lua.PushObject( fw );        
lua.SetGlobal( "fw" );        
lua.Pop( 1 );        

//	Turn on bloom
fw.GetRenderer().SetBloom(1);

// Get framework main camera        
fw.main.GetCamera().SetPosition( Vec3(0,2,-10) );        

// Load the scene      
Model  scene("Content\\scene.gmf") ;
   if ( !scene.IsValid() )
   {
       MessageBoxA( 0, "Failed to load scene.", "Error", 0 );
       return engine.Free();
   }
scene.SetType(1);

// Load the oildrum
Model model("Content\\oildrum.gmf") ;
   if ( !model.IsValid() )
   {
       MessageBoxA( 0, "Failed to load scene.", "Error", 0 );
       return engine.Free();
   }
model.SetType(1);
model.SetMass(1.0f);

//	Make a bunch of copies
for ( int i=1; i<=200; i++ ) {
	Entity modelCopy = model.Copy();
	modelCopy.SetPosition(Vec3(rnd(-5,5),rnd(5,15),rnd(-5,5)));
	modelCopy.SetRotation(Vec3(rnd(0,360),rnd(0,360),rnd(0,360)));
}

fw.transparency.GetWorld().Set();

//Create the transparent object 
Sphere sphere(50);
sphere.SetPosition(Vec3(0, 3, 0)); 
sphere.SetScale(2.0f);

//Load the transparent material 
Material mat("Content\\glass_refraction.mat");
if( !mat.IsValid() )
{
	MessageBoxA(0, "Failed to load material.", "Error", 0);
	return engine.Free();
}
sphere.Paint(mat);

//	Set Shader params
Shader shader = mat.GetShader();
shader.Set("refractionstrength",0.05f);

fw.main.GetWorld().Set();

// Create a light
DirectionalLight light( CREATENOW );        
light.SetRotation( Vec3(45) );        

// Camera controls
TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
float move=0;
float strafe=0;

// Center the mouse on the screen and hide it
Mouse::Move(engine.GetWidth()/2,engine.GetHeight()/2);
Mouse::Hide();

//	Turn on Collision
Collisions::Set(1,1);

while( !engine.IsTerminated() && !Keyboard::I****(KEY_ESCAPE) )        
{   
	// Update the mouse input
	mx=Curve((float)Mouse::GetX()-engine.GetWidth()/2, mx, 6);
	my=Curve((float)Mouse::GetY()-engine.GetHeight()/2, my, 6);
	Mouse::Move(engine.GetWidth()/2,engine.GetHeight()/2);

	//	Get keyboard input
	move=Curve((float)(Keyboard::IsDown(KEY_W)-Keyboard::IsDown(KEY_S)), move, 20);
	strafe=Curve((float)(Keyboard::IsDown(KEY_D)-Keyboard::IsDown(KEY_A)), strafe, 20);

	// Lets update the cameras rotation
	camrotation.X=camrotation.X + (my / 10.0f);
	camrotation.Y=camrotation.Y - (mx / 10.0f);
	fw.main.GetCamera().Move( Vec3(strafe / 10.0f,0,move / 10.0f) );
	fw.main.GetCamera().SetRotation(camrotation);

	// Update the world and render it
	fw.Update();                
	fw.Render();                
	engine.Flip( 0 );        
}                

return engine.Free();
}

 

RefractionTest.png

 

Thanks,

-David

Link to comment
Share on other sites

I was able to solve my issues by using the second material file provided with the demo which defines the color and depth buffers for you as texture parameters 2 and 3 within the material file itself, I am still kind of curious though if there is a way to do this in code with LEO/Framework.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...