-/* $Id: s_bitmap.c,v 1.10 2001/05/30 15:22:05 brianp Exp $ */
+/* $Id: s_bitmap.c,v 1.11 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
fragZ = (GLdepth) ( ctx->Current.RasterPos[2] * ctx->DepthMaxF);
if (ctx->Fog.Enabled) {
- if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fogCoord = ctx->Current.FogCoord;
- else
- fogCoord = ctx->Current.RasterDistance;
+ }
+ else {
+ fogCoord = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
}
else {
fogCoord = 0.0;
-/* $Id: s_copypix.c,v 1.19 2001/05/30 15:22:05 brianp Exp $ */
+/* $Id: s_copypix.c,v 1.20 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "s_context.h"
#include "s_depth.h"
+#include "s_fog.h"
#include "s_histogram.h"
#include "s_pixeltex.h"
#include "s_span.h"
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
GLint i;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i = 0; i < width; i++) {
zspan[i] = z;
fogSpan[i] = fog;
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;
}
if (ctx->Fog.Enabled) {
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i = 0; i < width; i++) {
fogSpan[i] = fog;
}
-/* $Id: s_drawpix.c,v 1.20 2001/05/30 15:22:05 brianp Exp $ */
+/* $Id: s_drawpix.c,v 1.21 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "s_context.h"
#include "s_drawpix.h"
+#include "s_fog.h"
#include "s_pixeltex.h"
#include "s_span.h"
#include "s_stencil.h"
/* Fragment depth values */
if (ctx->Depth.Test || ctx->Fog.Enabled) {
GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF);
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
GLint i;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i = 0; i < drawWidth; i++) {
zspan[i] = zval;
fogSpan[i] = fog;
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF);
- GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
- ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
+ GLfloat fog;
GLint i;
+
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
+ fog = ctx->Current.RasterFogCoord;
+ }
+ else {
+ fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ }
+
for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;
-/* $Id: s_fog.c,v 1.12 2001/05/03 22:13:32 brianp Exp $ */
+/* $Id: s_fog.c,v 1.13 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "s_pb.h"
+
+
+/*
+ * Used to convert current raster distance to a fog factor in [0,1].
+ */
+GLfloat
+_mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z)
+{
+ GLfloat d, f;
+
+ switch (ctx->Fog.Mode) {
+ case GL_LINEAR:
+ if (ctx->Fog.Start == ctx->Fog.End)
+ d = 1.0F;
+ else
+ d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
+ f = (ctx->Fog.End - z) * d;
+ return CLAMP(f, 0.0F, 1.0F);
+ case GL_EXP:
+ d = ctx->Fog.Density;
+ f = exp(-d * z);
+ return f;
+ case GL_EXP2:
+ d = ctx->Fog.Density;
+ f = exp(-(d * d * z * z));
+ return f;
+ default:
+ _mesa_problem(ctx, "Bad fog mode in make_fog_coord");
+ return 0.0;
+ }
+}
+
+
+
/*
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
- * fog - array of interpolated screen-space fog coordinates in [0..1]
+ * fog - array of fog factors in [0,1]
* red, green, blue, alpha - pixel colors
* Output: red, green, blue, alpha - fogged pixel colors
*/
/*
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
- * z - array of integer depth values
+ * fog - array of fog factors in [0,1]
* index - pixel color indexes
* Output: index - fogged pixel color indexes
*/
/*
- * Calculate fog coords from window z values
+ * Calculate fog factors (in [0,1]) from window z values
* Input: n - number of pixels
* z - array of integer depth values
* red, green, blue, alpha - pixel colors
*
* Use lookup table & interpolation?
*/
-void
-_mesa_win_fog_coords_from_z( const GLcontext *ctx,
- GLuint n,
- const GLdepth z[],
- GLfloat fogcoord[] )
+static void
+compute_fog_factors_from_z( const GLcontext *ctx,
+ GLuint n,
+ const GLdepth z[],
+ GLfloat fogFact[] )
{
const GLboolean ortho = (ctx->ProjectionMatrix.m[15] != 0.0F);
const GLfloat p10 = ctx->ProjectionMatrix.m[10];
GLfloat eyez = (ndcz - p14) / p10;
if (eyez < 0.0)
eyez = -eyez;
- fogcoord[i] = (fogEnd - eyez) * fogScale;
+ fogFact[i] = (fogEnd - eyez) * fogScale;
}
}
else {
GLfloat eyez = p14 / (ndcz + p10);
if (eyez < 0.0)
eyez = -eyez;
- fogcoord[i] = (fogEnd - eyez) * fogScale;
+ fogFact[i] = (fogEnd - eyez) * fogScale;
}
}
}
GLfloat eyez = (ndcz - p14) / p10;
if (eyez < 0.0)
eyez = -eyez;
- fogcoord[i] = exp( -ctx->Fog.Density * eyez );
+ fogFact[i] = exp( -ctx->Fog.Density * eyez );
}
}
else {
GLfloat eyez = p14 / (ndcz + p10);
if (eyez < 0.0)
eyez = -eyez;
- fogcoord[i] = exp( -ctx->Fog.Density * eyez );
+ fogFact[i] = exp( -ctx->Fog.Density * eyez );
}
}
break;
if (tmp < FLT_MIN_10_EXP)
tmp = FLT_MIN_10_EXP;
#endif
- fogcoord[i] = exp( tmp );
+ fogFact[i] = exp( tmp );
}
}
else {
if (tmp < FLT_MIN_10_EXP)
tmp = FLT_MIN_10_EXP;
#endif
- fogcoord[i] = exp( tmp );
+ fogFact[i] = exp( tmp );
}
}
}
break;
default:
- _mesa_problem(ctx, "Bad fog mode in _mesa_win_fog_coords_from_z");
+ _mesa_problem(ctx, "Bad fog mode in compute_fog_factors_from_z");
return;
}
}
_mesa_depth_fog_rgba_pixels( const GLcontext *ctx,
GLuint n, const GLdepth z[], GLchan rgba[][4] )
{
- GLfloat fog[PB_SIZE];
+ GLfloat fogFact[PB_SIZE];
ASSERT(n <= PB_SIZE);
- _mesa_win_fog_coords_from_z( ctx, n, z, fog );
- _mesa_fog_rgba_pixels( ctx, n, fog, rgba );
+ compute_fog_factors_from_z( ctx, n, z, fogFact );
+ _mesa_fog_rgba_pixels( ctx, n, fogFact, rgba );
}
_mesa_depth_fog_ci_pixels( const GLcontext *ctx,
GLuint n, const GLdepth z[], GLuint index[] )
{
- GLfloat fog[PB_SIZE];
+ GLfloat fogFact[PB_SIZE];
ASSERT(n <= PB_SIZE);
- _mesa_win_fog_coords_from_z( ctx, n, z, fog );
- _mesa_fog_ci_pixels( ctx, n, fog, index );
+ compute_fog_factors_from_z( ctx, n, z, fogFact );
+ _mesa_fog_ci_pixels( ctx, n, fogFact, index );
}
-/* $Id: s_fog.h,v 1.4 2001/05/03 22:13:32 brianp Exp $ */
+/* $Id: s_fog.h,v 1.5 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "swrast.h"
+extern GLfloat
+_mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z);
+
+
extern void
_mesa_fog_rgba_pixels( const GLcontext *ctx,
GLuint n, const GLfloat fog[],
-/* $Id: s_span.c,v 1.14 2001/05/15 21:30:27 brianp Exp $ */
+/* $Id: s_span.c,v 1.15 2001/06/18 23:55:18 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Input: n - number of pixels in the span
* x, y - location of leftmost pixel in the span
* z - array of [n] z-values
+ * fog - array of fog factor values in [0,1]
* index - array of [n] color indexes
* primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP
*/
* Input: n - number of pixels in the span
* x, y - location of leftmost pixel in the span
* z - array of [n] z-values
+ * fog - array of fog factor values in [0,1]
* r, g, b, a - the color of the pixels
* primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
*/