Created
November 27, 2016 13:05
-
-
Save tobspr/489f218d9eaee933d7ec77ba770a3980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from panda3d.core import * | |
| from random import random | |
| import direct.directbase.DirectStart | |
| vertex_glsl = """ | |
| #version 400 | |
| in vec4 p3d_Vertex; | |
| uniform mat4 p3d_ModelViewProjectionMatrix; | |
| void main() { | |
| gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex; | |
| } | |
| """ | |
| fragment_glsl = """ | |
| #version 400 | |
| uniform struct { | |
| vec4 baseColor; | |
| } p3d_Material; | |
| out vec3 color; | |
| void main() { | |
| color = p3d_Material.baseColor.xyz; | |
| } | |
| """ | |
| smiley = loader.loadModel("smiley") | |
| smiley.reparent_to(render) | |
| material = Material() | |
| smiley.set_material(material) | |
| def reload_shaders(): | |
| shader = Shader.make(Shader.SL_GLSL, vertex_glsl, fragment_glsl) | |
| render.set_shader(shader) | |
| def change_material(): | |
| material = Material(smiley.get_material()) | |
| print(material) | |
| material.set_base_color(Vec4(random(), random(), random(), 1)) # Assertion | |
| base.accept("r", reload_shaders) | |
| base.accept("c", change_material) | |
| base.disableMouse() | |
| base.cam.setPos(10, 10, 10) | |
| base.cam.lookAt(smiley) | |
| reload_shaders() | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment