Perspective Divide

Hello!

Does anyone know how I can turn perspective divide off for texture coordinates? Or maybe how to compute the divide out of it. (I actually need the perspective correction turned off.) I’m guessing it’s a render state, but I’m having difficulties locating it.

-Greg

Looks like I’m able to null it out in the vertex shader:

l_position=mul(mat_modelproj, vtx_position);
l_position.xyz = l_position.xyz/l_position.w;
l_position.w = 1.0;

-Greg

This caused some nasty clipping artifacts. So I’m going to try a different approach instead. Thanks anyways. :slight_smile:

I’m unclear as to what a perspective divide is exactly, but are you looking for an orthogonal camera/lens deal?
Check the manual here: www.panda3d.org/manual/index.php/O … hic_Lenses

Hope that helped…

I think he is talking about Pov or frustum, you can set those on base.camera

No, he’s talking about the way that modern graphics cards automatically render textures so that the texture details show foreshortening as the polygon recedes into the distance. This is called “perspective correct textures”, and is necessary to make textures look correct without having lots of vertices.

You take this feature for granted these days, but in the early days of 3-D graphics it was a big deal and didn’t come for free. For instance, the original Playstation didn’t do this. You could see artifacts of this from textures that appear to stretch weirdly as you rotated your point of view.

I don’t know of any easy way to turn this feature off, but you might be able to do with a fragment shader. Or, you could use a software renderer like Mesa, which does allow you to turn it off (mainly because it’s an expensive feature to enable in software).

David

So, I’m not entirely sure what you’re trying to acheive by turning texture perspective off, but I can tell you I’ve effectively done it with Panda before. When I wanted to create a cartoon-like effect I’ve seen before. It’s most often seen when animators draw in plaid without contouring it to the object its on. This usually makes the texture look static, flat, and surreal, as the object moves yet the texture remains the same.

The way I did it was to dynamically project the texture onto whatever object from the camera’s point of view with the exact same lens properties as the camera. This might be a bit performance intensive if you intend to use it scene-wide however.

Otherwise, I think your stuck writing a custom shader for it. These kind of things happen at the video card level these days.

Here’s a quick example of what I’ve done before. It uses all standard Panda files so no worries there.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
import sys, os

#Create texture projector, parent to camera
proj = render.attachNewNode(LensNode('proj'))
lens = PerspectiveLens()
proj.node().setLens(lens)
proj.reparentTo(base.camera)

#Load assets
model = loader.loadModel('models/teapot')
model.reparentTo(render)
tex = loader.loadTexture('maps/envir-treetrunk.jpg')
ts = TextureStage('ts')

#Project texture onto teapot
model.projectTexture(ts, tex, proj)

#Rotate teapot
dummy = render.attachNewNode('dummy')
dummy.setPos(0, 15, -0.5)
model.reparentTo(dummy)
intervalA = model.hprInterval(1.0,Vec3(360, 0, 0))
intervalA.loop()
intervalB = dummy.hprInterval(1.66,Vec3(0, 360, 0))
intervalB.loop()

run()