[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум Panda3D - по русски » Panda3D » Примеры кода » Многопроходной рендер. (Отложенный рендер в панда.)
Многопроходной рендер.
serg-kkzДата: Воскресенье, 05.04.2020, 14:02 | Сообщение # 1
Генерал-лейтенант
Группа: Модераторы
Сообщений: 732
Награды: 3
Репутация: 17
Статус: Offline
В панда очень легко настроить многопроходной рендер. На удивление.

Код
from direct.showbase.ShowBase import ShowBase
from panda3d.core import NodePath
from panda3d.core import Shader, BitMask32, LVector4

def green():
    
    vertex = """
            #version 330
            
            uniform mat4 p3d_ModelViewProjectionMatrix;
            in vec4 p3d_Vertex;
            in vec2 p3d_MultiTexCoord0;
            out vec2 texcoord;

            void main() {
                gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
                texcoord = p3d_MultiTexCoord0;
            }
            """

    fragment = """
            #version 330

            uniform sampler2D p3d_Texture0;

            in vec2 texcoord;
            out vec4 color;

            void main() {
              color = vec4(0, 1, 0, 1)*texture(p3d_Texture0, texcoord);
            }
            """

    return Shader.make(Shader.SL_GLSL, vertex, fragment)

def blue():
    
    vertex = """
            #version 330
            
            uniform mat4 p3d_ModelViewProjectionMatrix;
            in vec4 p3d_Vertex;
            in vec2 p3d_MultiTexCoord0;
            out vec2 texcoord;

            void main() {
                gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
                texcoord = p3d_MultiTexCoord0;
            }
            """

    fragment = """
            #version 330

            uniform sampler2D p3d_Texture0;

            in vec2 texcoord;
            out vec4 color;

            void main() {
              color = vec4(0, 0, 1, 1)*texture(p3d_Texture0, texcoord);
            }
            """

    return Shader.make(Shader.SL_GLSL, vertex, fragment)
    
    
def red():
    
    vertex = """
            #version 330
            
            uniform mat4 p3d_ModelViewProjectionMatrix;
            in vec4 p3d_Vertex;
            in vec2 p3d_MultiTexCoord0;
            out vec2 texcoord;

            void main() {
                gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
                texcoord = p3d_MultiTexCoord0;
            }
            """

    fragment = """
            #version 330

            uniform sampler2D p3d_Texture0;

            in vec2 texcoord;
            out vec4 color;

            void main() {
              color = vec4(1, 0, 0, 1)*texture(p3d_Texture0, texcoord);
            }
            """

    return Shader.make(Shader.SL_GLSL, vertex, fragment)

class Demo(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        
        #self.cam.node().setCameraMask(BitMask32.bit(0))
        
        #base.win.active = False

        Buffer0 = base.win.makeTextureBuffer("stage4", 512, 512)
        Buffer0.setSort(0)
        Buffer0.setClearColor(LVector4(0, 0, 0, 1))
        # Creating a camera for the buffer.
        self.camera4 = base.makeCamera(Buffer0, lens=base.cam.node().getLens())
        
        Buffer1 = base.win.makeTextureBuffer("stage5", 512, 512)
        Buffer1.setSort(1)
        Buffer1.setClearColor(LVector4(0, 0, 0, 1))
        # Creating a camera for the buffer.
        self.camera5 = base.makeCamera(Buffer1, lens=base.cam.node().getLens())
        
        Buffer2= base.win.makeTextureBuffer("stage6", 512, 512)
        Buffer2.setSort(2)
        Buffer2.setClearColor(LVector4(0, 0, 0, 1))
        # Creating a camera for the buffer.
        self.camera6 = base.makeCamera(Buffer2, lens=base.cam.node().getLens())

        # Create a new scene.
        room = loader.load_model("models/abstractroom")
        room.setTag("Green", "True")
        room.setTag("Blue", "True")
        room.setTag("Red", "True")
        #room.hide(BitMask32.bit(0))
        room.reparent_to(render)
        
        green_render = NodePath("green_render")
        green_render.setShader(green())
        
        self.camera4.node().setTagStateKey("Green")
        self.camera4.node().setTagState("True", green_render.getState())

        blue_render = NodePath("blue_render")
        blue_render.setShader(blue())

        self.camera5.node().setTagStateKey("Blue")
        self.camera5.node().setTagState("True", blue_render.getState())

        red_render = NodePath("blue_render")
        red_render.setShader(red())

        self.camera6.node().setTagStateKey("Red")
        self.camera6.node().setTagState("True", red_render.getState())

        self.accept("v", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        base.bufferViewer.setCardSize(0.5, 0)

demo = Demo()
demo.run()


Прикрепления: 8349363.jpg(152.8 Kb)


ООП  -  

Сообщение отредактировал serg-kkz - Воскресенье, 05.04.2020, 14:53
 
Форум Panda3D - по русски » Panda3D » Примеры кода » Многопроходной рендер. (Отложенный рендер в панда.)
  • Страница 1 из 1
  • 1
Поиск: