Auto Deferred Shader

Thank you. I was using Intel HD Graphics and disabling shadows fixed the problem. However, on making a very minimal test program:

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
from deferred_render import *
from options import Options
class Test(ShowBase):
def init(self):
ShowBase.init(self)
DeferredRenderer(**Options(‘presets/full.ini’).get())
self.light_1 = SphereLight(color=(1, 1, 1), pos=(0,0,0), radius=10.0, shadow_size=0)
test=Test()
test.run()

It responds but I get a black window apart form the bottom left corner which goes grey.

@serega-kkz
FrameBufferProperties warning - replace loadPrcFileData("", "depth-bits 32") with loadPrcFileData("", "depth-bits 24")

I don’t know what the shader warnings are about - it says ‘was successfully compiled’ so I think that should work. Are you getting anything on the screen? Did you try running it with the minimal preset?

@Py_and_P3D_is_Best
Hard to tell what’s going wrong, but I think you should at least put a model in to see something more.

smiley = loader.load_model('smiley')
smiley.reparent_to(deferred_render)

Replaced: loadPrcFileData("", “depth-bits 32”) by loadPrcFileData("", “depth-bits 24”)

 Known pipe types:
      wglGraphicsPipe
    (all display modules loaded.)
    Vertex shader was successfully compiled to run on hardware.
    Fragment shader was successfully compiled to run on hardware.
    :display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
    Vertex shader(s) linked, fragment shader(s) linked.

Vertex shader was successfully compiled to run on hardware.
Fragment shader was successfully compiled to run on hardware.
:display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
Vertex shader(s) linked, fragment shader(s) linked.

Vertex shader was successfully compiled to run on hardware.
Fragment shader was successfully compiled to run on hardware.
:display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
Vertex shader(s) linked, fragment shader(s) linked.

...

I still see the wrong scene display.

ADD:

Vertex shader was successfully compiled to run on hardware.
Fragment shader was successfully compiled to run on hardware.
:display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
Vertex shader(s) linked, fragment shader(s) linked.

The console message is displayed as spam.

ADD:

In a spam I found out:

