Created
March 25, 2014 17:27
-
-
Save Noxalus/9766856 to your computer and use it in GitHub Desktop.
Multiple camera rendering problem with render target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "minko/Minko.hpp" | |
#include "minko/MinkoSDL.hpp" | |
#include "minko/MinkoPNG.hpp" | |
using namespace minko; | |
using namespace minko::math; | |
using namespace minko::component; | |
const uint WINDOW_WIDTH = 800; | |
const uint WINDOW_HEIGHT = 600; | |
int | |
main(int argc, char** argv) | |
{ | |
auto canvas = Canvas::create("Minko Example - Reflection", WINDOW_WIDTH, WINDOW_HEIGHT); | |
auto sceneManager = component::SceneManager::create(canvas->context()); | |
sceneManager->assets() | |
->registerParser<file::PNGParser>("png") | |
->queue("effect/Basic.effect") | |
->queue("texture/box.png") | |
; | |
auto complete = sceneManager->assets()->complete()->connect([&](file::AssetLibrary::Ptr assets) | |
{ | |
auto root = scene::Node::create("root") | |
->addComponent(sceneManager); | |
auto cameraTarget = Vector3::create(); | |
// Render target | |
auto renderTarget = render::Texture::create( | |
assets->context(), clp2(WINDOW_WIDTH), clp2(WINDOW_HEIGHT), false, true); | |
// Create reflected camera | |
auto reflectedCamera = scene::Node::create("reflectedCamera") | |
->addComponent(Renderer::create(0xff000000, renderTarget, assets->effect("effect/Basic.effect"))) | |
->addComponent(PerspectiveCamera::create( | |
(float) WINDOW_WIDTH / (float) WINDOW_HEIGHT, (float) PI * 0.25f, .1f, 1000.f) | |
) | |
->addComponent(Transform::create(Matrix4x4::create() | |
->lookAt(cameraTarget, Vector3::create(0.f, -3.f, -5.f))) | |
); | |
// Create main camera | |
auto camera = scene::Node::create("camera") | |
->addComponent(Renderer::create(0x7f7f7fff)) | |
->addComponent(PerspectiveCamera::create( | |
(float) WINDOW_WIDTH / (float) WINDOW_HEIGHT, (float) PI * 0.25f, .1f, 1000.f | |
) | |
) | |
->addComponent(Transform::create(Matrix4x4::create() | |
->lookAt(cameraTarget, Vector3::create(0.f, 3.f, -5.f))) | |
); | |
// Create cube node | |
auto cube = scene::Node::create("cube") | |
->addComponent(Transform::create(Matrix4x4::create()->appendTranslation(0.f, 1.f, 0.f))) | |
->addComponent(Surface::create( | |
geometry::CubeGeometry::create(assets->context()), | |
material::BasicMaterial::create()->diffuseColor(Vector4::create(0.f, 0.f, 1.f, 1.f)), | |
assets->effect("effect/Basic.effect") | |
) | |
); | |
// Create reflection plane | |
auto reflectionPlane = scene::Node::create("reflectionPlane") | |
->addComponent(Transform::create( | |
Matrix4x4::create() | |
->appendScale(5.f) | |
->appendRotationX(-PI / 2.f) | |
->appendTranslation(0.f, 0, 0.f) | |
) | |
) | |
->addComponent(Surface::create( | |
geometry::QuadGeometry::create( | |
assets->context()), | |
material::Material::create()->set("diffuseMap", assets->texture("texture/box.png")), | |
assets->effect("effect/Basic.effect") | |
) | |
); | |
// Add cameras to the scene root | |
root->addChild(reflectedCamera); | |
root->addChild(camera); | |
// Add geometry to the root node | |
root->addChild(cube); | |
root->addChild(reflectionPlane); | |
auto enterFrame = canvas->enterFrame()->connect([&](Canvas::Ptr canvas, uint t, float dt) | |
{ | |
reflectionPlane->component<Surface>()->material()->set("diffuseMap", renderTarget), | |
sceneManager->nextFrame(t, dt); | |
}); | |
canvas->run(); | |
}); | |
sceneManager->assets()->load(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment