本文整理汇总了Python中panda3d.core.Shader.make方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.make方法的具体用法?Python Shader.make怎么用?Python Shader.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.Shader
的用法示例。
在下文中一共展示了Shader.make方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def __init__(self):
# The basics
ShowBase.__init__(self)
base.disableMouse()
base.setBackgroundColor(0.1, 0.1, 0.1)
base.setFrameRateMeter(True)
self.accept("escape", sys.exit)
# Camera
self.camera_orbit = base.render.attach_new_node("Camera orbit")
self.camera_pitch = self.camera_orbit.attach_new_node("Camera pitch")
base.camera.reparent_to(self.camera_pitch)
base.camera.set_pos(0, -5, 0)
# Camera control
self.camera_movement = (0, 0)
self.accept("arrow_up", self.change_camera_movement, [ 0, -1])
self.accept("arrow_up-up", self.change_camera_movement, [ 0, 1])
self.accept("arrow_down", self.change_camera_movement, [ 0, 1])
self.accept("arrow_down-up", self.change_camera_movement, [ 0, -1])
self.accept("arrow_left", self.change_camera_movement, [-1, 0])
self.accept("arrow_left-up", self.change_camera_movement, [ 1, 0])
self.accept("arrow_right", self.change_camera_movement, [ 1, 0])
self.accept("arrow_right-up", self.change_camera_movement, [-1, 0])
base.taskMgr.add(self.move_camera, "Move camera")
# Object
self.model = loader.loadModel("models/smiley")
self.model.reparent_to(base.render)
shader = Shader.make(
Shader.SL_GLSL,
vertex = vertex_shader,
fragment = fragment_shader,
)
self.model.set_shader(shader)
示例2: _makeFontShader
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def _makeFontShader(self):
self.fontShader = Shader.make(Shader.SLGLSL, """
#version 150
uniform mat4 p3d_ModelViewProjectionMatrix;
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;
uniform float displData[100];
out vec2 texcoord;
uniform vec2 pos;
uniform vec2 size;
void main() {
int rawDispl = int(displData[gl_InstanceID]);
ivec2 offsetDispl = ivec2( rawDispl % 16, rawDispl / 16);
vec2 offsetCoordReal = vec2(offsetDispl.x / 16.0, (5.0 - offsetDispl.y) / 6.0);
texcoord = p3d_MultiTexCoord0 / vec2(16,6) + offsetCoordReal;
vec4 offset = vec4(gl_InstanceID*size.x*0.55 , 0, 0, 0) + vec4(pos.x, 0, pos.y, 0);
vec4 finalPos = p3d_Vertex * vec4(size.x, size.x, size.x, 1.0) + offset;
gl_Position = p3d_ModelViewProjectionMatrix * finalPos;
}
""", """
#version 150
#pragma file FastText.fragment
in vec2 texcoord;
uniform sampler2D font;
uniform vec3 color;
out vec4 result;
void main() {
float textFactor = texture(font, texcoord).x;
result = vec4(color, textFactor);
}
""")
示例3: load
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def load(self, *args):
""" Loads a shader in the order: vertex, fragment,
geometry, tesseval, tesscontrol """
newArgs = []
toHash = ""
for arg in args:
if len(arg) < 1:
newArgs.append("")
continue
content = self._handleIncludes(arg)
newArgs.append(content)
toHash += content
self._writeDebugShader("Shader-" + str(arg), content)
self._clearIncludeStack()
# Check if we already have the result cached
hashed = hash(toHash)
if hashed in self._ShaderCache:
# Cache entry found
return self._ShaderCache[hashed]
shaderName = args[1].replace("Shader", "").split(".")[0].lstrip("/")
result = Shader.make(Shader.SLGLSL, *newArgs)
self._ShaderCache[hashed] = result
return result
示例4: _makeShader
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def _makeShader(shaderEffects, baseShader=None):
"""
Generates shader source from effects and converts it into a Panda3D shader object
baseShader is source to inject effects into
"""
source=shadereffects.makeSource(shaderEffects, baseShader)
key=source
if key not in builtEffectsShaders:
if useShaderFiles:
# preflatten should not impact anything much, but lets us get the full names
shaderEffects=[s.flatten() for s in shaderEffects]
name='debug('+','.join([e.name for e in shaderEffects])+')'
outLoc='ShadersOut/'+name+'.sha'
print 'Making Shader: '+outLoc
builtEffectsShaders[key]=Shader.make(source)
if useShaderFiles:
fOut=open(outLoc, 'w')
fOut.write(source)
fOut.close()
return builtEffectsShaders[key]
示例5: setupTargetClip
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def setupTargetClip(self):
"""
The target is fed in to the typewriter but until we invent "geom curling",
it shouldn't be visible under the typewriter under the desk.
The @underDeskClip node has a world-relative bounding box, which
we can convert to the target-relative bounding box, and pass to a
shader that can clip the nodes.
"""
shader = Shader.make(
Shader.SLGLSL,
"""
#version 120
attribute vec4 p3d_MultiTexCoord0;
attribute vec4 p3d_MultiTexCoord1;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = p3d_MultiTexCoord0;
gl_TexCoord[1] = p3d_MultiTexCoord1;
}
""",
"""
#version 120
uniform sampler2D baseTex;
uniform sampler2D charTex;
const vec4 zero = vec4(0, 0, 0, 0);
const vec4 one = vec4(1, 1, 1, 1);
const vec4 half = vec4(0.5, 0.5, 0.5, 0);
void main() {
vec4 baseColor = texture2D(baseTex, gl_TexCoord[0].st);
vec4 typeColor = texture2D(charTex, gl_TexCoord[1].st);
gl_FragColor = baseColor * typeColor;
}"""
)
self.target.setShader(shader)
baseTex = self.targetRoot.getTexture()
print "Base Texture:",baseTex
self.target.setShaderInput("baseTex", baseTex)
self.target.setShaderInput("charTex", self.tex)
示例6: _makeFontShader
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def _makeFontShader(self):
self.fontShader = Shader.make(Shader.SLGLSL, """
#version 150
uniform mat4 p3d_ModelViewProjectionMatrix;
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;
uniform float displData[100];
out vec2 texcoord;
uniform vec2 pos;
uniform sampler2D font;
uniform vec2 size;
void main() {
int rawDispl = int(displData[gl_InstanceID]);
ivec2 offsetDispl = ivec2( rawDispl % 16, rawDispl / 16);
vec2 offsetCoordReal = vec2(offsetDispl.x / 16.0,
(5.0 - offsetDispl.y) / 6.0);
vec2 halfOffset = 1.0 / textureSize(font, 0);
texcoord = clamp(p3d_MultiTexCoord0, halfOffset, 1.0 - halfOffset) / vec2(16,6) + offsetCoordReal;
vec4 offset = vec4(gl_InstanceID*size.x*0.56 , 0, 0, 0) +
vec4(pos.x, 0, pos.y, 0);
vec4 finalPos = p3d_Vertex * vec4(size.xxx, 1.0) + offset;
gl_Position = p3d_ModelViewProjectionMatrix * finalPos;
}
""", """
#version 150
in vec2 texcoord;
uniform sampler2D font;
uniform vec3 color;
out vec4 result;
void main() {
float textFactor = texture(font, texcoord).x;
vec2 texsize = textureSize(font, 0);
ivec2 icoord = ivec2(texcoord * texsize);
ivec2 cidx = icoord / ivec2(16, 6);
vec2 minCoord = (cidx * vec2(16, 6) + vec2(1.0)) / texsize;
vec2 maxCoord = ((cidx + 1) * vec2(16, 6) - vec2(1.0)) / texsize;
float outlineSize = 0.75;
float textShadow = clamp(
texture(font, clamp(texcoord + vec2(-outlineSize, -outlineSize) / texsize, minCoord, maxCoord)).x +
texture(font, clamp(texcoord + vec2(outlineSize, -outlineSize) / texsize, minCoord, maxCoord)).x +
texture(font, clamp(texcoord + vec2(-outlineSize, outlineSize) / texsize, minCoord, maxCoord)).x +
texture(font, clamp(texcoord + vec2(outlineSize, outlineSize) / texsize, minCoord, maxCoord)).x, 0, 1) * 0.7;
result = vec4( mix(vec3(0), color, textFactor), textFactor + textShadow);
}
""")
示例7: load
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def load(self, *args):
""" Loads a shader in the order: vertex, fragment,
geometry, tesseval, tesscontrol """
newArgs = []
for arg in args:
if len(arg) < 1:
newArgs.append("")
continue
content = self._handleIncludes(arg)
newArgs.append(content)
self._writeDebugShader("Shader-" + str(arg), content)
self._clearIncludeStack()
result = Shader.make(Shader.SLGLSL, *newArgs)
return result
示例8: loadShader
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def loadShader(self):
"""Textures based on altitude and slope."""
logging.info( "loading textures...")
### texture scaling
texScale = self.terrain.tileSize / 32 * self.terrain.horizontalScale
self.texScale = Vec4(texScale, texScale, texScale, 1.0)
### Load textures
self.normalMap = self.loadTexture("Detail_NRM.png")
self.displacementMap = self.loadTexture("Detail_DISP.png")
self.testOn = False
self.detailTex = self.loadTexture("Detail_COLOR.png")
self.detailTex2 = self.loadTexture("Detail_COLOR2.png")
self.tex1 = self.loadTexture("dirt.jpg")
self.tex2 = self.loadTexture("grass.jpg")
self.tex3 = self.loadTexture("rock.jpg")
self.tex4 = self.loadTexture("snow.jpg")
self.normalTS = TextureStage('normalMap')
#self.normalTS2 = TextureStage('normalMap')
self.detailTS = TextureStage('detailMap')
self.ts1 = TextureStage('textures')
### Load the boundries for each texture
# regionLimits ( min height, max height, min slope, max slope )
self.textureMapper = TextureMapper(self.terrain)
self.textureMapper.addTexture(self.tex1)
self.textureMapper.addRegionToTex(Vec4(-9999.0, self.indexToHeight(0.1), -001, 1.001))
self.textureMapper.addTexture(self.tex2)
self.textureMapper.addRegionToTex(Vec4(self.indexToHeight(-0.15), self.indexToHeight(0.75), -0.001, 0.30))
self.textureMapper.addTexture(self.tex3)
self.textureMapper.addRegionToTex(Vec4(self.indexToHeight(0.1), self.indexToHeight(0.95), 0.10, 1.001))
#second region forces tex 2 and 4 to blend a bit at their boundries regardless of slope
self.textureMapper.addRegionToTex(Vec4(self.indexToHeight(0.4), self.indexToHeight(0.9), -0.001, 1.001))
self.textureMapper.addTexture(self.tex4)
self.textureMapper.addRegionToTex(Vec4(self.indexToHeight(0.72), 9999.0, -0.001, 1.001))
logging.info( "initializing terrain shader generator...")
file = 'shaders/terrain.sha'
if SAVED_TEXTURE_MAPS:
self.shaderGenerator = BakedTerrainShaderGenerator(self.terrain, self, self.textureMapper)
file = 'shaders/bakedTerrain.sha'
else:
self.shaderGenerator = FullTerrainShaderGenerator(self.terrain, self, self.textureMapper)
file = 'shaders/fullTerrain.sha'
logging.info( "terrain shader generator initialized...")
if RUNTYPE == 'python':
self.shaderGenerator.saveShader(file)
self.shader = Shader.load(file, Shader.SLCg)
else:
self.shader = Shader.make(self.shaderGenerator.createShader(), Shader.SLCg);
self.terrain.setShaderInput("normalMap", self.normalMap)
self.terrain.setShaderInput("displacementMap", self.displacementMap)
self.terrain.setShaderInput("detailTex", self.detailTex)
self.terrain.setShaderInput('tscale', self.texScale)
self.terrain.setShaderInput("fogColor", Vec4(1.0, 1.0, 1.0, 1.0))
self.terrain.setShaderInput("camPos", base.camera.getPos())
示例9: reconfigure
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def reconfigure(self, fullrebuild, changed):
""" Reconfigure is called whenever any configuration change is made. """
configuration = self.configuration
if (fullrebuild):
self.cleanup()
if (len(configuration) == 0):
return
auxbits = 0
needtex = set(["color"])
needtexcoord = set(["color"])
if ("CartoonInk" in configuration):
needtex.add("aux")
auxbits |= AuxBitplaneAttrib.ABOAuxNormal
needtexcoord.add("aux")
if ("AmbientOcclusion" in configuration):
needtex.add("depth")
needtex.add("ssao0")
needtex.add("ssao1")
needtex.add("ssao2")
needtex.add("aux")
auxbits |= AuxBitplaneAttrib.ABOAuxNormal
needtexcoord.add("ssao2")
if ("BlurSharpen" in configuration):
needtex.add("blur0")
needtex.add("blur1")
needtexcoord.add("blur1")
if ("Bloom" in configuration):
needtex.add("bloom0")
needtex.add("bloom1")
needtex.add("bloom2")
needtex.add("bloom3")
auxbits |= AuxBitplaneAttrib.ABOGlow
needtexcoord.add("bloom3")
if ("ViewGlow" in configuration):
auxbits |= AuxBitplaneAttrib.ABOGlow
if ("VolumetricLighting" in configuration):
needtex.add(configuration["VolumetricLighting"].source)
for tex in needtex:
self.textures[tex] = Texture("scene-" + tex)
self.textures[tex].setWrapU(Texture.WMClamp)
self.textures[tex].setWrapV(Texture.WMClamp)
self.finalQuad = self.manager.renderSceneInto(textures = self.textures, auxbits=auxbits)
if (self.finalQuad == None):
self.cleanup()
return False
if ("BlurSharpen" in configuration):
blur0=self.textures["blur0"]
blur1=self.textures["blur1"]
self.blur.append(self.manager.renderQuadInto(colortex=blur0,div=2))
self.blur.append(self.manager.renderQuadInto(colortex=blur1))
self.blur[0].setShaderInput("src", self.textures["color"])
self.blur[0].setShader(self.loadShader("filter-blurx.sha"))
self.blur[1].setShaderInput("src", blur0)
self.blur[1].setShader(self.loadShader("filter-blury.sha"))
if ("AmbientOcclusion" in configuration):
ssao0=self.textures["ssao0"]
ssao1=self.textures["ssao1"]
ssao2=self.textures["ssao2"]
self.ssao.append(self.manager.renderQuadInto(colortex=ssao0))
self.ssao.append(self.manager.renderQuadInto(colortex=ssao1,div=2))
self.ssao.append(self.manager.renderQuadInto(colortex=ssao2))
self.ssao[0].setShaderInput("depth", self.textures["depth"])
self.ssao[0].setShaderInput("normal", self.textures["aux"])
self.ssao[0].setShaderInput("random", loader.loadTexture("maps/random.rgb"))
self.ssao[0].setShader(Shader.make(SSAO_BODY % configuration["AmbientOcclusion"].numsamples, Shader.SL_Cg))
self.ssao[1].setShaderInput("src", ssao0)
self.ssao[1].setShader(self.loadShader("filter-blurx.sha"))
self.ssao[2].setShaderInput("src", ssao1)
self.ssao[2].setShader(self.loadShader("filter-blury.sha"))
if ("Bloom" in configuration):
bloomconf = configuration["Bloom"]
bloom0=self.textures["bloom0"]
bloom1=self.textures["bloom1"]
bloom2=self.textures["bloom2"]
bloom3=self.textures["bloom3"]
if (bloomconf.size == "large"):
scale=8
downsampler="filter-down4.sha"
elif (bloomconf.size == "medium"):
scale=4
downsampler="filter-copy.sha"
else:
scale=2
downsampler="filter-copy.sha"
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from panda3d.core import Shader [as 别名]
# 或者: from panda3d.core.Shader import make [as 别名]
def __init__(self, name, folder):
file=folder+'maps/'+name+'.txt'
d=parseFile(file)
#inputMapNames, tex2DNames, shaderSource
if "Input" in d:
self.inputMapNames=d["Input"]
else:
self.inputMapNames=[]
if "Tex2D" in d:
tex2D=d["Tex2D"]
else:
tex2D=[]
shaderSource='\n'.join(d["Shader"])
self.name=name
texLines=[]
paramsStrs=[]
paramsDefStrs=[]
for i in xrange(len(self.inputMapNames)):
texLines.append(' in uniform sampler2D tex_'+str(i)+': TEXUNIT'+str(i)+',')
paramsStrs.append('tex2D(tex_'+str(i)+', l_tex)')
paramsDefStrs.append('float4 map_'+self.inputMapNames[i])
self.shaderTex=[]
for t in tex2D:
i=len(texLines)
texName='tex_'+str(i)
texLines.append(' in uniform sampler2D '+texName+': TEXUNIT'+str(i)+',')
paramsStrs.append('tex_'+str(i))
paramsDefStrs.append('sampler2D tex2D_'+t)
tex=loadTex(folder+'textures/'+t)
texStage=TextureStage(t+"stage")
self.shaderTex.append((texStage,tex))
texText='\n'.join(texLines)
paramsText=', '.join(paramsStrs)
paramsDef=', '.join(paramsDefStrs)
if len(paramsDef)>0:
paramsDef=", "+paramsDef
paramsText=", "+paramsText
self.source=mapMakerShaderSource.replace('#tex#',texText)
self.source=self.source.replace('#params#',paramsText)
self.source=self.source.replace('#source#',shaderSource)
self.source=self.source.replace('#paramsDef#',paramsDef)
if useShaderFiles:
outLoc='ShadersOut/'+name+'.sha'
fOut=open(outLoc, 'w')
fOut.write(self.source)
fOut.close()
self.shader=loader.loadShader(outLoc)
else:
self.shader=Shader.make(self.source)
self.resolutionScale=1
self.addPixels=0
if "Settings" in d:
for s in d["Settings"]:
t=s.split()
v=t[1]
m=t[0]
if m=='resolutionScale':
self.resolutionScale=float(v)
elif m=='addPixels':
self.addPixels=int(v)