当前位置: 首页>>代码示例>>Python>>正文


Python PNMImage.setMaxval方法代码示例

本文整理汇总了Python中panda3d.core.PNMImage.setMaxval方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setMaxval方法的具体用法?Python PNMImage.setMaxval怎么用?Python PNMImage.setMaxval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.PNMImage的用法示例。


在下文中一共展示了PNMImage.setMaxval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GPUFFT

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setMaxval [as 别名]

#.........这里部分代码省略.........
    def _reverseRow(self, indices):
        """ Reverses the bits in the given row. This is required for inverse
        fft (actually we perform a normal fft, but reversing the bits gives
        us an inverse fft) """
        mask = 0x1
        for j in xrange(self.size):
            val = 0x0
            temp = int(indices[j])  # Int is required, for making a copy
            for i in xrange(self.log2Size):
                t = mask & temp
                val = (val << 1) | t
                temp = temp >> 1
            indices[j] = val

    def _computeWeighting(self):
        """ Precomputes the weights & indices, and stores them in a texture """
        indicesA = [[0 for i in xrange(self.size)]
                    for k in xrange(self.log2Size)]
        indicesB = [[0 for i in xrange(self.size)]
                    for k in xrange(self.log2Size)]
        weights = [[Vec2(0.0) for i in xrange(self.size)]
                   for k in xrange(self.log2Size)]

        self.debug("Pre-Generating indices ..")
        self._generateIndices(indicesA, indicesB)
        self._reverseRow(indicesA[0])
        self._reverseRow(indicesB[0])

        self.debug("Pre-Generating weights ..")
        self._generateWeights(weights)

        # Create storage for the weights & indices
        self.weightsLookup = PNMImage(self.size, self.log2Size, 4)
        self.weightsLookup.setMaxval((2 ** 16) - 1)
        self.weightsLookup.fill(0.0)

        # Populate storage
        for x in xrange(self.size):
            for y in xrange(self.log2Size):
                indexA = indicesA[y][x]
                indexB = indicesB[y][x]
                weight = weights[y][x]

                self.weightsLookup.setRed(x, y, indexA / float(self.size))
                self.weightsLookup.setGreen(x, y, indexB / float(self.size))
                self.weightsLookup.setBlue(x, y, weight.x * 0.5 + 0.5)
                self.weightsLookup.setAlpha(x, y, weight.y * 0.5 + 0.5)

        # Convert storage to texture so we can use it in a shader
        self.weightsLookupTex = Texture("Weights Lookup")
        self.weightsLookupTex.load(self.weightsLookup)
        self.weightsLookupTex.setFormat(Texture.FRgba16)
        self.weightsLookupTex.setMinfilter(Texture.FTNearest)
        self.weightsLookupTex.setMagfilter(Texture.FTNearest)
        self.weightsLookupTex.setWrapU(Texture.WMClamp)
        self.weightsLookupTex.setWrapV(Texture.WMClamp)

    def _prepareAttributes(self):
        """ Prepares all shaderAttributes, so that we have a list of
        ShaderAttributes we can simply walk through in the update method,
        that is MUCH faster than using setShaderInput, as each call to
        setShaderInput forces the generation of a new ShaderAttrib """
        self.attributes = []
        textures = [self.pingTexture, self.pongTexture]

        currentIndex = 0
开发者ID:aurodev,项目名称:RenderPipeline,代码行数:70,代码来源:GPUFFT.py

示例2: WaterManager

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setMaxval [as 别名]
class WaterManager(DebugObject):

    """ Simple wrapper arround WaterDisplacement which combines 3 displacement
    maps into one, and also generates a normal map """

    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)
#.........这里部分代码省略.........
开发者ID:rimij405,项目名称:RenderPipeline,代码行数:103,代码来源:WaterManager.py


注:本文中的panda3d.core.PNMImage.setMaxval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。