Jump to content

[Resolved] Water Reflections


Rimerdal
 Share

Recommended Posts

I have been playing around with the editor and the engine trying out different things and after creating a third person camera I noticed something quirky about the water and was wondering if anyone knew what was going on or hopefully how to fix it... is it something I screwed up in the editor or is it related to the third person camera, maybe something I have forgotten, or its not supported? Just kind of hoping someone has ran into this issue before and has an idea of how to fix it or where I should start looking.

 

I am not really doing anything special in code, this water is setup in the SBX and is loaded in with scene, however, I can post the code if anyone thinks it might help. I can also post the SBX but it uses quite a few models from Arteria3D that I cannot send with the SBX so that could get in the way.

 

Also want to mention that the water looks fine in the editor and is reflecting everything correctly or at least seems to be. It also used to work very well when I was using my first person camera... it seems to have completely screwed up at this point. I based my third person camera code off the code I found in Jecklyn Heights, as it seemed to be a rather solid base to build a more robust third person camera (and I am still kind of riding with the training wheels on as far as LE is concerned.)

 

EDIT: Code is now in a post below

 

Screenshot1.png

Screenshot2.png

 

Thanks,

David

Link to comment
Share on other sites

Alright, going to try and organize this in a way that makes sense. I have been using Jecklyn Heights source code as a base for a couple things, trying to get a handle on how everything works.

 

I just tried removing the water plane from the SBX and creating the water in code to the same end.

 

 

This is the main game class:

#include "Game.h"
#include "Configuration.h"
#include "LevelManager.h"
#include "CameraController.h"

CGame::CGame()
{

}

CGame::~CGame()
{
Shutdown();
}

int CGame::Initialize()
{  
// Configuration
g_Config->LoadXMLConfigurationFile("Content/Configuration.xml");

// Application Title
SetAppTitle( g_Config->GetCString("Name","Window") );

// Initialize Window.
// Width, Height, Depth (Pass 32 for Fullscreen)
Graphics(g_Config->GetInteger("Width","Window"), g_Config->GetInteger("Height","Window"), g_Config->GetBool("Fullscreen","Window") ? 32 : 0, g_Config->GetInteger("Hertz","Window"));

// Register ../Assets/ as a media location
RegisterAbstractPath("");

// Initialize Framewerk
if ( !(m_Framework = CreateFramework()) )
{
	MessageBoxA(0,"Failed to initialize engine.","(Error)",0);
	return 0;
}

// Global Accessor for the Framework object, for Lua, and non-member use.
SetGlobalObject("fw", m_Framework);

//##############################################################################
//	Load settings from the XML file and setup anything else needed down the road
//##############################################################################

// Trilinear Filter
TFilter( g_Config->GetBool("TrilinearFilter", "Render") );

// Anisotropic Filtering
AFilter(min<int>( g_Config->GetInteger("AnisotropicFilter", "Render"),MaxAFilter()) );

// Set Antialiasing
SetAntialias( g_Config->GetBool("Antialias", "Render")); //	Default: Disabled

// Texture Quality
SetTextureQuality( g_Config->GetInteger("TextureQuality", "Render") );

// Shadow Quality
SetShadowQuality( g_Config->GetInteger("ShadowQuality", "Render") );

// Full Screen Bloom/Glow //
SetBloom( g_Config->GetBool("Bloom", "Render") ); // (Default: Enabled)

// SSAO //
SetSSAO( g_Config->GetBool("SSAO", "Render") ); // (Default: Disabled)

// Water //
//SetWater( g_Config->GetBool("Water", "Render") ); // (Default: Disabled)

// HDRR //
//SetHDR( g_Config->GetBool("HDR", "Render") ); // (Default: Enabled)

// Crespecular Rays //
SetGodRays( g_Config->GetBool("GodRays", "Render") ); // (Default: Disabled)

// Distance Fog //
SetDistanceFogRange(0,50);
SetDistanceFogColor(Vec4(1,1,1,1));
SetDistanceFogAngle(0,45);
SetDistanceFog( g_Config->GetBool("DistanceFog", "Render") ); // (Default: Disabled)

// Depth of Field //
SetFarDOF( g_Config->GetBool("DepthOfField", "Render") ); // (Default: Disabled)
SetFarDOFStrength(0.5f);
SetFarDOFRange(20.0f, 200.0f);

// Atmospheric Effects //

// Brightness //
SetBrightness( g_Config->GetFloat("Brightness", "Render") );

// Contrast //
SetContrast( g_Config->GetFloat("Contrast", "Render") );

// Saturation //
SetSaturation( g_Config->GetFloat("Saturation", "Render") );

//	Turn on occlusion culling, this could slow down performance with to many entities
OcclusionCulling(true);

//	This should be an option later on
SetWater(1);
SetReflectionElements(ENTITY_MESH+ENTITY_TERRAIN);

// Statistics (0 = Disabled, 1 = FPS, 2 = Detailed) //
SetStats(2); // (Default: 1 [FPS])

//####################################################################

// Set Lua framework variable        
BP lua = GetLuaState();        
lua_pushobject( lua, m_Framework );        
lua_setglobal( lua, "fw" );        
lua_pop( lua, 1 );

//	Set up our collision
Collisions(3,1,true);

//	Load a scene
CLevelManager::GetInstance()->LoadLevel("Content/Maps/TestIsland/mypractice.sbx");

//	Create a player
m_Player = new CPlayerController(PLAYER_LOCAL, "node_1");

//	Setup the camera
CCameraController::GetInstance()->Initialize();
m_Player->SetAsFocus();

//	Setup the games ambient lighting, this will need to be defined later by each level
AmbientLight(Vec3(0.3f, 0.3f, 0.3f));

//	Return success!
return 1;
}

