Commit cbc5fe16 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX] proper lighting (zoom-invariant) for the template module

parent 476081cc
......@@ -34,7 +34,13 @@ void main()
// prepare light
v_normal = gl_NormalMatrix * gl_Normal;
gl_FrontColor = gl_Color;
vec4 color = gl_FrontMaterial.diffuse;
vec4 color = gl_Color;
gl_FrontColor = color;
gl_BackColor = color;
gl_Position = ftransform();
......@@ -436,6 +436,16 @@ void WMTemplate::moduleMain()
// This always returns if you manually add your module and no project file loader or something similar has to restore any values.
// Before we begin, we finally create a shader object which shades the graphics we create in this module. You can use your own shaders or a
// global one, like WGELighting. When creating a shader, you need to specify its name and an optional search path. When developing modules,
// this search path should be you module's local resource path.
m_shader = new WGEShader( "WGELighting", m_localPath );
// Later in the code, we show how we use a property to modify the graphics color. There, we use the OpenGL material mechanism. So we need to
// switch the shader to this mode by setting a compile-time switch:
m_shader->setDefine( "USE_MATERIAL_DIFFUSE" );
// There are multiple ways to set uniforms and defines automatically by binding them to properties. But this is not the topic of this module.
// Normally, you will have a loop which runs as long as the module should not shutdown. In this loop you can react on changing data on input
// connectors or on changed in your properties.
debugLog() << "Entering main loop";
......@@ -587,6 +597,10 @@ void WMTemplate::moduleMain()
// right? Setting the color can be done in such an update callback. See in the header file, how this class is defined.
m_geode->addUpdateCallback( new SafeUpdateCallback( this ) );
// The default lighting is not very pretty. We can bind a default shader provided by OpenWalnut to this geode to have nice per-pixel
// Phong shading. We earlier created this shader object. Now, we need to apply it:
m_shader->apply( m_geode );
// And insert the new node
m_rootNode->insert( m_geode );
......@@ -33,6 +33,7 @@
#include "core/common/WItemSelector.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
......@@ -302,6 +303,11 @@ private:
void hideButtonPressed();
* We want some nice shading effects, so we need a nice shader.
WGEShader::RefPtr m_shader;
* Node callback to change the color of the shapes inside the root node. For more details on this class, refer to the documentation in
* moduleMain().
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