本文整理汇总了Python中panda3d.core.Shader.loadCompute方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.loadCompute方法的具体用法?Python Shader.loadCompute怎么用?Python Shader.loadCompute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.Shader
的用法示例。
在下文中一共展示了Shader.loadCompute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import loadCompute [as 别名]
def __init__(self, N, sourceTex, normalizationFactor):
""" Creates a new fft instance. The source texture has to specified
from the begining, as the shaderAttributes are pregenerated for
performance reasons """
DebugObject.__init__(self, "GPU-FFT")
self.size = N
self.log2Size = int(math.log(N, 2))
self.normalizationFactor = normalizationFactor
# Create a ping and a pong texture, because we can't write to the
# same texture while reading to it (that would lead to unexpected
# behaviour, we could solve that by using an appropriate thread size,
# but it works fine so far)
self.pingTexture = Texture("FFTPing")
self.pingTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba32)
self.pongTexture = Texture("FFTPong")
self.pongTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba32)
self.sourceTex = sourceTex
for tex in [self.pingTexture, self.pongTexture, sourceTex]:
tex.setMinfilter(Texture.FTNearest)
tex.setMagfilter(Texture.FTNearest)
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
# Pregenerate weights & indices for the shaders
self._computeWeighting()
# Pre generate the shaders, we have 2 passes: Horizontal and Vertical
# which both execute log2(N) times with varying radii
self.horizontalFFTShader = Shader.loadCompute(Shader.SLGLSL,
"Shader/Water/HorizontalFFT.compute")
self.horizontalFFT = NodePath("HorizontalFFT")
self.horizontalFFT.setShader(self.horizontalFFTShader)
self.horizontalFFT.setShaderInput(
"precomputedWeights", self.weightsLookupTex)
self.horizontalFFT.setShaderInput("N", LVecBase2i(self.size))
self.verticalFFTShader = Shader.loadCompute(Shader.SLGLSL,
"Shader/Water/VerticalFFT.compute")
self.verticalFFT = NodePath("VerticalFFT")
self.verticalFFT.setShader(self.verticalFFTShader)
self.verticalFFT.setShaderInput(
"precomputedWeights", self.weightsLookupTex)
self.verticalFFT.setShaderInput("N", LVecBase2i(self.size))
# Create a texture where the result is stored
self.resultTexture = Texture("Result")
self.resultTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba16)
self.resultTexture.setMinfilter(Texture.FTLinear)
self.resultTexture.setMagfilter(Texture.FTLinear)
# Prepare the shader attributes, so we don't have to regenerate them
# every frame -> That is VERY slow (3ms per fft instance)
self._prepareAttributes()
示例2: _createInitialGrid
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import loadCompute [as 别名]
def _createInitialGrid(self):
""" Creates the initial cloud grid """
shader = Shader.loadCompute(Shader.SLGLSL, "Shader/Clouds/InitialGrid.compute")
dummy = NodePath("dummy")
dummy.setShader(shader)
dummy.setShaderInput("cloudGrid", self.voxelGrid)
sattr = dummy.getAttrib(ShaderAttrib)
Globals.base.graphicsEngine.dispatch_compute(
(self.cloudResolution / 8, self.cloudResolution / 8, self.cloudResolutionH / 8), sattr, Globals.base.win.getGsg())
shader = Shader.loadCompute(Shader.SLGLSL, "Shader/Clouds/CloudNoise.compute")
dummy = NodePath("dummy")
dummy.setShader(shader)
dummy.setShaderInput("noiseGrid", self.cloudNoise)
sattr = dummy.getAttrib(ShaderAttrib)
Globals.base.graphicsEngine.dispatch_compute(
(64 / 8, 64 / 8, 64 / 8), sattr, Globals.base.win.getGsg())
示例3: __init__
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import loadCompute [as 别名]
def __init__(self):
DebugObject.__init__(self, "WaterManager")
self.options = OceanOptions()
self.options.size = 512
self.options.windDir.normalize()
self.options.waveAmplitude *= 1e-7
self.displacementTex = Texture("Displacement")
self.displacementTex.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.normalTex = Texture("Normal")
self.normalTex.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.combineShader = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/Combine.compute")
self.ptaTime = PTAFloat.emptyArray(1)
# Create a gaussian random texture, as shaders aren't well suited
# for that
setRandomSeed(523)
self.randomStorage = PNMImage(self.options.size, self.options.size, 4)
self.randomStorage.setMaxval((2 ** 16) - 1)
for x in xrange(self.options.size):
for y in xrange(self.options.size):
rand1 = self._getGaussianRandom() / 10.0 + 0.5
rand2 = self._getGaussianRandom() / 10.0 + 0.5
self.randomStorage.setXel(x, y, float(rand1), float(rand2), 0)
self.randomStorage.setAlpha(x, y, 1.0)
self.randomStorageTex = Texture("RandomStorage")
self.randomStorageTex.load(self.randomStorage)
self.randomStorageTex.setFormat(Texture.FRgba16)
self.randomStorageTex.setMinfilter(Texture.FTNearest)
self.randomStorageTex.setMagfilter(Texture.FTNearest)
# Create the texture wwhere the intial height (H0 + Omega0) is stored.
self.texInitialHeight = Texture("InitialHeight")
self.texInitialHeight.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.texInitialHeight.setMinfilter(Texture.FTNearest)
self.texInitialHeight.setMagfilter(Texture.FTNearest)
# Create the shader which populates the initial height texture
self.shaderInitialHeight = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/InitialHeight.compute")
self.nodeInitialHeight = NodePath("initialHeight")
self.nodeInitialHeight.setShader(self.shaderInitialHeight)
self.nodeInitialHeight.setShaderInput("dest", self.texInitialHeight)
self.nodeInitialHeight.setShaderInput(
"N", LVecBase2i(self.options.size))
self.nodeInitialHeight.setShaderInput(
"patchLength", self.options.patchLength)
self.nodeInitialHeight.setShaderInput("windDir", self.options.windDir)
self.nodeInitialHeight.setShaderInput(
"windSpeed", self.options.windSpeed)
self.nodeInitialHeight.setShaderInput(
"waveAmplitude", self.options.waveAmplitude)
self.nodeInitialHeight.setShaderInput(
"windDependency", self.options.windDependency)
self.nodeInitialHeight.setShaderInput(
"randomTex", self.randomStorageTex)
self.attrInitialHeight = self.nodeInitialHeight.getAttrib(ShaderAttrib)
self.heightTextures = []
for i in xrange(3):
tex = Texture("Height")
tex.setup2dTexture(self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
tex.setMinfilter(Texture.FTNearest)
tex.setMagfilter(Texture.FTNearest)
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
self.heightTextures.append(tex)
# Also create the shader which updates the spectrum
self.shaderUpdate = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/Update.compute")
self.nodeUpdate = NodePath("update")
self.nodeUpdate.setShader(self.shaderUpdate)
self.nodeUpdate.setShaderInput("outH0x", self.heightTextures[0])
self.nodeUpdate.setShaderInput("outH0y", self.heightTextures[1])
self.nodeUpdate.setShaderInput("outH0z", self.heightTextures[2])
self.nodeUpdate.setShaderInput("initialHeight", self.texInitialHeight)
self.nodeUpdate.setShaderInput("N", LVecBase2i(self.options.size))
self.nodeUpdate.setShaderInput("time", self.ptaTime)
self.attrUpdate = self.nodeUpdate.getAttrib(ShaderAttrib)
# Create 3 FFTs
self.fftX = GPUFFT(self.options.size, self.heightTextures[0],
self.options.normalizationFactor)
self.fftY = GPUFFT(self.options.size, self.heightTextures[1],
#.........这里部分代码省略.........