Jump to content

Shaders With C++


gamecreator
 Share

Recommended Posts

Maybe if you gave some actual information concerning the problem, someone could give advice on how to resolve instead of just guessing what the problem could be? wink.png

 

Is it a particular shader effect thats not working? Is something not loading correctly? Maybe post a small demo showing the problem.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Found out what was causing it.

 

camera->SetParent(controller_pivot, true);

 

I have my camera parented to a controller pivot (to follow behind my character, in third person). As soon as I comment this code out, the shaders work. I can set the camera's position manually, of course, but is there a way to work around this?

Link to comment
Share on other sites

Yeah. The parenting is done in the initial setup code. I have this in my main loop to turn the shaders off and on at will:

 

if(window->KeyHit(Key::NumPad1)) camera->AddPostEffect("Shaders/PostEffects/00_Underwater+Caustics.lua");
if(window->KeyHit(Key::NumPad2)) camera->AddPostEffect("Shaders/PostEffects/04_pp_dof.lua");
if(window->KeyHit(Key::NumPad0)) camera->ClearPostEffects();

 

Works perfectly without the parenting. Mostly doesn't work with it set.

 

Edit: so this may be something to do with the pivot. I'm altering my test code now too and there it works even with the pivot parenting. Bah.

Link to comment
Share on other sites

  • 2 weeks later...

Ok. I took the time to create a new project from scratch, new map and for a while the camera parenting and shaders worked fine. But somewhere after I put the camera into the player class, it stopped working. Not sure why. Again, if you comment out the SetParent, it works.

 

Here's the project: http://www.mediafire.com/download/c88y8vof1382ara/ShaderTest.zip

 

Thanks to anyone who can take a look. And in the effort of saving everyone time, here's what player.cpp looks like:

 

#include "world.h"
#include "player.h"

using namespace Leadwerks;

playerclass player[10];

void playerclass::think()
{
}

void playerclass::initialize(float xx, float yy, int which)
{
  x=xx, y=yy;

  controller = Pivot::Create();

  model = Model::Load("Models/fir.mdl");
  model->SetParent(controller, false);
  model->SetRotation(90, 180, 0, true);

  controller->SetShadowMode(Light::Dynamic);
  controller->SetPosition(xx, 12, yy, false);

  //  Commented these out for now to make things easier to debug
  // controller->SetMass(1);
  // controller->SetPhysicsMode(Entity::CharacterPhysics);

  camera->SetPosition(xx, 17.5, yy-1.9, true);
  camera->SetRotation(10, 0, 0);

  //  COMMENT THIS OUT TO GET SHADERS WORKING
  camera->SetParent(controller, true);

}

playerclass::playerclass()
{
  x=0.0;
  y=0.0;
  speed=1.5;
}

 

Thanks!

Link to comment
Share on other sites

I suspect the problem is one of his Lua-based effects. He's probably calling camera:GetPosition() and retrieving the local position instead of the global one, which will be different if the entity has a parent.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

No post shaders were in your uploaded project so all failed to load. But I just copied some off another project.

 

In underwater shader replace line 57: (your reflection camera scale doesn't seem to be 1 but 0.99999..) , and add (true) to getposition since your camera is parented:

  	 if camera:GetScale().y>.9 and camera:GetPosition(true).y <= height

 

dof shader... replace line 20 (since your refl. cam doesn't have a scale of 1, why is that??):

and camera:GetScale().y>.9

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

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