本文整理汇总了Python中Code.RenderingPipeline.RenderingPipeline.reloadShaders方法的典型用法代码示例。如果您正苦于以下问题:Python RenderingPipeline.reloadShaders方法的具体用法?Python RenderingPipeline.reloadShaders怎么用?Python RenderingPipeline.reloadShaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Code.RenderingPipeline.RenderingPipeline
的用法示例。
在下文中一共展示了RenderingPipeline.reloadShaders方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from Code.RenderingPipeline import RenderingPipeline [as 别名]
# 或者: from Code.RenderingPipeline.RenderingPipeline import reloadShaders [as 别名]
#.........这里部分代码省略.........
# self.camGroundColNp.show()
# Uncomment this line to show a visual representation of the
# collisions occuring
# self.cTrav.showCollisions(render)
# Create some ocean
self.water = ProjectedWaterGrid(self.renderPipeline)
self.water.setWaterLevel(-4.0)
# Create the skybox
self.skybox = self.renderPipeline.getDefaultSkybox()
self.skybox.reparentTo(render)
self.prepareSRGB(render)
self.reloadShader()
self.renderPipeline.onSceneInitialized()
# Add demo slider to move the sun position
if self.renderPipeline.settings.displayOnscreenDebugger:
self.renderPipeline.guiManager.demoSlider.node[
"command"] = self.setSunPos
self.renderPipeline.guiManager.demoSlider.node[
"value"] = 50
def setSunPos(self):
rawValue = self.renderPipeline.guiManager.demoSlider.node["value"]
dPos = Vec3(100, 100, rawValue - 20)
self.dirLight.setPos(dPos * 100000000.0)
def reloadShader(self):
self.renderPipeline.reloadShaders()
# Records the state of the arrow keys
def setKey(self, key, value):
self.keyMap[key] = value
def prepareSRGB(self, np):
""" Sets the correct texture format for all textures found in <np> """
for tex in np.findAllTextures():
baseFormat = tex.getFormat()
if baseFormat == Texture.FRgb:
tex.setFormat(Texture.FSrgb)
elif baseFormat == Texture.FRgba:
tex.setFormat(Texture.FSrgbAlpha)
else:
print "Unkown texture format:", baseFormat
print "\tTexture:", tex
# tex.setMinfilter(Texture.FTLinearMipmapLinear)
# tex.setMagfilter(Texture.FTLinear)
tex.setAnisotropicDegree(16)
# Accepts arrow keys to move either the player or the menu cursor,
# Also deals with grid checking and collision detection
def move(self, task):
# If the camera-left key is pressed, move camera left.
# If the camera-right key is pressed, move camera right.
base.camera.lookAt(self.ralph)
if (self.keyMap["cam-left"] != 0):
示例2: Main
# 需要导入模块: from Code.RenderingPipeline import RenderingPipeline [as 别名]
# 或者: from Code.RenderingPipeline.RenderingPipeline import reloadShaders [as 别名]
#.........这里部分代码省略.........
# self.toggleSceneWireframe()
self.renderPipeline.onSceneInitialized()
def setSunPos(self):
""" Sets the sun position based on the debug slider """
radial = True
rawValue = self.renderPipeline.guiManager.demoSlider.node["value"]
diff = self.lastSliderValue - rawValue
self.lastSliderValue = rawValue
if radial:
rawValue = rawValue / 100.0 * 2.0 * math.pi
dPos = Vec3(
math.sin(rawValue) * 30.0, math.cos(rawValue) * 30.0, 20.0)
# dPos = Vec3(100, 100, self.lastSliderValue*2 10)
else:
dPos = Vec3(30, (rawValue - 50) * 1.5, 0)
# dPos = Vec3(-2, 0, 40)
if abs(diff) > 0.0001:
if hasattr(self, "dirLight"):
self.dirLight.setPos(dPos * 100000000.0)
def toggleSceneWireframe(self):
""" Toggles the scene rendermode """
self.sceneWireframe = not self.sceneWireframe
if self.sceneWireframe:
render.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MWireframe), 10)
else:
render.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MFilled), 10)
self.skybox.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MFilled), 20)
def prepareSRGB(self, np):
""" Sets the correct texture format for all textures found in <np> """
for tex in np.findAllTextures():
baseFormat = tex.getFormat()
# Only diffuse textures should be SRGB
if "diffuse" in tex.getName().lower():
if baseFormat == Texture.FRgb:
tex.setFormat(Texture.FSrgb)
elif baseFormat == Texture.FRgba:
tex.setFormat(Texture.FSrgbAlpha)
elif baseFormat == Texture.FSrgb or baseFormat == Texture.FSrgbAlpha:
# Format is okay already
pass
else:
print "Unkown texture format:", baseFormat
print "\tTexture:", tex
# All textures should have the correct filter modes
tex.setMinfilter(Texture.FTLinearMipmapLinear)
tex.setMagfilter(Texture.FTLinear)
tex.setAnisotropicDegree(16)
def loadLights(self, scene):
""" Loads lights from a .egg. Lights should be empty objects (blender) """
model = self.loader.loadModel(scene)
lights = model.findAllMatches("**/PointLight*")
for prefab in lights:
light = PointLight()
light.setRadius(prefab.getScale().x)
light.setColor(Vec3(2))
light.setPos(prefab.getPos())
light.setShadowMapResolution(2048)
light.setCastsShadows(False)
self.renderPipeline.addLight(light)
print "Adding Light:", prefab.getPos(), prefab.getScale()
self.lights.append(light)
self.initialLightPos.append(prefab.getPos())
self.test = light
def setShaders(self, refreshPipeline=True):
""" Sets all shaders """
self.debug("Reloading Shaders ..")
if self.renderPipeline:
# for obj in self.transparentObjects:
# obj.setShader(
# self.renderPipeline.getDefaultTransparencyShader(), 30)
if refreshPipeline:
self.renderPipeline.reloadShaders()
def convertToPatches(self, model):
""" Converts a model to patches. This is required before being able
to use it with tesselation shaders """
self.debug("Converting model to patches ..")
for node in model.find_all_matches("**/+GeomNode"):
geom_node = node.node()
num_geoms = geom_node.get_num_geoms()
for i in range(num_geoms):
geom_node.modify_geom(i).make_patches_in_place()
示例3: Main
# 需要导入模块: from Code.RenderingPipeline import RenderingPipeline [as 别名]
# 或者: from Code.RenderingPipeline.RenderingPipeline import reloadShaders [as 别名]
#.........这里部分代码省略.........
def setSunPos(self):
""" Sets the sun position based on the debug slider """
radial = True
rawValue = self.renderPipeline.guiManager.demoSlider.node["value"]
diff = self.lastSliderValue - rawValue
self.lastSliderValue = rawValue
if radial:
rawValue = rawValue / 100.0 * 2.0 * math.pi
dPos = Vec3(
math.sin(rawValue) * 100.0, math.cos(rawValue) * 100.0, 100)
# dPos = Vec3(100, 100, (rawValue - 50) * 10.0)
else:
dPos = Vec3(30, (rawValue - 50), 100)
if abs(diff) > 0.0001:
self.dirLight.setPos(dPos)
self.dirLight.setDirection(dPos)
def toggleSceneWireframe(self):
""" Toggles the scene rendermode """
self.sceneWireframe = not self.sceneWireframe
if self.sceneWireframe:
self.scene.setRenderModeWireframe()
else:
self.scene.clearRenderMode()
def prepareSRGB(self, np):
""" Sets the correct texture format for all textures found in <np> """
for tex in np.findAllTextures():
baseFormat = tex.getFormat()
# Only diffuse textures should be SRGB
if "diffuse" in tex.getName().lower():
print "Preparing texture", tex.getName()
if baseFormat == Texture.FRgb:
tex.setFormat(Texture.FSrgb)
elif baseFormat == Texture.FRgba:
tex.setFormat(Texture.FSrgbAlpha)
else:
print "Unkown texture format:", baseFormat
print "\tTexture:", tex
# All textures should have the correct filter modes
tex.setMinfilter(Texture.FTLinearMipmapLinear)
tex.setMagfilter(Texture.FTLinear)
tex.setAnisotropicDegree(16)
def loadLights(self, scene):
""" Loads lights from a .egg. Lights should be empty objects (blender) """
model = self.loader.loadModel(scene)
lights = model.findAllMatches("**/PointLight*")
for prefab in lights:
light = PointLight()
light.setRadius(prefab.getScale().x)
light.setColor(Vec3(2))
light.setPos(prefab.getPos())
light.setShadowMapResolution(2048)
light.setCastsShadows(False)
self.renderPipeline.addLight(light)
print "Adding Light:", prefab.getPos(), prefab.getScale()
self.lights.append(light)
self.initialLightPos.append(prefab.getPos())
self.test = light
def loadSkybox(self):
""" Loads the skybox """
self.skybox = self.loader.loadModel("Models/Skybox/Model.egg.bam")
self.skybox.setScale(40000)
self.skybox.reparentTo(self.render)
def setShaders(self, refreshPipeline=True):
""" Sets all shaders """
self.debug("Reloading Shaders ..")
if self.renderPipeline:
self.scene.setShader(
self.renderPipeline.getDefaultObjectShader(False))
if refreshPipeline:
self.renderPipeline.reloadShaders()
if self.skybox:
self.skybox.setShader(BetterShader.load(
"Shader/DefaultObjectShader/vertex.glsl", "Shader/Skybox/fragment.glsl"))
def convertToPatches(self, model):
""" Converts a model to patches. This is REQUIRED before beeing able
to use it with tesselation shaders """
self.debug("Converting model to patches ..")
for node in model.find_all_matches("**/+GeomNode"):
geom_node = node.node()
num_geoms = geom_node.get_num_geoms()
for i in range(num_geoms):
geom_node.modify_geom(i).make_patches_in_place()
示例4: World
# 需要导入模块: from Code.RenderingPipeline import RenderingPipeline [as 别名]
# 或者: from Code.RenderingPipeline.RenderingPipeline import reloadShaders [as 别名]
class World(ShowBase):
def __init__(self):
# Load the default configuration.prc. This is recommended, as it
# contains some important panda options
loadPrcFile("../../Config/configuration.prc")
ShowBase.__init__(self)
# Create a new pipeline instance
self.renderPipeline = RenderingPipeline(self)
# Set the base path for the pipeline. This is required as we are in
# a subdirectory
self.renderPipeline.getMountManager().setBasePath("../../")
# Also set the write path
#self.renderPipeline.getMountManager().setWritePath("../../Temp/")
# Load the default settings
self.renderPipeline.loadSettings("../../Config/pipeline.ini")
# Now create the pipeline
self.renderPipeline.create()
self.addTask(self.moveTask, "move")
self.renderPipeline.onSceneInitialized()
#This creates the on screen title that is in every tutorial
self.title = OnscreenText(text="Panda3D: Tutorial 2 - Carousel",
style=1, fg=(1,1,1,1),
pos=(0.87,-0.95), scale = .07)
base.setBackgroundColor(.6, .6, 1) #Set the background color
base.disableMouse() #Allow manual positioning of the camera
camera.setPosHpr( 0, -8, 2.5, 0, -9, 0 ) #Set the cameras' position
#and orientation
self.loadModels() #Load and position our models
self.setupLights() #Add some basic lighting
self.startCarousel() #Create the needed intervals and put the
#carousel into motion
self.accept("r", self.reloadShader)
# As the model is moving, we have to register it as a dynamic object
for node in [self.carousel, self.lights1, self.lights2]:
self.renderPipeline.setEffect(node, "Effects/Default/Default.effect", {
"dynamic": True
})
def reloadShader(self):
self.renderPipeline.reloadShaders()
def moveTask(self, task):
counter = globalClock.getFrameTime() * 0.5
self.sun.setPos(Vec3(sin(counter) * 70, cos(counter) * 60, sin(counter*1.6323) * 20.0 + 60.0) * 1000000.0)
return task.cont
def loadModels(self):
#Load the carousel base
self.carousel = loader.loadModel("models/carousel_base")
self.carousel.reparentTo(render) #Attach it to render
#Load the modeled lights that are on the outer rim of the carousel
#(not Panda lights)
#There are 2 groups of lights. At any given time, one group will have the
#"on" texture and the other will have the "off" texture.
self.lights1 = loader.loadModel("models/carousel_lights")
self.lights1.reparentTo(self.carousel)
#Load the 2nd set of lights
self.lights2 = loader.loadModel("models/carousel_lights")
#We need to rotate the 2nd so it doesn't overlap with the 1st set.
self.lights2.setH(36)
self.lights2.reparentTo(self.carousel)
#Load the textures for the lights. One texture is for the "on" state,
#the other is for the "off" state.
self.lightOffTex = loader.loadTexture("models/carousel_lights_off.jpg")
self.lightOnTex = loader.loadTexture("models/carousel_lights_on.jpg")
#Create an list (self.pandas) with filled with 4 dummy nodes attached to
#the carousel.
#This uses a python concept called "Array Comprehensions." Check the Python
#manual for more information on how they work
self.pandas = [self.carousel.attachNewNode("panda"+str(i))
for i in range(4)]
self.models = [loader.loadModel("models/carousel_panda")
for i in range(4)]
self.moves = [0 for i in range(4)]
#.........这里部分代码省略.........
示例5: Main
# 需要导入模块: from Code.RenderingPipeline import RenderingPipeline [as 别名]
# 或者: from Code.RenderingPipeline.RenderingPipeline import reloadShaders [as 别名]
#.........这里部分代码省略.........
opts["label"] = BetterOnscreenText(x=20, y=currentY,
text=opts["name"], align="left", parent=self.windowNode,
size=15, color=col)
opts["value_label"] = BetterOnscreenText(x=250, y=currentY,
text=str(opts["default"]), align="right", parent=self.windowNode,
size=15, color=Vec3(0.6),mayChange=True)
currentY += 50
def materialOptionChanged(self):
container = self.model
for name, opt in self.slider_opts.items():
container.setShaderInput("opt_" + name, opt["slider"].getValue())
opt["value_label"].setText("{:0.4f}".format(opt["slider"].getValue()))
def setSunPos(self):
""" Sets the sun position based on the debug slider """
radial = True
rawValue = self.renderPipeline.guiManager.demoSlider.node["value"]
diff = self.lastSliderValue - rawValue
self.lastSliderValue = rawValue
if radial:
rawValue = rawValue / 100.0 * 2.0 * math.pi
dPos = Vec3(
math.sin(rawValue) * 100.0, math.cos(rawValue) * 100.0, 100)
# dPos = Vec3(100, 100, (rawValue - 50) * 10.0)
else:
dPos = Vec3(30, (rawValue - 50) * 1.5, 100)
if abs(diff) > 0.0001:
self.dirLight.setPos(dPos)
self.dirLight.setDirection(dPos)
def toggleSceneWireframe(self):
""" Toggles the scene rendermode """
self.sceneWireframe = not self.sceneWireframe
if self.sceneWireframe:
self.scene.setRenderModeWireframe()
else:
self.scene.clearRenderMode()
def prepareSRGB(self, np):
""" Sets the correct texture format for all textures found in <np> """
for tex in np.findAllTextures():
baseFormat = tex.getFormat()
# Only diffuse textures should be SRGB
if "diffuse" in tex.getName().lower():
print "Preparing texture", tex.getName()
if baseFormat == Texture.FRgb:
tex.setFormat(Texture.FSrgb)
elif baseFormat == Texture.FRgba:
tex.setFormat(Texture.FSrgbAlpha)
elif baseFormat == Texture.FSrgb or baseFormat == Texture.FSrgbAlpha:
# Format is okay already
pass
else:
print "Unkown texture format:", baseFormat
print "\tTexture:", tex
# All textures should have the correct filter modes
tex.setMinfilter(Texture.FTLinearMipmapLinear)
tex.setMagfilter(Texture.FTLinear)
tex.setAnisotropicDegree(16)
def setShaders(self, refreshPipeline=True):
""" Sets all shaders """
self.debug("Reloading Shaders ..")
if self.renderPipeline:
self.scene.setShader(
self.renderPipeline.getDefaultObjectShader(False))
self.model.setShader(Shader.load(Shader.SLGLSL,
"DefaultObjectShader/vertex.glsl",
"dynamicMaterialFragment.glsl"))
if refreshPipeline:
self.renderPipeline.reloadShaders()
if self.skybox:
self.skybox.setShader(Shader.load(Shader.SLGLSL,
"DefaultObjectShader/vertex.glsl", "Skybox/fragment.glsl"))
def convertToPatches(self, model):
""" Converts a model to patches. This is REQUIRED before beeing able
to use it with tesselation shaders """
self.debug("Converting model to patches ..")
for node in model.find_all_matches("**/+GeomNode"):
geom_node = node.node()
num_geoms = geom_node.get_num_geoms()
for i in range(num_geoms):
geom_node.modify_geom(i).make_patches_in_place()