void CGame::Shutdown()
{

}

int CGame::Run()
{
while( !KeyHit(KEY_ESCAPE) && !AppTerminate())
{
	if( !AppSuspended() ) // We are not in focus!
	{  
		// Update the player
		m_Player->Update(AppTime());

		// Update the level and the objects in the framework
		CLevelManager::GetInstance()->Update();

		//	Update the camera
		CCameraController::GetInstance()->Update();

		//	Leadwerks Render
		RenderFramework();

		// Screenshot functionality
		if (KeyHit(KEY_F12))
		{
			std::string picfile = "Screenshots/Screenshot";								
			std::ostringstream ts;
			ts << picfile << AppTime()/*pTimer->GetDays() << "." << pTimer->GetHours() << "." << pTimer->GetMinutes() << "." << pTimer->GetSeconds()*/ << ".png";
			picfile = ts.str();
			SaveBuffer(CurrentBuffer(), const_cast<char*>(picfile.c_str()), 100);
		}

		Flip( 0 );
	}
}

return 0;
}

 

 

This is the Player Controller class:

#include "PlayerController.h"
#include "LevelManager.h"
#include "CameraController.h"

CPlayerController::CPlayerController()
{
//	Set the type
m_Type = PLAYER_LOCAL;

//	Create a player controller
m_Player=CreateController();
EntityType(m_Player,3,1);
SetBodyMass(m_Player,60);
SweptCollision(m_Player,1);

//	Movement variables
move=0.0;
strafe=0.0;
}

CPlayerController::CPlayerController(PlayerType type, const char* spawnPoint)
{
//	Set the type
m_Type = type;

//	Find the spawn point
TEntity spawn=FindChild(CLevelManager::GetInstance()->m_eScene, spawnPoint);

//	Create a player controller
m_Player=CreateController(1.8f, 0.4f, 1.0f, 45, 0.9f);
EntityType(m_Player,3,1);
SetBodyMass(m_Player,60);
SweptCollision(m_Player,1);
PositionEntity(m_Player, EntityPosition(spawn));

//	Create and parent the controller to the model
playerMesh=LoadModel("abstract::crawler.gmf");
RotateEntity(playerMesh, Vec3(0, 180, 0));
SetBodyMass(playerMesh, 60);
EntityParent(playerMesh, m_Player, 0);

//	Movement variables
move=0.0;
strafe=0.0;
}

