WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Texture Coordinate Generation (TexGen) using Shader (https://forum.worldviz.com/showthread.php?t=4588)

goro 05-16-2013 06:14 AM

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)

Bye using above code we are making quad invisible.

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)

This code is giving us the parallel projection of Rendered Texture to screen but we don't know how to position & scale it to get as fine effect as the previous fixed functionality code.

Please help us. If any efficient alternate way then please suggest.

Thanks!

goro 05-31-2013 01:44 AM

Urgent help required
 
Please help me to mimic viz.TEXGEN_PROJECT_EYE using shader :(


All times are GMT -7. The time now is 01:27 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC