How to use the payton.scene.shader.Shader function in Payton

To help you get started, we’ve selected a few Payton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sinanislekdemir / payton / payton / scene / material.py View on Github external
_mode = Shader.LIGHT_COLOR

        if self.display == SOLID:
            if lit and self.lights:
                if self._texture is not None:
                    _mode = Shader.LIGHT_TEXTURE
                else:
                    _mode = Shader.LIGHT_COLOR
            else:
                if self._texture is not None:
                    _mode = Shader.NO_LIGHT_TEXTURE
                else:
                    _mode = Shader.NO_LIGHT_COLOR
        else:
            _mode = Shader.NO_LIGHT_COLOR

        if mode is not None:
            _mode = mode

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if self._texture is not None:
            check = shader.get_location("tex_unit")
            if check > -1:
                glActiveTexture(GL_TEXTURE0)
                glBindTexture(GL_TEXTURE_2D, self._texture)
                shader.set_int("tex_unit", 0)

        if not shader._depth_shader:
            shader.set_vector3_np("object_color", self._color_np)
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
self.__timer = -1.0
        self.observers: List[Observer] = []
        self.observers.append(Observer(active=True))

        self.hudcam = Observer(active=True, position=[0, 0, 1.0], up=[0, 1.0, 0], perspective=False,)

        self.active_observer = self.observers[0]

        self.lights: List[Light] = []
        self.lights.append(Light())

        self.clocks: Dict[str, Clock] = {}
        self.grid = Grid()
        self.controller = Controller()
        self.background = Background()
        self.shaders: Dict[str, Shader] = {
            "default": Shader(fragment=default_fragment_shader, vertex=default_vertex_shader),
            "depth": Shader(
                fragment=depth_fragment_shader, vertex=depth_vertex_shader, geometry=depth_geometry_shader,
            ),
        }
        self.shaders["depth"]._depth_shader = True

        # SDL Related Stuff
        self.window = None
        self.window_width = width
        self.window_height = height
        self._context = None
        self._mouse = [0, 0]
        self._shift_down = False
        self._ctrl_down = False
        self._rotate = False
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
self.observers: List[Observer] = []
        self.observers.append(Observer(active=True))

        self.hudcam = Observer(active=True, position=[0, 0, 1.0], up=[0, 1.0, 0], perspective=False,)

        self.active_observer = self.observers[0]

        self.lights: List[Light] = []
        self.lights.append(Light())

        self.clocks: Dict[str, Clock] = {}
        self.grid = Grid()
        self.controller = Controller()
        self.background = Background()
        self.shaders: Dict[str, Shader] = {
            "default": Shader(fragment=default_fragment_shader, vertex=default_vertex_shader),
            "depth": Shader(
                fragment=depth_fragment_shader, vertex=depth_vertex_shader, geometry=depth_geometry_shader,
            ),
        }
        self.shaders["depth"]._depth_shader = True

        # SDL Related Stuff
        self.window = None
        self.window_width = width
        self.window_height = height
        self._context = None
        self._mouse = [0, 0]
        self._shift_down = False
        self._ctrl_down = False
        self._rotate = False
        self.collisions: Dict[str, CollisionTest] = {}
github sinanislekdemir / payton / payton / scene / geometry / base.py View on Github external
self.track()

        if self._vertex_count == 0:
            # dummy object, render children and leave
            # render children
            for child in self.children:
                self.children[child].render(
                    lit, shader, self._model_matrix,
                )

            return

        # Material shading mode.
        mode = None
        if self._has_vertex_colors:
            mode = Shader.PER_VERTEX_COLOR

        shader.set_matrix4x4_np("model", self._model_matrix_fortran)
        indice_0 = ctypes.c_void_p(0)
        for material in self.materials.values():
            if not material.display == SOLID and shader._depth_shader:
                continue

            material.render(
                lit, shader, mode,
            )

            # Actual rendering
            if material._vao > NO_VERTEX_ARRAY and glIsVertexArray(material._vao):
                glBindVertexArray(material._vao)
                pmode = GL_LINE
                primitive = GL_TRIANGLES
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
def __init__(
        self,
        top_color: Optional[List[float]] = None,
        bottom_color: Optional[List[float]] = None,
        **kwargs: Dict[str, Any],
    ):
        self.top_color = [0.6, 0.8, 1.0, 1.0] if top_color is None else top_color
        self.bottom_color = [0.6275, 0.6275, 0.6275, 1.0] if bottom_color is None else bottom_color
        variables = ["top_color", "bot_color"]
        self._shader = Shader(
            fragment=background_fragment_shader, vertex=background_vertex_shader, variables=variables,
        )
        self._vao = None
        self.visible = True
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
self.observers.append(Observer(active=True))

        self.hudcam = Observer(active=True, position=[0, 0, 1.0], up=[0, 1.0, 0], perspective=False,)

        self.active_observer = self.observers[0]

        self.lights: List[Light] = []
        self.lights.append(Light())

        self.clocks: Dict[str, Clock] = {}
        self.grid = Grid()
        self.controller = Controller()
        self.background = Background()
        self.shaders: Dict[str, Shader] = {
            "default": Shader(fragment=default_fragment_shader, vertex=default_vertex_shader),
            "depth": Shader(
                fragment=depth_fragment_shader, vertex=depth_vertex_shader, geometry=depth_geometry_shader,
            ),
        }
        self.shaders["depth"]._depth_shader = True

        # SDL Related Stuff
        self.window = None
        self.window_width = width
        self.window_height = height
        self._context = None
        self._mouse = [0, 0]
        self._shift_down = False
        self._ctrl_down = False
        self._rotate = False
        self.collisions: Dict[str, CollisionTest] = {}
        self._click_planes: List[CPlane] = []
github sinanislekdemir / payton / payton / scene / material.py View on Github external
def render(self, lit: bool, shader: Shader, mode: Optional[int] = None,) -> None:
        if not self._initialized:
            self.build()

        _mode = Shader.LIGHT_COLOR

        if self.display == SOLID:
            if lit and self.lights:
                if self._texture is not None:
                    _mode = Shader.LIGHT_TEXTURE
                else:
                    _mode = Shader.LIGHT_COLOR
            else:
                if self._texture is not None:
                    _mode = Shader.NO_LIGHT_TEXTURE
                else:
                    _mode = Shader.NO_LIGHT_COLOR
        else:
            _mode = Shader.NO_LIGHT_COLOR

        if mode is not None:
github sinanislekdemir / payton / examples / mid-level / shader.py View on Github external
uniform vec3 object_color;
uniform int material_mode;
uniform float opacity;

uniform sampler2D tex_unit;

void main() {
    FragColor = vec4(1.0, 0.0, 0.0, 0.5);
}
"""

scene = Scene()
cube = Cube()
cube2 = Cube()
shader = Shader(fragment=fragment_shader)
scene.shaders["default"] = shader
scene.add_object("cube", cube)
scene.add_object("cube2", cube2)

cube2.position = [0, 0, 2]
scene.run()