CPlayerController::~CPlayerController()
{

}

void CPlayerController::Update(flt dt)
{
switch(m_Type)
{
	case PLAYER_LOCAL:
	{
		HandleInput();
		break;
	}
}

//	Update the player models animations
float framebegin = 0.0f;
float frameend = 69.0f;

if(KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT))
{
	framebegin=131.0;
       frameend=171.0;
}
else if((move || strafe) && jump == 0.0f)
{
	framebegin = 70.0f;
	frameend = 130.0f;
}

   float frame=dt/25.0f;
frame=fmodf(frame,frameend-framebegin)+framebegin;
Animate(playerMesh,frame,1.0,0,true);

//Set controller input
float camY = CCameraController::GetInstance()->GetRotation().Y;
UpdateController(m_Player,camY,move,strafe,jump, 100.0f, 5);
}

void CPlayerController::HandleInput()
{
//Player movement
move=((float)KeyDown(KEY_W)-KeyDown(KEY_S)) * 5.0f;
strafe=((float)KeyDown(KEY_D)-KeyDown(KEY_A)) * 5.0f;

//Jumping
jump=0.0;
if (KeyHit(KEY_SPACE)) {
	if (!ControllerAirborne(m_Player)) {
		jump=10.0;
	}
}

//Run
if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) {
	if (!ControllerAirborne(m_Player)) {
		move*=2.0;
		strafe*=2.0;
	}
}
}

void CPlayerController::SetAsFocus()
{
//	Set this player as the target focus
CCameraController::GetInstance()->SetTarget(playerMesh);
}

 

 

...and this is the camera:

#include "CameraController.h"
#include "Platform.h"

#define FRAMES	15.0f

bool CCameraController::Initialize()
{
//	Default camera settings
m_Target = NULL; 
m_fDesiredDistance = 5.0; 
m_nMouseZ = 0;
m_nDeltaZ = 0;
m_nMouseZInterp = 0;

//	Get the camera from the engine and set its range
m_Camera = GetLayerCamera(GetFrameworkLayer(0));
CameraRange(m_Camera,0.1f,10000);

//	Create our camera pivots and parrents them accordingly
m_tTargetPivot = CreatePivot();
m_tCameraPivot = CreatePivot();
PositionEntity(m_Camera,EntityPosition(m_tCameraPivot,GLOBAL_SPACE),GLOBAL_SPACE);
EntityParent(m_tCameraPivot,m_tTargetPivot,GLOBAL_SPACE);
EntityParent(m_Camera,m_tCameraPivot,GLOBAL_SPACE);

//	Setup the desired distances
MoveEntity(m_tCameraPivot, Vec3(0.0f,3.0f,-m_fDesiredDistance),GLOBAL_SPACE);
m_fDesiredDistance = EntityDistance(m_tTargetPivot,m_tCameraPivot);

//	Hide the mouse and center it
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

//	Camera was created succesfully
return true;
}

void CCameraController::Update()
{	
//	Handles the Z input
Scroll();

//	We reposition the pivot based on the target
if(m_Target)
{
	TVec3 targetPos = EntityPosition(m_Target,GLOBAL_SPACE);
	PositionEntity(m_tTargetPivot,Vec3(targetPos.X, targetPos.Y + 2.0f, targetPos.Z),GLOBAL_SPACE);
	ThirdPerson();
}
}

void CCameraController::ThirdPerson()
{
//	Get the mouse input and smooth it out
m_fMouseX = Curve(MouseX() - GraphicsWidth() / 2.0f, m_fMouseX, 6.0f/AppSpeed());
m_fMouseY = Curve(MouseY() - GraphicsHeight() / 2.0f, m_fMouseY, 6.0f/AppSpeed());

//	Center the mouse
MoveMouse((int)(GraphicsWidth() / 2.0f), (int)(GraphicsHeight() / 2.0f)); 

//	Rotate the camera based on the input
m_vCameraRotation.X = EntityRotation(m_tTargetPivot).X + m_fMouseY / 5.0f;
m_vCameraRotation.Y = EntityRotation(m_tTargetPivot).Y - m_fMouseX / 5.0f;

//	Lock the X rotation
if(m_vCameraRotation.X > 45.0f) m_vCameraRotation.X = 45.0f;
if(m_vCameraRotation.X < -45.0f) m_vCameraRotation.X = -45.0f;

RotateEntity(m_tTargetPivot, m_vCameraRotation, GLOBAL_SPACE);

//	Perform camera collision
CameraCollision();
}

