OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Glow
View page
Source of version: 9
(current)
This page explains how to add glow to your scene. As example of what we mean some before/after pictures are below. If you are looking for stencil glow, have a look at this topic: http://www.ogre3d.org/forums/viewtopic.php?f=11&t=27477 !!Examples {img fileId="1588" alt="Glow_overview.jpg"} a=texture, b=glow mask, c=result {img fileId="1589" alt="Glow_off.png"} Glow (and HDR) disabled {img fileId="1590" alt="Glow_on.png"} Glow and HDR on !!Files You will need to add these files to your resources: !!!glow.compositor {CODE(wrap="1", colors="c++")}compositor Glow { technique { texture rt0 target_width target_height PF_A8R8G8B8 texture glowMap target_width target_height PF_A8R8G8B8 texture AtoB target_width target_height PF_A8R8G8B8 //Fetch scene contents. target rt0 { input previous } //Get scene rendered with 'Glow' scheme target glowMap { input none material_scheme glow pass clear { } pass render_scene { } } //Blur it along X. target AtoB { input none pass clear { } pass render_quad { material GlowCompositorMat/GlowA input 0 glowMap } } //Blur along Y, add to original, and output. target_output { input none pass render_quad { material GlowCompositorMat/GlowB input 0 rt0 input 1 AtoB } } } }{CODE} === glow.cg === {CODE(wrap="1", colors="c++")}//A. float4 GlowA_fp ( float2 uv: TEXCOORD0, uniform sampler2D scene: register(s0), uniform float4 invTexSize //uniform float time ) : COLOR #define RENDER_SCENE 1 #define BLUR_RADIUS 2 { float4 colour = float4(0); float blurSize = BLUR_RADIUS * invTexSize.x; //X-blur. colour += tex2D(scene, float2(uv.x - 4.0*blurSize, uv.y)) * 1.0/25.0; colour += tex2D(scene, float2(uv.x - 3.0*blurSize, uv.y)) * 2.0/25.0; colour += tex2D(scene, float2(uv.x - 2.0*blurSize, uv.y)) * 3.0/25.0; colour += tex2D(scene, float2(uv.x - blurSize, uv.y)) * 4.0/25.0; colour += tex2D(scene, float2(uv.x, uv.y)) * 5.0/25.0; colour += tex2D(scene, float2(uv.x + blurSize, uv.y)) * 4.0/25.0; colour += tex2D(scene, float2(uv.x + 2.0*blurSize, uv.y)) * 3.0/25.0; colour += tex2D(scene, float2(uv.x + 3.0*blurSize, uv.y)) * 2.0/25.0; colour += tex2D(scene, float2(uv.x + 4.0*blurSize, uv.y)) * 1.0/25.0; return colour; } //B. float4 GlowB_fp ( float2 uv: TEXCOORD0, uniform sampler2D scene: register(s0), uniform sampler2D blurX: register(s1), uniform float4 invTexSize, uniform float time ) : COLOR { float4 colour = float4(0); float blurSize = BLUR_RADIUS * invTexSize.y; //Y-blur. colour += tex2D(blurX, float2(uv.x, uv.y - 4.0*blurSize)) * 1.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y - 3.0*blurSize)) * 2.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y - 2.0*blurSize)) * 3.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y - blurSize)) * 4.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y)) * 5.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y + blurSize)) * 4.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y + 2.0*blurSize)) * 3.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y + 3.0*blurSize)) * 2.0/25.0; colour += tex2D(blurX, float2(uv.x, uv.y + 4.0*blurSize)) * 1.0/25.0; //Add this to original, return. return #if RENDER_SCENE tex2D(scene, uv) + #endif colour * 4; }{CODE} === glow.program === {CODE(wrap="1", colors="c++")}fragment_program GlowA_fp cg { source glow.cg entry_point GlowA_fp default_params { param_named_auto invTexSize inverse_texture_size 0 //param_named_auto time time_0_2pi 1 } profiles ps_2_0 arbfp1 } material GlowCompositorMat/GlowA { technique { pass { cull_hardware none cull_software none depth_func always_pass fragment_program_ref GlowA_fp { } texture_unit map { tex_coord_set 0 tex_address_mode clamp filtering trilinear } } } } fragment_program GlowB_fp cg { source glow.cg entry_point GlowB_fp default_params { param_named_auto invTexSize inverse_texture_size 0 param_named_auto time time_0_2pi 4 } profiles ps_2_0 arbfp1 } material GlowCompositorMat/GlowB { technique { pass { cull_hardware none cull_software none depth_func always_pass fragment_program_ref GlowB_fp { } texture_unit scene { tex_coord_set 0 tex_address_mode clamp filtering trilinear } texture_unit map { tex_coord_set 0 tex_address_mode clamp filtering trilinear } } } }{CODE} !!!GlowMaterialListener.h (add to your sources) {CODE(wrap="1", colors="c++")}#ifndef GLOWMATERIALLISTENER_H__ #define GLOWMATERIALLISTENER_H__ #include <Ogre.h> #include <OgreMaterialManager.h> class GlowMaterialListener : public Ogre::MaterialManager::Listener { protected: Ogre::MaterialPtr mBlackMat; public: GlowMaterialListener() { mBlackMat = Ogre::MaterialManager::getSingleton().create("mGlowBlack", "Internal"); mBlackMat->getTechnique(0)->getPass(0)->setDiffuse(0,0,0,0); mBlackMat->getTechnique(0)->getPass(0)->setSpecular(0,0,0,0); mBlackMat->getTechnique(0)->getPass(0)->setAmbient(0,0,0); mBlackMat->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,0); } Ogre::Technique *handleSchemeNotFound(unsigned short, const Ogre::String& schemeName, Ogre::Material*mat, unsigned short, const Ogre::Renderable*) { if (schemeName == "glow") { //LogManager::getSingleton().logMessage(">> adding glow to material: "+mat->getName()); return mBlackMat->getTechnique(0); } return NULL; } }; #endif //GLOWMATERIALLISTENER_H__{CODE} !!Load the compositor in your code {CODE(wrap="1", colors="c++")}#include "GlowMaterialListener.h" ... { CompositorManager::getSingleton().addCompositor(mCamera->getViewport(), "Glow"); CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "Glow", true); GlowMaterialListener *gml = new GlowMaterialListener(); Ogre::MaterialManager::getSingleton().addListener(gml); }{CODE} !!Add materials that glow Add a new glow scheme technique to your material. Original material: {CODE(wrap="1", colors="c++")}material AC3D/Box5W900/Mat004_NoTex { technique { pass { emissive 1 1 1 0.3 texture_unit { anim_texture W900_headlight_material.png 2 0 } } } }{CODE} New material: {CODE(wrap="1", colors="c++")}material AC3D/Box5W900/Mat004_NoTex { technique { pass { emissive 1 1 1 0.3 texture_unit { anim_texture W900_headlight_material.png 2 0 } } } technique { scheme glow pass { texture_unit { texture W900_headlight_material_1.png } ambient 1 1 1 diffuse 1 1 1 specular 0 0 0 1 emissive 0 0 0 } } }{CODE} Please note that you can change the amount of the glow by modifying the ambient and diffuse values. (also during runtime) It may help to write a 'base' material to avoid repetition. For example, if 'BaseAmbient' and 'BasePerLight' are your ambient and per-light shaders respectively:- {CODE(wrap="1", colors="c++")}material BaseGlow { set $diffuse_tex "Default.png" set $normal_tex "Default_NM.png" set $glow_tex "Default_GW.png" set $ambient "0.8 0.8 0.8 1" set $diffuse "0.9 0.9 0.9 1" set $specular "0.9 0.9 0.9 1" set $glow_amount "0.7" technique Shaders { pass { ambient $ambient vertex_program_ref BaseAmbient_vp { } fragment_program_ref BaseAmbient_fp { } texture_unit DiffuseMap { texture $diffuse_tex } } pass { max_lights 12 scene_blend add iteration once_per_light diffuse $diffuse specular $specular vertex_program_ref BasePerLight_vp { } fragment_program_ref BasePerLight_fp { } texture_unit DiffuseMap { texture $diffuse_tex } texture_unit NormalMap { } texture_unit ShadowMap { content_type shadow filtering anisotropic max_anisotropy 16 tex_address_mode border tex_border_colour 1 1 1 } } } technique Fallback { pass { ambient $ambient diffuse $diffuse specular $specular texture_unit DiffuseMap { texture $diffuse_tex } } } technique Glow { scheme Scheme/Glow pass { ambient $glow_amount $glow_amount $glow_amount 1 vertex_program_ref BaseAmbient_vp { } fragment_program_ref BaseAmbient_fp { } texture_unit GlowMap { texture $glow_tex } } } }{CODE} Then you can just do this to make a new glowing material, for example:- {CODE(wrap="1", colors="c++")}material Objects/Player : BaseGlow { set $diffuse_tex "Player.png" set $ambient "0.9 0.9 0.9 1" set $diffuse "0.9 0.9 0.9 1" set $specular "0.3 0.3 0.3 1" set $glow_tex "Player_GW.png" set $glow_amount "0.2" }{CODE} !!Debugging You can change "#define RENDER_SCENE 1" to "#define RENDER_SCENE 0" in glow.cg in order to just display glowing objects. Non-glowing objects will be black. --- Written by ((User:Tdev|Tdev))
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
198 online users