WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-16-2013, 06:14 AM
goro goro is offline
Member
 
Join Date: May 2012
Posts: 33
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!
Reply With Quote
  #2  
Old 05-31-2013, 01:44 AM
goro goro is offline
Member
 
Join Date: May 2012
Posts: 33
Unhappy Urgent help required

Please help me to mimic viz.TEXGEN_PROJECT_EYE using shader
Reply With Quote
Reply

Tags
texgen, texture coordinates

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


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


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