Created
February 22, 2015 01:02
-
-
Save rdb/df2465d56e7e61c139d7 to your computer and use it in GitHub Desktop.
Example GLSL shader in Panda with simple texture mapping
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 Shader | |
vshader = """#version 140 | |
// Vertex inputs | |
in vec4 p3d_Vertex; | |
in vec2 p3d_MultiTexCoord0; | |
// Uniform inputs | |
uniform mat4 p3d_ModelViewProjectionMatrix; | |
// Output to fragment shader | |
out vec2 texcoord; | |
void main() { | |
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex; | |
texcoord = p3d_MultiTexCoord0; | |
} | |
""" | |
fshader = """#version 140 | |
uniform sampler2D p3d_Texture0; | |
// Input from vertex shader | |
in vec2 texcoord; | |
void main() { | |
vec4 color = texture(p3d_Texture0, texcoord); | |
gl_FragColor = color.bgra; | |
} | |
""" | |
from direct.showbase.ShowBase import ShowBase | |
base = ShowBase() | |
model = loader.loadModel('environment') | |
model.reparentTo(base.render) | |
shader = Shader.make(Shader.SL_GLSL, vshader, fshader) | |
model.setShader(shader) | |
base.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment