Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#56 Bug fix: textureinfo() & float texture()

open
nobody
None
5
2005-09-14
2005-09-14
Du Jie
No

Hi,

When rendering tree models with leaf textures of
RGBA channels, I find that: (Ref: code below)
[1] textureinfo(texturename,"channels",nChannel) does
not return with nChannel =4. In fact, it always report
3 channels.

[2] opac=float texture(texturename[3],"fill",1); give
the incorrect opac value when the input texture is in
RGB format,
opac should be "1" if alpha channel is not found.

After checking the Pixie 1.4.6 source, I have
managed to fix this two bugs, and the source patch is
attached in this report, maybe it is of any use to
Pixie lovers. ;-)

Now my tree models are rendering happily with PIXIE!

Regards,

Du Jie

//------------------- Code
-----------------------------------------------------
//Get opacity
//3Delight is slow at guessing non-existent channel
value.(Maybe because img is not prepared by tdlmake?)
/*
D.J. 2005/9/9

Pixie 1.4.6 does not give correct result via
texture(..,"fill",1).
*/
#if defined(DELIGHT)||defined(_PIXIE_)
#pragma message("Get alpha channel via textureinfo()\n")
uniform float nChannel=3;
textureinfo(texturename,"channels",nChannel);

TRACE2("tex=[%s] nChannel=[%f]\n",
texturename,nChannel);

opac=1;
if(nChannel>3){

opac=float texture(texturename[3]);
}

#else //PRMAN & AQSIS & BMRT & AIR

opac=float texture(texturename[3],"fill",1);

TRACE2("tex=[%s] opac=[%f]\n", texturename,opac);

#endif

============[ Fix: float texture() ]===========
In Texture.cpp: [line 880]

void CTextureLayer::lookup(float *r,float x,float
y,const CTextureLookup *l) {

/*
DJ 2005/9/10

Fix the channel overflow bug!
effect: the float texture(texturename[3],"fill",1)
will not give the result of "1" when texturename is
a 3-channel texture.

*/
//////////////////////// Fix begin
///////////////////////////////////////////
if(l->channel>=this->numSamples){//Channel overflow
r[0]=l->fill;
if(!l->lookupFloat){
r[1]=l->fill;
r[2]=l->fill;
}
return;
}
//////////////////////////Fix end
//////////////////////////////////
int xi;
int yi;
float dx;
float dy;
float res[4*3];
float tmp;

==========[Fix: textureinfo() ]================
This fix coovers serval source.
(1) add a virtual method in "texture.h"
class CTexture{

//-------- D.J. 2005/9/10 --------------------------
virtual int getNumChannels() const=0;
//---------------------------------------------------
}

(2)In "texture.cpp", implements the new virtual method:

class CMadeTexture : public CTexture {
public:
//----------- D.J. ------- 2005/9/10 --------------
virtual int getNumChannels() const{
assert(numLayers);
return layers[0]->numSamples;
}
//-------------------------------------------------
};

class CRegularTexture : public CTexture {
public:
//----------- D.J. ------- 2005/9/10 --------------
virtual int getNumChannels() const{
assert(layer);
return layer->numSamples;
}
//-------------------------------------------------
};

(3) In ShaderFunctions.h (line 943) , apply the fix to
textureinfo() API:

define TEXTUREINFO_PRE FUN4OUTEXPR_PRE \ float found; \ CTexture *texture; \ TCode out[16*2]; \ \ texture = getTexture(op1->string); \ \ if (texture == NULL) { \ found = 0; \ } else { \ int i; \ \ for (i=0;i<16*2;i++) out[i].real = 0; \ \ found = 1; \ \ if (strcmp(op2->string,"resolution") == 0) { \ out[0].real = (float) texture->width; \ out[1].real = (float) texture->height; \ } else if
(strcmp(op2->string,"type") == 0) { \ out[0].string = "FIXME"; \ } else if (strcmp(op2->string,"channels")
== 0) { \

out[0].real=(float)texture->getNumChannels();// MyFix \ /*Old impl: out[0].real = (float) 3;*/ \ } else if (strcmp(op2->string,"viewingmatrix")
== 0) { \ } else if
(strcmp(op2->string,"projectionmatrix") == 0) { \ } else { \ found = 0; \ } \ }

Discussion