Vertex shader was successfully compiled to run on hardware.
:display:gsg:glgsg(error): An error occurred while compiling GLSL fragment shader shaders/mix_f.glsl:
Fragment shader failed to compile with the following errors:
ERROR: shaders/mix_f.glsl:6: error(#132) Syntax error: ';' parse error
ERROR: error(#273) 1 compilation errors.  No code generated
:display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
Vertex shader(s) linked.

On adding the smiley model and moving it four units forward. This is what I see:


This seems very unusual to me.

The problem with the display is solved)

shaders/mix_f.glsl

uniform sampler2D normal_tex;;

del ; :smile:

1 Like

@Py_and_P3D_is_Best
Ok, I think I know this one, add loadPrcFileData('','textures-power-2 None') somewhere on top, before importing Showbase.

@serega-kkz
That’s a pesky driver/compiler - in shaders/mix_f.glsl change line 6: uniform sampler2D normal_tex;; to uniform sampler2D normal_tex; there’s an extra ‘;’ at the end, didn’t know that’s even an error. Edit: ok, I see you got that.

2 Likes

However, spam:

Vertex shader was successfully compiled to run on hardware.
Fragment shader was successfully compiled to run on hardware.
:display:gsg:glgsg(warning): Shader created-shader produced the following warnings:
Vertex shader(s) linked, fragment shader(s) linked.

in the console lowers my frames (((

Thank You. loadPrcFileData('','textures-power-2 None') fixed the problem very well.

Hmm, I downloaded the standard geometry of the Roaming-Ralph level. And I do not understand where to look for shader work)))

Code:

from panda3d.core import *

loadPrcFileData("", "show-buffers 0")
loadPrcFileData("", "shadow-depth-bits 24")
#loadPrcFileData("", "depth-bits 32")
loadPrcFileData("", "depth-bits 24")
loadPrcFileData('','framebuffer-srgb 0')
loadPrcFileData('','textures-power-2 None')
loadPrcFileData("", "sync-video 0")
loadPrcFileData("", "show-frame-rate-meter  1")
loadPrcFileData("", "texture-anisotropic-degree 2")
loadPrcFileData("", "win-size 1366 768")

from direct.showbase import ShowBase
from direct.showbase.DirectObject import DirectObject

from deferred_render import *
from options import Options

class Test(DirectObject):
    def __init__(self):
        base = ShowBase.ShowBase()
       
        DeferredRenderer(**Options("presets/full.ini").get())
        self.light_1 = SphereLight(color=(1, 1, 1), pos=(0, -200, 400), radius=1000.0, shadow_size=512)

        self.environ = loader.loadModel("models/world")   
        self.environ.reparentTo(render)   
        
test = Test()
base.run()

Result:

You need to parent to the model to deferred_render self.environ.reparentTo(deferred_render) and some times also disable transparancy

I’m moving forward. Here’s the code based on your recommendations.

from panda3d.core import *

loadPrcFileData("", "show-buffers 0")
loadPrcFileData("", "shadow-depth-bits 24")
#loadPrcFileData("", "depth-bits 32")
loadPrcFileData("", "depth-bits 24")
loadPrcFileData('','framebuffer-srgb 0')
loadPrcFileData('','textures-power-2 None')
loadPrcFileData("", "sync-video 0")
loadPrcFileData("", "show-frame-rate-meter  0")
loadPrcFileData("", "texture-anisotropic-degree 2")
loadPrcFileData("", "win-size 1366 768")

from direct.showbase import ShowBase
from direct.showbase.DirectObject import DirectObject

from deferred_render import *
from options import Options

class Test(DirectObject):
    def __init__(self):
        base = ShowBase.ShowBase()
       
        DeferredRenderer(**Options("presets/full.ini").get())
        self.light_1 = SphereLight(color=(1, 1, 1), pos=(0, -200, 400), radius=1000.0, shadow_size=512)

        deferred_renderer.set_near_far(1.0,200.0)
        
        self.environ = loader.loadModel("models/world")  
        self.environ.setTransparency(0)
        self.environ.reparentTo(deferred_render)
        
        
test = Test()
base.run()

This is the result:

It looks strange …

I hurried to conclusions, the original scene looks incorrect.

I’m not sure what’s wrong with the test scene - that looks about right and it’s what I see when I run it.
I’ve changed your test script, my scene was way smaller than the Roaming Ralph environment so the fog settings needed adjusting and I don’t think a gigantic point light works for illuminating an outdoor scene like this - I used a directional (scene light):

from panda3d.core import *

loadPrcFileData("", "show-buffers 0")
loadPrcFileData("", "shadow-depth-bits 24")
#loadPrcFileData("", "depth-bits 32")
loadPrcFileData("", "depth-bits 24")
loadPrcFileData('','framebuffer-srgb 0')
loadPrcFileData('','textures-power-2 None')
loadPrcFileData("", "sync-video 0")
loadPrcFileData("", "show-frame-rate-meter  0")
loadPrcFileData("", "texture-anisotropic-degree 2")
loadPrcFileData("", "win-size 1280 720")

from direct.showbase import ShowBase
from direct.showbase.DirectObject import DirectObject

from deferred_render import *
from options import Options

config_custom={'shadows': 1024,
            'shading_setup': {'FORWARD_SIZE': 1, 'DISABLE_POM': 1, 'FORWARD_AUX': 1},
            'filter_setup': [{'inputs': {'random_tex': 'tex/noise.png', 'amount': 0.9, 'strength': 0.7, 'sample_rad': 0.01, 'falloff': 1.0},
                            'name': 'ao_basic',
                            'shader': 'ao'},
                            {'translate_tex_name': {'ao_basic': 'input_tex'},
                            'inputs': {'blur': 2.5},
                            'size': 0.5,
                            'name': 'ao',
                            'shader': 'blur'},
                            {'inputs': {'direction': LVector3f(0, 0, 0),
                            'ambient': LVector3f(0.02, 0.01, 0.01),
                            'light_color': LVector3f(0, 0, 0)},
                            'name': 'final_light',
                            'shader': 'dir_light'},
                            {'inputs': {'desat': 0.2, 'scale': 10.0, 'power': 2.0},
                            'size': 0.5,
                            'name': 'base_bloom',
                            'shader': 'bloom'},
                            {'translate_tex_name': {'base_bloom': 'input_tex'},
                            'inputs': {'blur': 3.0},
                            'size': 0.5,
                            'name': 'bloom',
                            'shader': 'blur'},
                            {'shader': 'ssr',
                            'name': 'base_ssr',
                            'define': {'maxDelta': 0.044, 'rayLength': 0.034, 'stepsCount': 16, 'fade': 0.3}},
                            {'inputs': {'noise_tex': 'tex/noise.png', 'blur': 6.0},
                            'name': 'ssr',
                            'shader': 'ref_blur'},
                            {'translate_tex_name': {'final_light': 'final_color'},
                            'inputs': {'noise_tex': 'tex/noise.png', 'lut_tex': 'tex/new_lut_nearest_f_rgb16_clamp.png'},
                            'name': 'compose',
                            'shader': 'mix'},
                            {'translate_tex_name': {'compose': 'input_tex'},
                            'inputs': {'fog_start': 110.0, 'dof_far_start': 90.0, 'dof_near': 5.0, 'fog_color': LVector3f(0.831, 0.831, 0.874), 'dof_far_max': 200.0, 'fog_max': 200.0},
                            'shader': 'fog'},
                            {'translate_tex_name': {'fog': 'input_tex'},
                            'inputs': {'blur': 6.0},
                            'shader': 'dof'},
                            {'translate_tex_name': {'dof': 'input_tex'},
                            'name': 'pre_aa',
                            'shader': 'chroma'},
                            {'inputs': {'subpix_shift': 0.125, 'span_max': 2.0, 'reduce_mul': 0.0625},
                            'shader': 'fxaa'}]
            }



class Test(DirectObject):
    def __init__(self):
        base = ShowBase.ShowBase()

        DeferredRenderer(**config_custom)
        #self.light_1 = SphereLight(color=(1, 1, 1), pos=(0, -200, 400), radius=1000.0, shadow_size=512)
        self.light_0 = SceneLight(color=(0.25, 0.25, 0.13), direction=Vec3(0.5, 0.0, 1.0), shadow_size=0)

        deferred_renderer.set_near_far(1.0,200.0)

        self.environ = loader.loadModel("models/world")
        self.environ.setTransparency(0)
        self.environ.reparentTo(deferred_render)
        self.environ.find('**wall').hide()#hide the wall



test = Test()
base.run()

Hmm, the problem was in lighting. I think that I misconceived the work of a point light.

Add: There was a question, how to get the shadows?

I only have shadows for point (SphereLight) and spotlights (ConeLight), you need to set the shadow size when creating a light (like shadow_size=1024). There should be methods to turn the shadows on and off, but I think I never wrote them all. Will need to update the code.

I have been using this system and I would like to make a sky-box. However, using this system I cannot see the sky-box unless the camera is very close to it. This happens even when using the minimal preset. Do you know of any way by which I can have the sky-box visible at any distance?

You can change the draw distance using deferred_renderer.set_near_far(1.0,1000.0) but the way I implemented mixing the forward shading, deferred shading and fog is kind of bad, and the fog will obscure the skybox (unless you disable it).
I have a different setup where all the deferred shading stuff is mixed first, then comes fog, next the forward pass and color correction, finally fxaa. I’ll put it up on github later this week whenever I have a free moment.

1 Like

Thank you. Using set_near_far worked. I can now see the sky-box on minimal preset. :smiley:

Is there any way to add ambient light? I can’t use directional light (scene light). It creates dark shadow (which is too dark, it’s just black) on the ceiling when the direction is down.