![]() |
|
#1
|
|||
|
|||
|
Texture Coordinate Generation (TexGen) using Shader
Hi, we are receiving particular result with fixed functionality but finding difficult to get that using shader. We have to use the shader to go beyond the fixed functionality.
We have to mimic viz.TEXGEN_PROJECT_EYE in our shader to use nearby Texture Coordinates. First the successful implementation of what we are getting using fixed functionality: Code:
import viz
import vizact
viz.go()
#Add Piazza
piazza = viz.addChild('piazza.osgb')
#Add, Position & Scale TexQuad
quad = viz.addTexQuad()
quad.setPosition(0,2,6)
quad.setScale(2,2)
#Render Node & Render Texture
RT = viz.addRenderTexture()
RT.wrap(viz.WRAP_T, viz.REPEAT)
RT.wrap(viz.WRAP_S, viz.REPEAT)
RN = viz.addRenderNode()
RN.attachTexture(RT)
#Apply Rendered Texture to quad
quad.texture(RT)
#Get the Invisible Effect from generating the Texture Coordanates
quad.texGen(viz.TEXGEN_PROJECT_EYE)
#Spin the quad to see invisible effect
spin = vizact.spin(1,1,1,10)
quad.addAction(spin)
We have written a shader instead of TexGen. Check the code below: Code:
import viz
import vizact
viz.go()
#Add Piazza
piazza = viz.addChild('piazza.osgb')
#Add, Position & Scale TexQuad
quad = viz.addTexQuad()
quad.setPosition(0,2,6)
quad.setScale(2,2)
#Render Node & Render Texture
RT = viz.addRenderTexture()
RT.wrap(viz.WRAP_T, viz.REPEAT)
RT.wrap(viz.WRAP_S, viz.REPEAT)
RN = viz.addRenderNode()
RN.attachTexture(RT)
#Apply Rendered Texture to quad
quad.texture(RT)
#Shader
vertCode = """
void main()
{
gl_Position = ftransform();
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[0].s = dot(ecPosition,gl_EyePlaneS[0]);
gl_TexCoord[0].t = dot(ecPosition,gl_EyePlaneT[0]);
gl_TexCoord[0].p = dot(ecPosition,gl_EyePlaneR[0]);
gl_TexCoord[0].q = dot(ecPosition,gl_EyePlaneQ[0]);
}
"""
fragCode = """
uniform sampler2D tex;
void main()
{
gl_FragColor = texture2D(tex,gl_TexCoord[0].st);
}
"""
shader = viz.addShader(vert = vertCode, frag = fragCode)
quad.apply(shader)
quad.apply(viz.addUniformInt('tex',0))
#Spin the quad to see invisible effect
spin = vizact.spin(1,1,1,10)
quad.addAction(spin)
Please help us. If any efficient alternate way then please suggest. Thanks! |
| Tags |
| texgen, texture coordinates |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to render a texture of the transparent object and then blur it | whj | Vizard | 1 | 09-25-2012 03:15 PM |
| Avatar texture swaping | sleiN13 | Vizard | 5 | 06-24-2011 12:48 AM |
| How to apply shader and render texture to an object | whj | Vizard | 0 | 04-23-2010 12:23 PM |
| Shader for blurring | whj | Vizard | 1 | 04-19-2010 11:28 AM |
| Multiple Textures for Diffuse and Specularity Shader Issue | shivanangel | Vizard | 1 | 05-11-2009 10:44 AM |