From the glTexGen documentation ::
void glTexGenfv ( GLenum coord , GLenum pname , const GLfloat *params );
- coord - sets the coordinate of the texture. Must be one of GL_S, GL_T, GL_R or GL_Q.
- pname - if the texture generation function GL_OBJECT_LINEAR, the function
g = p1 xo + p2 yo + p3 zo + p4 wo
where g is the value calculated for the coordinate named in the coordinate, ...
therefore g is indeed a scalar value, which can be either s or the t-component of your value vec2 uv, depending on the coordinate value (GL_S or GL_T).
To be more explicit, the challenges
glTexGen(GL_S, GL_OBJECT_LINEAR, {ps0,ps1,ps2,ps3}) glTexGen(GL_T, GL_OBJECT_LINEAR, {pt0,pt1,pt2,pt3})
looks like
vec4 sPlane = vec4(ps0,ps1,ps2,ps3); vec4 tPlane = vec4(pt0,pt1,pt2,pt3); kOutBaseTCoord.s = dot(vec4(POSITION, 1.0), sPlane); kOutBaseTCoord.t = dot(vec4(POSITION, 1.0), tPlane);
Depending on the scale of your POSITION values, the output st coordinates may be outside the range (0,1). Using your values:
vec4 sPlane = vec4(1.0, 0.0, 0.0, 0.0); vec4 tPlane = vec4(0.0, 1.0, 0.0, 0.0);
will directly map the x coordinate of your model vertices to the s values ββof your texture coordinates, the same for y and t. Thus, if your model has a coordinate range outside (0,1), UV values ββwill follow.
To make the texture fit your model, you need to adapt the projection scale to the size of your model. For an approximate model size of 100.0, this will produce the following code:
float MODEL_SIZE = 100.0; vec4 sPlane = vec4(1.0/MODEL_SIZE, 0.0, 0.0, 0.0); vec4 tPlane = vec4(0.0, 1.0/MODEL_SIZE, 0.0, 0.0);
This solution can still give you values ββ<0 if you are modeling in the center (0,0,0). To adjust this, you can add an offset to the resulting UV values. For example:
kOutBaseTCoord.st += vec(0.5);
Please note that it all depends on your application and what you are trying to achieve with your texture projection. Feel free to adjust your formulas according to your needs, for which shaders are needed!