Commit 56f61d27 authored by nicoo's avatar nicoo

edit PostProcessing

- instanciation requires a root node used by the shader.
- add assert to constructor.
- comment hard coded shader code. Call water shader and use it on the root
  node.
parent dee1e93f
Pipeline #26050056 failed with stage
in 8 minutes and 47 seconds
#include "postprocessing.hpp"
#include <iostream>
#include <cassert>
#include <components/resource/resourcesystem.hpp>
......@@ -24,12 +25,17 @@ namespace nicoo
namespace MWRender
{
PostProcessing::PostProcessing(Resource::ResourceSystem *resourceSystem)
PostProcessing::PostProcessing(Resource::ResourceSystem *resourceSystem
, osg::Group* rootNode)
: mResourceSystem(resourceSystem)
, mRootNode(rootNode)
{
assert(mResourceSystem == nullptr);
assert(mRootNode == nullptr);
nicoo::print("PostProcessing()", static_cast<void*>(this));
updatePostProcessing();
// updatePostProcessing();
}
PostProcessing::~PostProcessing()
......@@ -41,6 +47,12 @@ namespace MWRender
PostProcessing::TEST()
{
nicoo::print("TEST()", static_cast<void*>(this));
// quick'n'dirty!
if (not mShaderApplied) {
nicoo::print("not shadderApplied", static_cast<void*>(this));
mShaderApplied = true;
createShaderPostProcessingStateSet();
}
}
void
......@@ -58,27 +70,51 @@ namespace MWRender
auto& shaderMgr = mResourceSystem->getSceneManager()->getShaderManager();
const char* fragmentSource =
"void main()"
"{"
"gl_FragColor = {1.0, 1.0, 1.0, 1.0};"
"}";
const char* vertexSource =
"void main()"
"{"
"}";
osg::ref_ptr<osg::Shader> fragmentShader = new osg::Shader( osg::Shader::FRAGMENT);
fragmentShader->setShaderSource(fragmentSource);
osg::ref_ptr<osg::Shader> vertexShader = new osg::Shader( osg::Shader::VERTEX);
vertexShader->setShaderSource(vertexSource);
// NOTE: shader tested on http://shdr.bkcore.com/ but not working in openmw engine.
// NOTE: source of vertexSource from http://shdr.bkcore.com/.
// const char* fragmentSource =
// "void main()"
// "{"
// "gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"
// "}";
// const char* vertexSource =
// "precision highp float;"
// "attribute vec3 position;"
// "attribute vec3 normal;"
// "uniform mat3 normalMatrix;"
// "uniform mat4 modelViewMatrix;"
// "uniform mat4 projectionMatrix;"
// "varying vec3 fNormal;"
// "varying vec3 fPosition;"
// ""
// "void main()"
// "{"
// "fNormal = normalize(normalMatrix * normal);"
// "vec4 pos = modelViewMatrix * vec4(position, 1.0);"
// "fPosition = pos.xyz;"
// "gl_Position = projectionMatrix * pos;"
// "}";
// osg::ref_ptr<osg::Shader> fragmentShader = new osg::Shader( osg::Shader::FRAGMENT);
// fragmentShader->setShaderSource(fragmentSource);
// osg::ref_ptr<osg::Shader> vertexShader = new osg::Shader( osg::Shader::VERTEX);
// vertexShader->setShaderSource(vertexSource);
std::map<std::string, std::string> defineMap;
defineMap.insert(std::make_pair(std::string("refraction_enabled"), std::string("1")));
osg::ref_ptr<osg::Shader> vertexShader (shaderMgr.getShader("water_vertex.glsl", defineMap, osg::Shader::VERTEX));
osg::ref_ptr<osg::Shader> fragmentShader (shaderMgr.getShader("water_fragment.glsl", defineMap, osg::Shader::FRAGMENT));
auto program = shaderMgr.getProgram(vertexShader, fragmentShader);
osg::ref_ptr<osg::StateSet> shaderStateset = new osg::StateSet;
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
mRootNode->setStateSet(shaderStateset);
}
}
......@@ -2,6 +2,7 @@
#define OPENMW_MWRENDER_POSTPROCESSING_H
#include <osg/ref_ptr>
#include <osg/Group>
namespace Resource
{
......@@ -12,12 +13,15 @@ namespace MWRender
{
class PostProcessing
{
private:
void updatePostProcessing();
void createShaderPostProcessingStateSet();
Resource::ResourceSystem* mResourceSystem;
Resource::ResourceSystem* mResourceSystem {nullptr};
bool mShaderApplied {false};
osg::Group* mRootNode {nullptr};
public:
PostProcessing(Resource::ResourceSystem* resourceSystem);
PostProcessing(Resource::ResourceSystem* resourceSystem, osg::Group* rootNode);
~PostProcessing();
void TEST();
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment