Question

I'm trying to convert a CG program to a GLSL program.

What I've done so far seems correct, but the GLSL shader outputs an incorrect output. The incorrect behavior is defined by a set of test images.

The only dark point on which I'm investigating is the function f3texRECT, which I've translated in texture. However, I cannot find any documentation about f3texRECT.

Can somebody put some light about?

Was it helpful?

Solution

f3texRECT() looks like it would map to texture() with a sampler2DRect instead of a sampler2D -- meaning the texture coordinates are unnormalized ([0..textureSize-1] instead of [0..1]). The "f3" prefix means the result is a three-channel color. Older versions of GLSL had a textureRect() function for this purpose, but it's been deprecated.

OTHER TIPS

f3texRECT(..args..) is exactly equivalent to texRECT(..args..).xyz in Cg -- it exists as a holdover from the older HSL which didn't have fully general swizzles.

In GLSL the equivalent function is texture, so you should be to use texture(..arg..).xyz there too, though the args might be slightly different.

The main confusion translating texture calls from Cg to GLSL is dealing with shadow textures -- shadow texture lookups in Cg use normal samplers but the tex call has an extra component in the coordinate. GLSL has distinct shadow sampler types instead. So when translating Cg to GLSL you need to figure out which textures are 'normal' textures and which are 'shadow' textures, based on how they are used. In the rare case that you have a single texture used for both normal and shadow lookups, you need to split it into two samplers for GLSL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top