void CCameraController::Scroll()
{
//	Get the Z input
int nMouseZ = MouseZ();

//	Save the previous distance from the player
float fPrevDistance = m_fDesiredDistance;

//	If the mouse wheel has been scrolled
if (m_nMouseZ != nMouseZ)
{
	m_nMouseZInterp += m_nMouseZ - nMouseZ;
	m_nMouseZ = nMouseZ;
}

//	If we are scrolling out...
if (m_nMouseZInterp > 0)
{
	//	Keep the camera from zooming to far out
	if ((m_fDesiredDistance + float(1.0f/FRAMES) > 8))
	{
		m_fDesiredDistance -= float(1.0f/FRAMES);
		m_nDeltaZ = ZSCROLLMAX - 1;
	}

	//	Move the camera
	m_fDesiredDistance += float(1.0f/FRAMES);
	m_nDeltaZ++; 

	//	Check if we are zoomed all the way out
	if (m_nDeltaZ == ZSCROLLMAX) 
	{
		//	Reset the counters
		m_nDeltaZ = 0;
		m_nMouseZInterp--;
	}
}	//	If we are zooming in...
else if (m_nMouseZInterp < 0) 
{
	//	Keep the camera from zooming to far in
	if ((m_fDesiredDistance + float(1.0f/FRAMES) < 2.0f))
	{
		m_fDesiredDistance = 2.0f;
		m_nDeltaZ = ZSCROLLMAX - 1;
	}

	//	Move the camera
	m_fDesiredDistance -= float(1.0f/FRAMES);
	m_nDeltaZ++;

	//	Check if we are at max zoom
	if (m_nDeltaZ == ZSCROLLMAX)
	{
		//	Reset the counters
		m_nDeltaZ = 0;
		m_nMouseZInterp++;
	}
}

// finding how much we moved and then moving that much
float fMoveDelta = fPrevDistance - m_fDesiredDistance;
MoveEntity(m_tCameraPivot,Vec3(0.0f,0.0f,fMoveDelta),GLOBAL_SPACE);
}

void CCameraController::CameraCollision()
{
//	TODO: Add code to this function
}

void CCameraController::SetTarget(TEntity Target)
{
m_Target = Target;
if (Target == NULL)
{
	return;
}

PositionEntity(m_tTargetPivot,EntityPosition(Target,GLOBAL_SPACE),GLOBAL_SPACE);
RotateEntity(m_tTargetPivot,EntityRotation(Target,GLOBAL_SPACE),GLOBAL_SPACE);
PointEntity(m_tCameraPivot,m_tTargetPivot,3);
}

 

Both 'Platform.h', 'Configuration.h', and 'LevelManager.h/cpp' are taken directly from Jecklyn Heights at the moment, I can post those also. I wasn't sure what you would need to look at so I posted all of the stuff I have changed or worked on. I also wasn't sure if you would need the headers, those can also be posted.

 

Thanks,

David

Link to comment
Share on other sites

// Create our camera pivots and parrents them accordingly

 

There are issue's to be aware of when parenting the framewerk camera.

 

http://leadwerks.com/werkspace/index.php?/topic/793-fw-main-camera-and-pivots/

  • Upvote 1

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

There are issue's to be aware of when parenting the framewerk camera.http://leadwerks.com/werkspace/index.php?/topic/793-fw-main-camera-and-pivots/

 

Thanks! That pretty much explains everything about why this isn't working... now to rewrite it to not use the pivot parenting and go back to having my water look good. :lol:

 

-David

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...