Page 1 of 27 12311 ... LastLast
Results 1 to 20 of 529

Thread: GLSL PBR Shader for viewport

  1. #1
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96

    GLSL PBR Shader for viewport

    Hello everyone!

    This thread is about the development of the PBR viewport.

    My first goal was reach somewhat the quality / feature of Marmoset 2 inside the viewport to easily preview game assets and work on shaders inside Blender node editor like you would with Unreal editor for instance.

    But recently I oriented my development towards supporting Cycles shading in realtime viewport. This provides a more intuitive and flexible approache to the features. I also started the support of physical lights.

    A lot of things are approximated. For instance, the world casts no shadows and Refraction is done only for front facing faces.

    But you can edit your mesh






    Downloads (Win64 - OSX64 - Linux64):




    V0.4 - 06/06/2016


    • Oren-nayar Diffuse (Env lighting)
    • Velvet Shader (Env lighting + Point lights)
    • Toon Shader (Env lighting + Point lights)
    • Ashikhmin & Beckmann distributions for isotropic and anisotropic
    • Closest Filtering for Texture node
    • Material layer overide but only for material. So you can preview one material on every objects without assigning it to each object.
    • Linearly Transformed Cosines to shade Area lights with the Glossy GGX (other distributions use the same LUT)
    • Material AO to apply occlusion during the shading stage an not at the post process stage. Algorithm is slow but correct (matches cycles)
    • Screen Space Reflections for Sharp Glossy shader. Algorithm is from Morgan McGuire blog and the step is always 1px so reflections can't go far.
    • Backface buffer to improve screen space effects.
    • Bias parameter to control the accuracy of the Environment Sampling.
    • Performance : Use a jitter texture + a sample texture to generate sampling random vectors instead of computing everything inside the shader. (this takes 2 texture slots though)
    • Performance : Lights shadowing (and lamp nodetree) are evaluated only once per Material.
    • Codebase Change : major thing I did is not using the common uniform interface for passing uniforms related to the sampling and PBR. I also splited the glsl files into more managable ones.



    V0.3 - 20/03/2016


    • Introduced a probe system that generates probe from the world environment or specific objects
    • Spherical harmonics are computed on the gpu and lower resolution (much faster)
    • Soft shadows of area lamps : shadow "FOV" controled by near clip plane


    V0.2 - 18/01/2016


    • Better Default preview shader for Glossy and Diffuse
    • Support Sphere / Spot / Sun (partial) / Area (partial) lights
    • Glossy Shader (only Sharp / GGX)
    • Diffuse Shader (No roughness in Realistic mode)
    • Translucent Shader (Approximated as backlighted Diffuse)
    • Refraction Shader (only Sharp)
    • Glass Shader (only Sharp)
    • Velvet Shader (only Point Lights)
    • World Environement Reflection (still not perfect with some caveats)
    • Soft shadows of spot lights
    • Support Lamp Nodes
    • Normal Map Node (now works as expected)
    • Color Management settings previewed in the viewport (still WIP)
    • Other small things...


    V0.1 - 21/06/2014

    So what I've done so far:


    • Rectified some GLSL node to output what they should output.
    • IBL specular reflection
    • Irradiance from spherical harmonics computed from the HDR (now weighted)
    • Lambertian diffusion
    • GGX specular distribution
    • Dielectric and Metallic
    • Newton ring reflection (just a simple little node graph)
    • Cubemap support. (Cubemap should be in blender conventional orientation).
    • Standard Lights support
    • Multithreaded filtering of cubemap mip : You can prefilter the cubemap and have "better" light approximation.
    • Fresnel effect intensity input.
    • Mapping Node support
    • Envmap intensity input.
    • Separated outputs for better control.
    • Glossiness / Specular Model.
    • Energy conservation. (should be off most of the times)
    • Choosing Sample Number.
    • Horizon occlusion.
    • Sampling Setting are stored in Images not in Nodes.


    Basicaly everything could be done in node if there is a proper reflection vector and a LOD sample value in the textures node but it would be tedious to do "for" loops with nodes.

    My modification of blender's code are:



    • New PBR node type: IBL input and compute Spherical Harmonics.
    • GLSL re/coding of the folowing nodes: Texture Coordinate, Geometry, Normal Map, Checker Texture (I found someone who already did afterward)
    • Fixed color correction inside the Image Texture Node (was not applied in GLSL).
    • Unclamped rectfloat before passing hdr texture to OpenGL and use GL_RGBA16F to have the "whole" (actualy half) hdr range in GLSL
    • Disable Canceling Mipmap in paint mode to actualy paint mask for the pbr shader (if not the reflection are not blured anymore).
    • Added Cooktorr GGX specular shader for energy preservation and specular distribution. (Only works in GLSL)
    • [New] Added cubemap support to blender's viewport.
    • [New] Added normalmap node support to blender's viewport.
    Attached Images Attached Images
    Last edited by hypersomniac; 05-Jun-16 at 20:24.



  2. #2
    Member
    Join Date
    Sep 2012
    Posts
    2,573
    Amazing work... but, should there be a link or...?



  3. #3
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    Sorry for not replying I was busy trying to compile for windows.

    So here is the build for win64 : https://www.dropbox.com/s/yy1p3bq886...-PBR_win64.zip

    And here is the test scene : https://www.dropbox.com/s/z7nrf6c9ca22vs9/pbr.blend

    Here you have some test with a real model.


    CAVEAT: Changing a value in the shader chain will recompute SH lighting so it'll be laggy when picking color and stuff. I need to find a way to recompute SH only on File Change/Loading.



  4. #4
    Member Ace Dragon's Avatar
    Join Date
    Feb 2006
    Location
    Wichita Kansas (USA)
    Posts
    28,151
    It would be neat if this could become the start of a new ultra-fast and high quality GLSL engine where you have modes for Cycles, BI, and the BGE as well as a custom mode where you plug in shaders for [insert your favorite render engine or game engine here].

    I would also wait to really flesh it out until it can take advantage of the new Viewport FX code, as it will just have a much nicer base to work with (a lot of the current viewport code is OpenGL 1.x stuff from more than 12 years ago)
    Last edited by Ace Dragon; 19-Jul-14 at 21:02.
    Sweet Dragon dreams, lovely Dragon kisses, gorgeous Dragon hugs. How sweet would life be to romp with Dragons, teasing you with their fire and you being in their games, perhaps they can even turn you into one as well.
    Adventures in Cycles; My official sketchbook



  5. #5
    Member Monio's Avatar
    Join Date
    Nov 2012
    Location
    Warsaw | Poland
    Posts
    168
    OH MY GOD! Hypersomnia, I love you!

    I'm working right now on proposal for new blender bakeing menagement. Just proposal, I cannot code it. Your viewport work can be huuuuge help for previewing baked map sets as complete shader. In my design baked maps can be previewed in another viewport shading mode that not relay on assigned materials (nor cycles or internal) but relay on textures linked to objects. This cannot be soved other way. In most of aplications textures are linked to materials, not to objects. But baked textures are different thing than typical texture. Using baked textures by linking them to material cannot result in proper preview if many objects use same material, it will look good only on just one object and incorrect on every other. If your viewport code can override blender materials it can be used as Bake Preview viewport shading mode and solve this mindbending mess with unlinked image nodes ad bake preview.
    Last edited by Monio; 21-Jul-14 at 04:41.



  6. #6
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    Originally Posted by Monio View Post
    OH MY GOD! Hypersomnia, I love you!

    I'm working right now on proposal for new blender bakeing menagement. Just proposal, I cannot code it. Your viewport work can be huuuuge help for previewing baked map sets as complete shader. In my design baked maps can be previewed in another viewport shading mode that not relay on assigned materials (nor cycles or internal) but relay on textures linked to objects. This cannot be soved other way. In most of aplications textures are linked to materials, not to objects. But baked textures are different thing than typical texture. Using baked textures by linking them to material cannot result in proper preview if many objects use same material, it will look good only on just one object and incorrect on every other. If your viewport code can override blender materials it can be used as Bake Preview viewport shading mode and solve this mindbending mess with unlinked image nodes ad bake preview.
    Actually my shader nodes are just an extention of blender's viewport. I am not sure of what your problem is as I don't have used cycles baking yet. But your proposal for batch baking is surely one thing blender lacks. I will keep an eye on this. and yeah making it working with my shader would be cool.



  7. #7



  8. #8
    Member Monio's Avatar
    Join Date
    Nov 2012
    Location
    Warsaw | Poland
    Posts
    168
    Yes. Nice but limited comparing to my solution.



  9. #9
    Amazing.
    hypersomniac !!!



  10. #10
    Dude, this is great. Really great. I've been using Substance Painter / Designer to do my PBR work for UE4, but it'd be nice to be able to do a lot of it in Blender. Not sure how it would work with, say, the painting toolset. Maybe if you get farther with it you could add some nodes/presets that work like modern game engines like UE4 or Unity 5.



  11. #11
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    New version!

    I separated Specular environment and SH in 2 nodes so you can chose the one you need and tweak their intensity and such. Just plug a LagLong EnvMap inside (it should be the same map obviously). I may get cubemaps to work.

    Well i've got the lamps working. It's hacky but it works. I added a specular type only defined for GLSL mode it's called CookTorr GGX under the standard (non Cycles) material tab (it reverts to toon shading everywhere else).

    You need to hook up a material using this spec shader in the PBR Lighting Node. This node overides the spec/diffuse color and the roughness of the material. You plug it in the right output and activate GLSL shading and voila!
    Just note that Hemi Lights don't follow the same spec function so disable spec on theses lights.

    Normal maps must be tangent space (for now), Non-color data, and pluged in a NormalMap Node (Cycle node).

    To combine Env Lighting and Lamp Lighting just follow this scheme (I made some annotations i found important):
    tuto.PNG

    This download is still here.

    Take note that it's not backward compatible with the previous build.



  12. #12
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    Originally Posted by RagingElbows View Post
    Dude, this is great. Really great. I've been using Substance Painter / Designer to do my PBR work for UE4, but it'd be nice to be able to do a lot of it in Blender. Not sure how it would work with, say, the painting toolset. Maybe if you get farther with it you could add some nodes/presets that work like modern game engines like UE4 or Unity 5.
    It is already working with paint mode! I'm also going to provide node presets for some shaders like you mentioned.



  13. #13
    Member NinthJake's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    2,294
    Holycrapholycrapholycrapholycrap, this is fantastic! I thought we would have to wait 3-5 years before we could have PBR-based viewport shading in Blender.

    Thanks a ton for the hard work and the build. (Where is the link to the Linux build by the way?)

    EDIT: So I got on my windows machine and tried this build out a bit and I must confess that I find it extremely confusing to set up. By looking at your new example it seems I need to first switch to Cycles to add the necessary nodes and then switch back to Blender game to change the specularity type to CockTorr GGX and set the viewport to textured GLSL shading.
    I just don't understand how to get any results to show in the viewport, everything I try just shows up as a black silhouette. Only IBL lighting, only lamps and both combined shows the same result.

    Your old example file does not work in this new version, do you have a new one to share please?
    Or it can just be that the build doesn't work properly, that would explain a lot. (but most likely the reason is that I am an idiot and have missed something glaringly obvious)
    Last edited by NinthJake; 22-Jul-14 at 18:39.



  14. #14
    Looks awesome. I hope this can integrate with the new Viewport FX code that is coming.



  15. #15
    Member NinthJake's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    2,294
    EDIT #2: Okay something seems to actually be broken. Not even the regular GLSL shading works now, even though it worked before. Not even if I restart Blender. Anyone else experiencing this?



  16. #16
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    Originally Posted by NinthJake View Post
    EDIT #2: Okay something seems to actually be broken. Not even the regular GLSL shading works now, even though it worked before. Not even if I restart Blender. Anyone else experiencing this?
    wow! I was not expecting that much trouble!

    Does it work with the a normal build (not mine)?

    Some thoughts about the problem:
    - roughness of 0 may give black IBL spec result on windows (i'm working on it).
    - roughness of 0 give no spec from PBR lighting node (it's expected i think).

    Concerning your 1st question : yes It is REALY confusing to setup but i'll do node groups so you won't have to deal with these problems! but image input need to be cycles one so I don't know how to solve this mess :/

    I noticed in Cycles "GLSL" material view mode the lamps does not update.

    Also i get crash too so it's not a safe build!

    Anyway here is a new test scene. Stupid Simple shader. It should work!

    Linux build should come soon. I still have to build a portable version of it.
    Last edited by hypersomniac; 22-Jul-14 at 20:54.



  17. #17
    Member NinthJake's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    2,294
    @hypersomniac Yes the regular builds work as expected. Yours "work" only as long as I don't switch to GLSL shading.

    This is what I get straight when I open your new example. If I deselect Suzanne I get a pure black silhouette instead. I also tried to start up a new instance of Blender and recreate your scene from scratch but still the same result.
    PBR_Problem.jpg


    I will try the Linux build later when you upload it. Thank you for your hard work



  18. #18
    Member hypersomniac's Avatar
    Join Date
    Jul 2014
    Location
    Paris, France
    Posts
    96
    @NinthJake I forgot to say that this shader needs opengl 2.10 if i'm not mistaken. I may ask you to check your graphic driver. Also you could check the console for GLSL errors.

    What graphic card do you have?

    Edit : Btw the graphic error you get is because the object is filled by the selected/unselected color. So it realy mean GLSL errors. Please check the console (top bar>window>show console) and paste them here.
    Last edited by hypersomniac; 22-Jul-14 at 21:32.



  19. #19
    Member Craig Jones's Avatar
    Join Date
    Apr 2006
    Location
    Yoakum, TX
    Posts
    6,191
    This is very interesting, and I hope you get this sorted out after the Viewport improvements come in. Question: will this be more liek an advanced version of GLSL for painting in the viewport and getting realistic materials? I haven't tried it yet, just reading the thread right now.



  20. #20
    Member NinthJake's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    2,294
    Originally Posted by hypersomniac View Post
    @NinthJake I forgot to say that this shader needs opengl 2.10 if i'm not mistaken. I may ask you to check your graphic driver. Also you could check the console for GLSL errors.

    What graphic card do you have?

    Edit : Btw the graphic error you get is because the object is filled by the selected/unselected color. So it realy mean GLSL errors. Please check the console (top bar>window>show console) and paste them here.
    I run an Nvidia GTX 560Ti (driver version: 335.23) which is supposed to support OpenGL 4.1

    This is the errors I get in the console.
    error_report.jpg



Page 1 of 27 12311 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •