Fixed render targets; renamed GuiTest to Editor
This commit is contained in:
@@ -76,10 +76,10 @@ target_link_libraries(0_Bootstrap OgreBites OgreBullet OgrePaging ${BULLET_DYNAM
|
||||
target_include_directories(0_Bootstrap PUBLIC OgreBites OgrePaging OgreBullet)
|
||||
add_dependencies(0_Bootstrap stage_files)
|
||||
|
||||
add_executable(GuiTest GuiTest.cpp ${TERRAIN_SRC} ${WATER_SRC})
|
||||
target_link_libraries(GuiTest OgreBites OgreBullet OgrePaging OgreTerrain OgreMeshLodGenerator ${OgreProcedural_LIBRARIES} ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY})
|
||||
target_include_directories(GuiTest PUBLIC OgreBites OgrePaging OgreBullet OgreTerrain OgreMeshLodGenerator ${OgreProcedural_INCLUDE_DIRS})
|
||||
add_dependencies(GuiTest stage_files import_buildings)
|
||||
add_executable(Editor Editor.cpp ${TERRAIN_SRC} ${WATER_SRC})
|
||||
target_link_libraries(Editor OgreBites OgreBullet OgrePaging OgreTerrain OgreMeshLodGenerator ${OgreProcedural_LIBRARIES} ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY})
|
||||
target_include_directories(Editor PUBLIC OgreBites OgrePaging OgreBullet OgreTerrain OgreMeshLodGenerator ${OgreProcedural_INCLUDE_DIRS})
|
||||
add_dependencies(Editor stage_files import_buildings)
|
||||
|
||||
add_executable(Procedural Procedural.cpp ${TERRAIN_SRC})
|
||||
target_link_libraries(Procedural OgreBites OgreBullet OgrePaging OgreTerrain OgreProcedural::OgreProcedural ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY})
|
||||
@@ -111,7 +111,7 @@ if(NOT OGRE_DYNAMIC)
|
||||
target_link_libraries(TerrainTest fix::assimp pugixml)
|
||||
target_link_libraries(Procedural fix::assimp pugixml)
|
||||
target_link_libraries(0_Bootstrap fix::assimp pugixml)
|
||||
target_link_libraries(GuiTest fix::assimp pugixml)
|
||||
target_link_libraries(Editor fix::assimp pugixml)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -234,5 +234,5 @@ add_custom_target(remove_scenes COMMAND rm -f ${CREATE_SCENES})
|
||||
|
||||
add_custom_target(import_vrm DEPENDS ${CREATE_SCENES})
|
||||
|
||||
install(TARGETS GuiTest DESTINATION bin)
|
||||
install(TARGETS Editor DESTINATION bin)
|
||||
|
||||
|
||||
@@ -285,6 +285,8 @@ class App : public OgreBites::ApplicationContext {
|
||||
// Ogre::Root::getSingleton().queueEndRendering();
|
||||
mApp->setWindowGrab(false);
|
||||
}
|
||||
if (evt.keysym.sym == OgreBites::SDLK_SPACE)
|
||||
mApp->dump_water();
|
||||
if (evt.keysym.sym == 'w')
|
||||
motion.z = -1.0f;
|
||||
if (evt.keysym.sym == 's')
|
||||
@@ -364,6 +366,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
mApp->updateCamera(evt.timeSinceLastFrame);
|
||||
mApp->updateSun(evt.timeSinceLastFrame);
|
||||
mApp->updateTerrain(evt.timeSinceLastFrame);
|
||||
mApp->updateWater(evt.timeSinceLastFrame);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -402,6 +405,10 @@ public:
|
||||
void loadResources() override
|
||||
{
|
||||
}
|
||||
void dump_water()
|
||||
{
|
||||
m_water.dump_textures();
|
||||
}
|
||||
|
||||
void initCamera()
|
||||
{
|
||||
@@ -641,6 +648,10 @@ public:
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void updateWater(float delta)
|
||||
{
|
||||
m_water.updateWater(delta);
|
||||
}
|
||||
void createContent()
|
||||
{
|
||||
int i;
|
||||
@@ -674,7 +685,6 @@ public:
|
||||
"Skybox/Dynamic", "General");
|
||||
OgreAssert(m, "Sky box material not found.");
|
||||
m->load();
|
||||
getRoot()->addFrameListener(&m_water);
|
||||
#endif
|
||||
}
|
||||
void create_entity_node(const Ogre::String &name, int key)
|
||||
@@ -9,8 +9,7 @@ static const uint32_t SUBMERGED_MASK = 0x0F0;
|
||||
static const uint32_t SURFACE_MASK = 0x00F;
|
||||
static const uint32_t WATER_MASK = 0xF00;
|
||||
Water::Water()
|
||||
: FrameListener()
|
||||
, RenderTargetListener()
|
||||
: RenderTargetListener()
|
||||
, mWaterNode(nullptr)
|
||||
, mScnMgr(nullptr)
|
||||
, mWindow(nullptr)
|
||||
@@ -31,6 +30,10 @@ Water::~Water()
|
||||
mScnMgr->destroySceneNode(mWaterNode);
|
||||
if(mReflectionTexture)
|
||||
mReflectionTexture->removeAllListeners();
|
||||
#if 0
|
||||
if(mRefractionTexture)
|
||||
mRefractionTexture->removeAllListeners();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Water::create_cameras()
|
||||
@@ -44,13 +47,16 @@ void Water::create_cameras()
|
||||
mReflectionCamera->enableCustomNearClipPlane(mReflectionClipPlaneAbove);
|
||||
mReflectionCamera->enableReflection(mReflectionPlane);
|
||||
|
||||
Ogre::Viewport * reflectionViewport = mReflectionTexture->addViewport(mReflectionCamera);
|
||||
Ogre::Viewport * reflectionViewport = mReflectionTexture->addViewport(mReflectionCamera, 0, 0, 0, 0.5f, 1.0f);
|
||||
reflectionViewport->setClearEveryFrame(true);
|
||||
reflectionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 0.0));
|
||||
reflectionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 1.0, 1.0));
|
||||
reflectionViewport->setOverlaysEnabled(false);
|
||||
// reflectionViewport->setVisibilityMask(0xFFF);
|
||||
reflectionViewport->setSkiesEnabled(true);
|
||||
reflectionViewport->setAutoUpdated(false);
|
||||
mViewports.push_back(reflectionViewport);
|
||||
|
||||
mRefractionTexture->addListener(this);
|
||||
// mRefractionTexture->addListener(this);
|
||||
#if 1
|
||||
mRefractionCamera = mScnMgr->createCamera("RefractionCamera");
|
||||
mCamera->getParentSceneNode()->attachObject(mRefractionCamera);
|
||||
mRefractionCamera->setAspectRatio(mCamera->getAspectRatio());
|
||||
@@ -58,24 +64,29 @@ void Water::create_cameras()
|
||||
mRefractionCamera->setFarClipDistance(mCamera->getFarClipDistance());
|
||||
mRefractionCamera->enableCustomNearClipPlane(mRefractionClipPlaneAbove);
|
||||
|
||||
Ogre::Viewport * refractionViewport = mRefractionTexture->addViewport(mRefractionCamera);
|
||||
Ogre::Viewport * refractionViewport = mReflectionTexture->addViewport(mRefractionCamera, 1, 0.5, 0, 0.5f, 1.0f);
|
||||
refractionViewport->setClearEveryFrame(true);
|
||||
refractionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 0.0));
|
||||
refractionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.5, 1.0, 1.0));
|
||||
refractionViewport->setOverlaysEnabled(false);
|
||||
refractionViewport->setSkiesEnabled(false);
|
||||
refractionViewport->setAutoUpdated(false);
|
||||
mViewports.push_back(refractionViewport);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Water::create_textures()
|
||||
{
|
||||
Ogre::TexturePtr reflectionTexture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"ReflectionTexture",
|
||||
"ReflectionRefractionTexture",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, 256, 256,
|
||||
Ogre::TEX_TYPE_2D, 512, 512,
|
||||
0,
|
||||
Ogre::PF_R8G8B8A8,
|
||||
Ogre::TU_RENDERTARGET);
|
||||
|
||||
mReflectionTexture = reflectionTexture->getBuffer()->getRenderTarget();
|
||||
mReflectionTexture->setAutoUpdated(false);
|
||||
#if 0
|
||||
Ogre::TexturePtr refractionTexture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"RefractionTexture",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
@@ -85,19 +96,20 @@ void Water::create_textures()
|
||||
Ogre::TU_RENDERTARGET);
|
||||
|
||||
mRefractionTexture = refractionTexture->getBuffer()->getRenderTarget();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Water::init()
|
||||
{
|
||||
int i;
|
||||
float w = 600.0f;
|
||||
float w = 1000.0f;
|
||||
// mWindow->addListener(this);
|
||||
create_cameras();
|
||||
Ogre::MeshPtr water_plane =
|
||||
Ogre::MeshManager::getSingleton().createPlane(
|
||||
"water",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
mWaterPlane, w, w, 10, 10, true, 1, 100, 100,
|
||||
mWaterPlane, w, w, 100, 100, true, 1, 100, 100,
|
||||
Ogre::Vector3::UNIT_Z);
|
||||
if (!Ogre::MeshLodGenerator::getSingletonPtr())
|
||||
new Ogre::MeshLodGenerator();
|
||||
@@ -146,6 +158,9 @@ void Water::init()
|
||||
water_lod1->setVisibilityFlags(WATER_MASK);
|
||||
mWaterMeshes.push_back(water_lod1);
|
||||
}
|
||||
/*
|
||||
Ogre::Root::getSingleton().addFrameListener(this);
|
||||
*/
|
||||
}
|
||||
|
||||
void Water::createWater(Ogre::RenderWindow * window, Ogre::Camera *camera)
|
||||
@@ -183,8 +198,16 @@ void Water::updateWater(float delta)
|
||||
mWaterMeshes[i]->setMaterialName("Water/Above");
|
||||
}
|
||||
}
|
||||
for (i = 0; i < mWaterMeshes.size(); i++)
|
||||
mWaterMeshes[i]->setVisible(false);
|
||||
for (i = 0; i < mViewports.size(); i++)
|
||||
mViewports[i]->update();
|
||||
// mReflectionTexture->update();
|
||||
for (i = 0; i < mWaterMeshes.size(); i++)
|
||||
mWaterMeshes[i]->setVisible(true);
|
||||
}
|
||||
|
||||
/*
|
||||
bool Water::frameEnded(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
updateWater(evt.timeSinceLastFrame);
|
||||
@@ -194,11 +217,12 @@ bool Water::frameRenderingQueued(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
return FrameListener::frameRenderingQueued(evt);
|
||||
}
|
||||
*/
|
||||
|
||||
void Water::preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
|
||||
{
|
||||
int i;
|
||||
if (evt.source == mReflectionTexture || evt.source == mRefractionTexture) {
|
||||
if (evt.source == mReflectionTexture /*|| evt.source == mRefractionTexture */) {
|
||||
for (i = 0; i < mWaterMeshes.size(); i++)
|
||||
mWaterMeshes[i]->setVisible(false);
|
||||
if (evt.source == mReflectionTexture)
|
||||
@@ -230,5 +254,5 @@ void Water::add_surface_entity(Ogre::Entity *ent)
|
||||
void Water::dump_textures()
|
||||
{
|
||||
mReflectionTexture->writeContentsToFile("Reflection.png");
|
||||
mRefractionTexture->writeContentsToFile("Refraction.png");
|
||||
// mRefractionTexture->writeContentsToFile("Refraction.png");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
|
||||
#include <OgreUnifiedShader.h>
|
||||
// SAMPLER2D(noiseMap, 0);
|
||||
SAMPLER2D(reflectMap, 0);
|
||||
SAMPLER2D(refractMap, 1);
|
||||
// SAMPLER2D(refractMap, 1);
|
||||
OGRE_UNIFORMS(
|
||||
uniform vec4 viewportSize;
|
||||
uniform f32vec4 cameraPosition;
|
||||
@@ -16,8 +16,8 @@ MAIN_DECLARATION
|
||||
screenUV.y = 1.0 - screenUV.y * 0.6 - 0.2;
|
||||
// vec2 final = projectionCoord.xy / projectionCoord.w;
|
||||
float depth = saturate(length(positionWS - cameraPosition.xyz) * 0.01);
|
||||
vec4 reflectionColour = texture2D(reflectMap, screenUV);
|
||||
vec4 refractionColour = texture2D(refractMap, screenUV);
|
||||
vec4 reflectionColour = texture2D(reflectMap, screenUV * vec2(0.5, 1.0));
|
||||
vec4 refractionColour = texture2D(reflectMap, screenUV * vec2(0.5, 1.0) + vec2(0.5, 0.0));
|
||||
vec4 result = mix(mix(reflectionColour, refractionColour, 0.5), vec4(0.0, 1.0, 1.0, 1.0), depth);
|
||||
result.a = 1.0;
|
||||
gl_FragColor = result;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define MAT_WATER_H
|
||||
#include <Ogre.h>
|
||||
class App;
|
||||
class Water : public Ogre::FrameListener, Ogre::RenderTargetListener {
|
||||
class Water : public /* Ogre::FrameListener, */ Ogre::RenderTargetListener {
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
Ogre::RenderWindow * mWindow;
|
||||
Ogre::SceneNode *mWaterNode, *mCameraNode;
|
||||
@@ -16,11 +16,12 @@ class Water : public Ogre::FrameListener, Ogre::RenderTargetListener {
|
||||
mRefractionClipPlaneBelow;
|
||||
bool mAbove;
|
||||
std::vector<Ogre::Entity *> mWaterMeshes;
|
||||
std::vector<Ogre::Viewport *> mViewports;
|
||||
// Reflection
|
||||
Ogre::RenderTexture * mReflectionTexture;
|
||||
Ogre::Camera * mReflectionCamera;
|
||||
// Refraction
|
||||
Ogre::RenderTexture * mRefractionTexture;
|
||||
// Ogre::RenderTexture * mRefractionTexture;
|
||||
Ogre::Camera * mRefractionCamera;
|
||||
bool mInRefTexUpdate;
|
||||
Ogre::Timer mtexture_dump;
|
||||
@@ -34,8 +35,8 @@ public:
|
||||
void createWater(Ogre::RenderWindow * window, Ogre::Camera *camera);
|
||||
void init();
|
||||
void updateWater(float delta);
|
||||
bool frameEnded(const Ogre::FrameEvent &evt) override;
|
||||
bool frameRenderingQueued(const Ogre::FrameEvent &evt) override;
|
||||
/* bool frameEnded(const Ogre::FrameEvent &evt) override; */
|
||||
/* bool frameRenderingQueued(const Ogre::FrameEvent &evt) override; */
|
||||
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override;
|
||||
void
|
||||
postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override;
|
||||
|
||||
@@ -94,14 +94,18 @@ material Water/Above
|
||||
*/
|
||||
texture_unit
|
||||
{
|
||||
texture ReflectionTexture
|
||||
texture ReflectionRefractionTexture
|
||||
tex_address_mode mirror
|
||||
filtering linear linear linear
|
||||
}
|
||||
/*
|
||||
texture_unit
|
||||
{
|
||||
texture RefractionTexture
|
||||
tex_address_mode mirror
|
||||
filtering linear linear linear
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,14 +152,18 @@ material Water/Below
|
||||
*/
|
||||
texture_unit
|
||||
{
|
||||
texture ReflectionTexture
|
||||
texture ReflectionRefractionTexture
|
||||
tex_address_mode mirror
|
||||
filtering linear linear linear
|
||||
}
|
||||
/*
|
||||
texture_unit
|
||||
{
|
||||
texture RefractionTexture
|
||||
tex_address_mode mirror
|
||||
filtering linear linear linear
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ fragment_program Water/water_fp glsl glsles glslang hlsl
|
||||
param_named noiseScale float 0.03
|
||||
// param_named noiseMap int 0
|
||||
param_named reflectMap int 0
|
||||
param_named refractMap int 1
|
||||
// param_named refractMap int 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ IN(vec4 vertex, POSITION)
|
||||
IN(vec3 normal, NORMAL)
|
||||
// IN(vec3 tangent, TANGENT)
|
||||
IN(vec3 uv0, TEXCOORD0)
|
||||
OUT(mat3 rotMatrix, TEXCOORD0)
|
||||
OUT(vec4 bumpCoordA, TEXCOORD1)
|
||||
OUT(vec4 bumpCoordB, TEXCOORD2)
|
||||
OUT(vec3 noiseCoord, TEXCOORD3)
|
||||
OUT(mat3 rotMatrix, TEXCOORD1)
|
||||
//OUT(vec4 bumpCoordA, TEXCOORD2)
|
||||
//OUT(vec4 bumpCoordB, TEXCOORD3)
|
||||
// OUT(vec3 noiseCoord, TEXCOORD4)
|
||||
OUT(highp vec4 projectionCoord, TEXCOORD4)
|
||||
OUT(vec3 eyeDir, TEXCOORD5)
|
||||
OUT(vec3 oNormal, TEXCOORD6)
|
||||
//OUT(vec3 eyeDir, TEXCOORD5)
|
||||
//OUT(vec3 oNormal, TEXCOORD6)
|
||||
OUT(f32vec3 positionWS, TEXCOORD7)
|
||||
MAIN_DECLARATION
|
||||
{
|
||||
@@ -78,8 +78,8 @@ MAIN_DECLARATION
|
||||
projectionCoord = mul(textureProjMatrix, vertex);
|
||||
|
||||
// Noise map coords
|
||||
noiseCoord.xy = (uv0.xy + (time * scroll)) * scale;
|
||||
noiseCoord.z = noise * time;
|
||||
// noiseCoord.xy = (uv0.xy + (time * scroll)) * scale;
|
||||
// noiseCoord.z = noise * time;
|
||||
// wave synthesis using two sine waves at different frequencies and phase shift
|
||||
for(int i = 0; i<NWAVES; ++i)
|
||||
{
|
||||
@@ -99,12 +99,14 @@ MAIN_DECLARATION
|
||||
rotMatrix = mat3(T, B, N);
|
||||
gl_Position = P;
|
||||
// calculate texture coordinates for normal map lookup
|
||||
#if 0
|
||||
bumpCoordA.xy = uv0.xy * textureScale + time * bumpSpeed;
|
||||
bumpCoordA.zw = uv0.xy * textureScale * 2.0 + time * bumpSpeed * 4.0;
|
||||
bumpCoordB.xy = uv0.xy * textureScale * 4.0 + time * bumpSpeed * 8.0;
|
||||
#endif
|
||||
|
||||
eyeDir = normalize(R.xyz - eyePosition);
|
||||
oNormal = normalize(normal + N);
|
||||
// eyeDir = normalize(R.xyz - eyePosition);
|
||||
// oNormal = normalize(normal + N);
|
||||
positionWS = mul(world, vertex).xyz;
|
||||
#else
|
||||
gl_Position = worldViewProj * vertex;
|
||||
|
||||
Reference in New Issue
Block a user