Giter Club home page Giter Club logo

ofxdeferredshading's Introduction

ofxDeferredShading

Here is demo.

Concept

Modern OpenGL compatible

I was satisfied with ofxPostPrpcessing long time, which is fabulous and has so many beautiful vfx in it. I really appreciate the author and contributors. But there is little problem when I use my own shaders with it. It is not written in "modern" shader version so cannot coexist with the "programmble renderer". At this moment, however we have to decide to abandon legacy but helpful functions including ofLight, glBegin()-glEnd()...

Photo-realistic in Real-time

And the addon mentioned above has only few effects for photo-real purpose such like "casting shadow". So I decided to reproduce and regather PostProcesses focusing "photo-real" rendering and compatible in modern version.

Now it contains

  • Edge detection
  • Multiple point-lights with attenuation
  • Casting shadow with directional light
    • plus Volumetric light using shadow map
  • SSAO: Screen Space Ambient Occlusion
  • Depth of Field
    • plus Foreground blurring
    • plus Bokeh point rendering
  • Bloom (Kawase's)
  • Volumetric fog

Support

  • openFrameworks 0.10.0~ (using glm library)

Usage

  • specify modern version of OpenGL in main.cpp
int main( ){
    ofGLWindowSettings settings;
    settings.setGLVersion(4, 1); // now we use OpenGL 4.1
    settings.setSize(1024, 768);

    ofCreateWindow(settings);
    ofRunApp(new ofApp());
}
  • declare instances in ofApp.h
    • it's safer to use std::shared_ptr
// declare in ofApp.h
ofxDeferredProcessing deferred;
ofPtr<ofxDeferred::SsaoPass> ssao;
ofPtr<ofxDeferred::PointLightPass> points;
ofPtr<ofxDeferred::ShadowLightPass> shadow;
ofPtr<ofxDeferred::HdrBloomPass> bloom;
...
  • init and create Passes in ofApp::setup(), and get reference of Passes
deferred.init(ofGetWidth(), ofGetHeight());
ssao = deferred.createPass<ofxDeferred::SsaoPass>();
points = deferred.createPass<ofxDeferred::PointLightPass>();
shadow = deferred.createPass<ofxDeferred::ShadowLightPass>();    
bloom = deferred.createPass<ofxDeferred::HdrBloomPass>();
  • set parameters via reference
ssao->setOcculusionRadius(5.0);
ssao->setDarkness(1.0);
  • draw objects between begin() and end().

  • If you want to HDR color, just specify vertex color bright enough (can be more than 1.0) through ofFloatColor's parameters.

  • if you want to use cast shadow (ShadowLightPass), you need another draw call for shadow map.

    // for shadow map
    shadowLightPass->beginShadowMap();
        drawObjs(); // draw something
        lightPass->drawLights(); // draw light bulbs
    shadowLightPass->endShadowMap();
    
    // for rendering pass
    deferred.begin(cam);
        drawObjs(); // exactly the same call above
        lightPass->drawLights();
    deferred.end();
  • Also, you can use own shader for mesh rendering. In this case, you need to write pixel data into color buffer properly like below.

#version 400

uniform int shadowFlag;

in vec4 vPos;
in vec4 vNormal;
in vec4 vColor;
in float vDepth;

layout (location = 0) out vec4 outputColor0; // Color
layout (location = 1) out vec4 outputColor1; // Position
layout (location = 2) out vec4 outputColor2; // Normal and Depth

void main(){

    if (shadowFlag == 1) {
        outputColor0.r = vDepth;
        outputColor0.a = 1.;
    } else {
        outputColor0 = vColor;
        outputColor1 = vPos;
        outputColor2 = vec4(vNormal.xyz, vDepth);
    }

}

Reference

Render Pass

Effects

Author

Ayumu Nagamatsu

ofxdeferredshading's People

Contributors

nama-gatsuo avatar npisanti avatar themancalledjakob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ofxdeferredshading's Issues

Using Custom Shader

Hi thanks for making this fantastic addon! I'm trying to use a custom shader, as shown in the readme, but I can't find any method to attach the shader to the deferred object or any of the passes. I also tried doing this:

shadow->beginShadowMap(cam);
        
        testShader.begin();
        world.draw();
        testShader.end();
        points->drawLights();

        shadow->endShadowMap();
        
        deferred.begin(cam);

        testShader.begin();
        world.draw();
        testShader.end();
        points->drawLights();

        deferred.end();

to no avail.
Am I missing something?

Mixed up order in the readme

Just a small hint: In the readme it says to add this to the *.h file

    ofxDeferredProcessing deferred;
    ofxDeferredShading::SsaoPass* vfx1;
    ofxDeferredShading::PointLightPass* vfx2;
    ofxDeferredShading::ShadowLightPass* vfx3;
    ofxDeferredShading::HdrBloomPass* vfx4;

and this to the *.cpp file:

deferred.init(ofGetWidth(), ofGetHeight());
vfx1 = deferred.createPass<ofxDeferredShading::SsaoPass>().get();
vfx2 = deferred.createPass<ofxDeferredShading::ShadowLightPass>().get();
vfx3 = deferred.createPass<ofxDeferredShading::PointLightPass>().get();    
vfx4 = deferred.createPass<ofxDeferredShading::HdrBloomPass>().get();

This will cause an error. vfx2 should be initialized as PointLightPass and vfx3 as the ShadowLightPass :)

glm compatibility for latest openFrameworks

Hi. Would it be possible to update the code to make it work with openFramework's new glm syntax?
I've tried but haven't quite succeeded.

ofMatrix4x4 becomes glm::mat4
ofVec3f becomes glm::vec3
etc.

Some of the changes are less straightforward.

For example a line like:
ofMatrix4x4 normalMatrix = ofMatrix4x4::getTransposedOf(cam.getModelViewMatrix().getInverse());
I think becomes:
glm::mat4 normalMatrix = glm::transpose(glm::inverse(cam.getModelViewMatrix()));

This might also help: hamoid fork of ofDeferredRendering

Cheers!

The example can't be build on Linux

Hi,

First, I thank you for this great addon, it adds to oF some features of 3d rendering engines.

I tried to compile the addon example on Debian Buster with gcc-8 (linux 64) and the build process failed because the compiler couldn't find some files:

I changed the include statement of PingPongBuffer.h to make it relative.

  • in DeferredProcessor.hpp
    from (line 3) #include "ofxDeferredShading/src/PingPongBuffer.h" to
    #include "PingPongBuffer.h"

  • in BlurPass.h (line 3)
    #include "ofxDeferredShading/src/PingPongBuffer.h become #include "../PingPongBuffer.h"

I also changed the filename /shader/shadow/ShadowLight.frag to shadowLight.frag (with the first s in lower-case) according to ShadowLightPass.ccp load declaration. Maybe you code on OSX or another case-insensitive system so it changes nothing.

It's not real issue because I already fixed them. I just start to code with C++, so, I don't know if it is safe to import header with relative path but in my case it works (I setup all my apps with the the oF projectGenerator because I use VS Code tasks to build them). I hope this issue can help someone on a linux distro who want to use your addon.

Again thank you for this great work.

Best

ssao 'darkness' parameter does nothing

This paremeter is never used in the shader. Is there another way to control the resulting darkness of the ssao?

Thanks very much for sharing this addon :)

Not working with GL 4,1

Thanks for the addon. I tried to run example with 4,1. Because, my GPU doesn't support 4,5. But, no success. Running on MAC OS X (High Sierra), btw.
Screen Shot 2020-04-02 at 17 53 15

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.