示例#1
0
def myCreateTexturedQuadGeometry(pos, width, height, image, useTextureRectangle, xyPlane, option_flip):


    
    flip = image.getOrigin()==osg.Image.TOP_LEFT
    if option_flip : flip =  not flip

    if useTextureRectangle :
        pictureQuad = osg.createTexturedQuadGeometry(pos,
                                           osg.Vec3(width,0.0,0.0),
                                            osg.Vec3(0.0,height,0.0) : osg: if (xyPlane) else Vec3(0.0,0.0,height),
                                           0.0,  image.t() : 0.0, image.s(), flip ? 0.0 if (flip) else  image.t())

        texture = osg.TextureRectangle(image)
        texture.setWrap(osg.Texture.WRAP_S, osg.Texture.CLAMP_TO_EDGE)
        texture.setWrap(osg.Texture.WRAP_T, osg.Texture.CLAMP_TO_EDGE)


        pictureQuad.getOrCreateStateSet().setTextureAttributeAndModes(0,
                                                                        texture,
                                                                        osg.StateAttribute.ON)

        return pictureQuad
    return top_group

# Here a scene consisting of a single quad is created. This scene is viewed by the screen camera.
# The quad is textured using a shader and the multiple textures generated in the RTT stage.
def createScene(cam_subgraph, tex_width, tex_height, useHDR, useImage, useMultiSample):
    
    if  not cam_subgraph : return 0

    # create a group to contain the quad and the pre render camera.
    parent = osg.Group()

    # textures to render to and to use for texturing of the final quad
    osg.TextureRectangle* textureRect[NUM_TEXTURES] = 0,0,0,0

    for (int i=0i<NUM_TEXTURESi++) 
        textureRect[i] = osg.TextureRectangle()
        textureRect[i].setTextureSize(tex_width, tex_height)
        textureRect[i].setInternalFormat(GL_RGBA)
        textureRect[i].setFilter(osg.Texture2D.MIN_FILTER,osg.Texture2D.LINEAR)
        textureRect[i].setFilter(osg.Texture2D.MAG_FILTER,osg.Texture2D.LINEAR)

        if useHDR :
            # Default HDR format
            textureRect[i].setInternalFormat(GL_RGBA32F_ARB)

            # GL_FLOAT_RGBA32_NV might be supported on pre 8-series GPUs
            #textureRect[i].setInternalFormat(GL_FLOAT_RGBA32_NV)

            # GL_RGBA16F_ARB can be used with this example,
            # but modify e-12 and e12 in the shaders accordingly
            #textureRect[i].setInternalFormat(GL_RGBA16F_ARB)
示例#3
0


def createPreRenderSubGraph(subgraph, tex_width, tex_height, renderImplementation, useImage, useTextureRectangle, useHDR, samples, colorSamples):


    
    if  not subgraph : return 0

    # create a group to contain the flag and the pre rendering camera.
    parent = osg.Group()

    # texture to render to and to use for rendering of flag.
    texture = 0
    if useTextureRectangle :
        textureRect = osg.TextureRectangle()
        textureRect.setTextureSize(tex_width, tex_height)
        textureRect.setInternalFormat(GL_RGBA)
        textureRect.setFilter(osg.Texture2D.MIN_FILTER,osg.Texture2D.LINEAR)
        textureRect.setFilter(osg.Texture2D.MAG_FILTER,osg.Texture2D.LINEAR)

        texture = textureRect
    else:
        texture2D = osg.Texture2D()
        texture2D.setTextureSize(tex_width, tex_height)
        texture2D.setInternalFormat(GL_RGBA)
        texture2D.setFilter(osg.Texture2D.MIN_FILTER,osg.Texture2D.LINEAR)
        texture2D.setFilter(osg.Texture2D.MAG_FILTER,osg.Texture2D.LINEAR)

        texture = texture2D
示例#4
0
    return geode

#include <osg/State>

void DepthPeeling.createPeeling()
    numTiles = ceil(sqrt(double(_numPasses)))

    # cleanup any previous scene data
    _root.removeChildren(0, _root.getNumChildren())

    # create depth textures
    _depthTextures.clear()
    _depthTextures.resize(3)
    for (unsigned int i = 0 i < 3 ++i) 
#ifdef USE_TEXTURE_RECTANGLE
        _depthTextures[i] = osg.TextureRectangle()
#else:
        _depthTextures[i] = osg.Texture2D()
#endif
        _depthTextures[i].setTextureSize(_texWidth, _texHeight)

        _depthTextures[i].setFilter(osg.Texture.MIN_FILTER, osg.Texture.NEAREST)
        _depthTextures[i].setFilter(osg.Texture.MAG_FILTER, osg.Texture.NEAREST)
        _depthTextures[i].setWrap(osg.Texture.WRAP_S, osg.Texture.CLAMP_TO_BORDER)
        _depthTextures[i].setWrap(osg.Texture.WRAP_T, osg.Texture.CLAMP_TO_BORDER)

#ifdef USE_PACKED_DEPTH_STENCIL
        _depthTextures[i].setInternalFormat(GL_DEPTH24_STENCIL8_EXT)
        _depthTextures[i].setSourceFormat(GL_DEPTH_STENCIL_EXT)
        _depthTextures[i].setSourceType(GL_UNSIGNED_INT_24_8_EXT)
#else:
def createRectangle(bb, filename):


    
    top_left = osg.Vec3(bb.xMin(),bb.yMax(),bb.zMax())
    bottom_left = osg.Vec3(bb.xMin(),bb.yMax(),bb.zMin())
    bottom_right = osg.Vec3(bb.xMax(),bb.yMax(),bb.zMin())
    top_right = osg.Vec3(bb.xMax(),bb.yMax(),bb.zMax())

    # create geometry
    geom = osg.Geometry()

    vertices = osg.Vec3Array(4)
    (*vertices)[0] = top_left
    (*vertices)[1] = bottom_left
    (*vertices)[2] = bottom_right
    (*vertices)[3] = top_right
    geom.setVertexArray(vertices)

    texcoords = osg.Vec2Array(4)
    (*texcoords)[0].set(0.0, 0.0)
    (*texcoords)[1].set(1.0, 0.0)
    (*texcoords)[2].set(1.0, 1.0)
    (*texcoords)[3].set(0.0, 1.0)
    geom.setTexCoordArray(0,texcoords)

    normals = osg.Vec3Array(1)
    (*normals)[0].set(0.0,-1.0,0.0)
    geom.setNormalArray(normals, osg.Array.BIND_OVERALL)

    colors = osg.Vec4Array(1)
    (*colors)[0].set(1.0,1.0,1.0,1.0)
    geom.setColorArray(colors, osg.Array.BIND_OVERALL)

    geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4))

    # disable display list so our modified tex coordinates show up
    geom.setUseDisplayList(False)

    # load image
    img = osgDB.readImageFile(filename)

    # setup texture
    texture = osg.TextureRectangle(img)

    texmat = osg.TexMat()
    texmat.setScaleByTextureRectangleSize(True)

    # setup state
    state = geom.getOrCreateStateSet()
    state.setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON)
    state.setTextureAttributeAndModes(0, texmat, osg.StateAttribute.ON)

    # turn off lighting
    state.setMode(GL_LIGHTING, osg.StateAttribute.OFF)

    # install 'update' callback
    geode = osg.Geode()
    geode.addDrawable(geom)
    geode.setUpdateCallback(TexturePanCallback(texmat))

    return geode