View Single Post
Old 11-25-2014, 08:08 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
You can add textures through the uniforms attribute of the effect class within the _createUniforms method. Here is a simple example:

class WarpEffect(vizfx.postprocess.BaseShaderEffect):

	def _getFragmentCode(self):
		return """
		uniform sampler2D vizpp_InputTex;
		uniform sampler2D redTex;
		uniform sampler2D blueTex;
		uniform sampler2D greenTex;
		void main()
			vec2 uv = gl_TexCoord[0].st;
			vec4 color = vec4(1.0);
			color.r = texture2D(vizpp_InputTex, texture2D(redTex, uv).rg).r;
			color.g = texture2D(vizpp_InputTex, texture2D(greenTex, uv).rg).g;
			color.b = texture2D(vizpp_InputTex, texture2D(blueTex, uv).rg).b;
			gl_FragColor = color;

	def _createUniforms(self):
		# Create texture objects
		redTex = viz.addTexture(...)
		greenTex = viz.addTexture(...)
		blueTex = viz.addTexture(...)
		# Apply textures to effect (automatically assigns uniform IDs)
		self.uniforms.addTexture('redTex', redTex)
		self.uniforms.addTexture('greenTex', greenTex)
		self.uniforms.addTexture('blueTex', blueTex)

Have a look at the Post-Process basics page in the documentation for more info:
Reply With Quote