Created
June 27, 2014 15:01
-
-
Save tobspr/a505865cb3efe58bd9d2 to your computer and use it in GitHub Desktop.
This file contains 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 * | |
loadPrcFileData("",""" | |
show-frame-rate-meter #t | |
""".strip()) | |
from direct.directbase import DirectStart | |
import math | |
# Shader | |
compute_source = """#version 430 | |
#pragma optionNV (unroll all) | |
layout (rgba8) uniform image2D destTex; | |
layout (local_size_x = 32, local_size_y = 32) in; | |
uniform float test; | |
void main() { | |
vec4 result = vec4(0, 0, 0, 1); | |
float minDepth = test; | |
for (int i = 0; i < 2000; i ++) { | |
minDepth += sin(float(i+minDepth)); | |
} | |
ivec2 storePos = ivec2(gl_GlobalInvocationID.xy); | |
imageStore(destTex, storePos, vec4(minDepth)); | |
}""" | |
# Create shader / compute node | |
shader = Shader.make_compute(Shader.SL_GLSL, compute_source) | |
compute_node = ComputeNode('compute') | |
compute_node.add_dispatch(1600/32, 960/32, 1) | |
tex = Texture() | |
# Create destination tex | |
tex.setup_2d_texture(1600, 960, Texture.TFloat, Texture.FRgba8) | |
tex.set_format(Texture.F_rgba8) | |
tex.set_minfilter(Texture.FT_nearest) | |
tex.set_magfilter(Texture.FT_nearest) | |
# Attach compute node and set shader inputs | |
np = render.attach_new_node(compute_node) | |
np.set_shader(shader) | |
np.set_shader_input('destTex', tex) | |
np.set_shader_input('test', 0.123123) # prevent unrolling | |
# Create card to show texture | |
cm = CardMaker('card') | |
cm.set_frame_fullscreen_quad() | |
card = render2d.attach_new_node(cm.generate()) | |
card.set_texture(tex) | |
# Done! | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment