|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectprocessing.core.PImage
processing.core.PGraphics
processing.core.PGraphics3D
public class PGraphics3D
Subclass of PGraphics that handles 3D rendering. It can render 3D inside a browser window and requires no plug-ins.
The renderer is mostly set up based on the structure of the OpenGL API, if you have questions about specifics that aren't covered here, look for reference on the OpenGL implementation of a similar feature. Lighting and camera implementation by Simon Greenwold.
| Field Summary | |
|---|---|
PMatrix3D |
camera
The camera matrix, the modelview will be set to this on beginDraw. |
float |
cameraAspect
Aspect ratio of camera's view. |
float |
cameraFar
|
float |
cameraFOV
Camera field of view. |
float |
cameraNear
|
float |
cameraX
Position of the camera. |
float |
cameraY
Position of the camera. |
float |
cameraZ
Position of the camera. |
float |
currentLightFalloffConstant
Current light falloff |
float |
currentLightFalloffLinear
|
float |
currentLightFalloffQuadratic
|
float[] |
currentLightSpecular
Current specular color for lighting |
int |
lightCount
|
float[][] |
lightDiffuse
Diffuse colors for lights. |
float[] |
lightFalloffConstant
Light falloff |
float[] |
lightFalloffLinear
|
float[] |
lightFalloffQuadratic
|
PVector[] |
lightNormal
Light direction (normalized vector) |
PVector[] |
lightPosition
Light positions |
float[][] |
lightSpecular
Specular colors for lights. |
float[] |
lightSpotAngle
Light spot angle |
float[] |
lightSpotAngleCos
Cosine of light spot angle |
float[] |
lightSpotConcentration
Light spot concentration |
int[] |
lightType
Light types |
PLine |
line
|
static int |
MAX_LIGHTS
Maximum lights by default is 8, which is arbitrary for this renderer, but is the minimum defined by OpenGL |
PMatrix3D |
modelview
The modelview matrix. |
PMatrix3D |
modelviewInv
Inverse modelview matrix, used for lighting. |
PMatrix3D |
projection
Current projection matrix. |
PSmoothTriangle |
smoothTriangle
Used for anti-aliased and perspective corrected rendering. |
static int |
TRI_COLOR_COUNT
|
static int |
TRI_DIFFUSE_A
|
static int |
TRI_DIFFUSE_B
|
static int |
TRI_DIFFUSE_G
|
static int |
TRI_DIFFUSE_R
|
static int |
TRI_SPECULAR_B
|
static int |
TRI_SPECULAR_G
|
static int |
TRI_SPECULAR_R
|
PTriangle |
triangle
|
float[] |
zbuffer
The depth buffer. |
| Fields inherited from class processing.core.PGraphics |
|---|
ambientB, ambientG, ambientR, backgroundColor, bezierDetail, colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, curveTightness, edge, ellipseMode, emissiveB, emissiveG, emissiveR, fill, fillColor, image, imageMode, normalX, normalY, normalZ, pixelCount, rectMode, shapeMode, shininess, smooth, specularB, specularG, specularR, sphereDetailU, sphereDetailV, stroke, strokeCap, strokeColor, strokeJoin, strokeWeight, textAlign, textAlignY, textFont, textLeading, textMode, textSize, textureImage, textureMode, textureU, textureV, tint, tintColor |
| Fields inherited from class processing.core.PImage |
|---|
format, height, parent, pixels, width |
| Constructor Summary | |
|---|---|
PGraphics3D()
|
|
| Method Summary | |
|---|---|
void |
ambientLight(float r,
float g,
float b)
Add an ambient light based on the current color mode. |
void |
ambientLight(float r,
float g,
float b,
float x,
float y,
float z)
Add an ambient light based on the current color mode. |
void |
applyMatrix(float n00,
float n01,
float n02,
float n10,
float n11,
float n12)
Apply a 3x2 affine transformation matrix. |
void |
applyMatrix(float n00,
float n01,
float n02,
float n03,
float n10,
float n11,
float n12,
float n13,
float n20,
float n21,
float n22,
float n23,
float n30,
float n31,
float n32,
float n33)
Apply a 4x4 transformation matrix. |
void |
applyMatrix(PMatrix2D source)
|
void |
applyMatrix(PMatrix3D source)
|
void |
beginCamera()
Set matrix mode to the camera matrix (instead of the current transformation matrix). |
void |
beginDraw()
Prepares the PGraphics for drawing. |
void |
beginShape(int kind)
Start a new shape. |
void |
box(float w,
float h,
float d)
|
void |
camera()
Set camera to the default settings. |
void |
camera(float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ)
More flexible method for dealing with camera(). |
void |
directionalLight(float r,
float g,
float b,
float nx,
float ny,
float nz)
|
void |
endCamera()
Record the current settings into the camera matrix, and set the matrix mode back to the current transformation matrix. |
void |
endDraw()
See notes in PGraphics. |
void |
endShape(int mode)
|
void |
flush()
Emit any sorted geometry that's been collected on this frame. |
void |
frustum(float left,
float right,
float bottom,
float top,
float znear,
float zfar)
Same as glFrustum(), except that it wipes out (rather than multiplies against) the current perspective matrix. |
PMatrix |
getMatrix()
|
PMatrix3D |
getMatrix(PMatrix3D target)
Copy the current transformation matrix into the specified target. |
void |
hint(int which)
Enable a hint option. |
boolean |
is2D()
Return true if this renderer supports 2D drawing. |
boolean |
is3D()
Return true if this renderer supports 2D drawing. |
void |
lightFalloff(float constant,
float linear,
float quadratic)
Set the light falloff rates for the last light that was created. |
void |
lights()
Sets up an ambient and directional light. |
void |
lightSpecular(float x,
float y,
float z)
Set the specular color of the last light created. |
float |
modelX(float x,
float y,
float z)
Returns the model space x value for an x, y, z coordinate. |
float |
modelY(float x,
float y,
float z)
Returns the model space y value for an x, y, z coordinate. |
float |
modelZ(float x,
float y,
float z)
Returns the model space z value for an x, y, z coordinate. |
void |
noLights()
Turn off all lights. |
void |
noSmooth()
Disable smoothing. |
void |
ortho()
Calls ortho() with the proper parameters for Processing's standard orthographic projection. |
void |
ortho(float left,
float right,
float bottom,
float top,
float near,
float far)
Similar to gluOrtho(), but wipes out the current projection matrix. |
void |
perspective()
Calls perspective() with Processing's standard coordinate projection. |
void |
perspective(float fov,
float aspect,
float zNear,
float zFar)
Similar to gluPerspective(). |
void |
pointLight(float r,
float g,
float b,
float x,
float y,
float z)
|
void |
popMatrix()
Replace the current transformation matrix with the top of the stack. |
void |
printCamera()
Print the current camera matrix. |
void |
printMatrix()
Print the current model (or "transformation") matrix. |
void |
printProjection()
Print the current projection matrix. |
void |
pushMatrix()
Push a copy of the current transformation matrix onto the stack. |
void |
resetMatrix()
Set the current transformation matrix to identity. |
void |
rotate(float angle)
Two dimensional rotation. |
void |
rotate(float angle,
float v0,
float v1,
float v2)
Rotate around an arbitrary vector, similar to glRotate(), except that it takes radians (instead of degrees). |
void |
rotateX(float angle)
Rotate around the X axis. |
void |
rotateY(float angle)
Rotate around the Y axis. |
void |
rotateZ(float angle)
Rotate around the Z axis. |
void |
scale(float s)
Same as scale(s, s, s). |
void |
scale(float sx,
float sy)
Same as scale(sx, sy, 1). |
void |
scale(float x,
float y,
float z)
Scale in three dimensions. |
float |
screenX(float x,
float y)
Given an x and y coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations. |
float |
screenX(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
float |
screenY(float x,
float y)
Given an x and y coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations. |
float |
screenY(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
float |
screenZ(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
void |
setMatrix(PMatrix2D source)
Set the current transformation to the contents of the specified source. |
void |
setMatrix(PMatrix3D source)
Set the current transformation to the contents of the specified source. |
void |
setSize(int iwidth,
int iheight)
Called in response to a resize event, handles setting the new width and height internally, as well as re-allocating the pixel buffer for the new size. |
void |
smooth()
If true in PImage, use bilinear interpolation for copy() operations. |
void |
sphere(float r)
Draw a sphere with radius r centered at coordinate 0, 0, 0. |
void |
spotLight(float r,
float g,
float b,
float x,
float y,
float z,
float nx,
float ny,
float nz,
float angle,
float concentration)
|
void |
strokeCap(int cap)
|
void |
strokeJoin(int join)
|
void |
texture(PImage image)
Set texture image for current shape. |
void |
translate(float tx,
float ty)
Translate in X and Y. |
void |
translate(float tx,
float ty,
float tz)
Translate in X, Y, and Z. |
void |
vertex(float x,
float y)
|
void |
vertex(float x,
float y,
float u,
float v)
|
| Methods inherited from class processing.core.PImage |
|---|
blend, blend, blendColor, clone, copy, copy, filter, filter, get, get, get, getCache, getImage, init, isModified, loadPixels, mask, mask, removeCache, resize, save, set, set, setCache, setModified, setModified, updatePixels, updatePixels |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public float[] zbuffer
public PMatrix3D modelview
public PMatrix3D modelviewInv
public PMatrix3D camera
public float cameraFOV
public float cameraX
public float cameraY
public float cameraZ
public float cameraNear
public float cameraFar
public float cameraAspect
public PMatrix3D projection
public static final int MAX_LIGHTS
public int lightCount
public int[] lightType
public PVector[] lightPosition
public PVector[] lightNormal
public float[] lightFalloffConstant
public float[] lightFalloffLinear
public float[] lightFalloffQuadratic
public float[] lightSpotAngle
public float[] lightSpotAngleCos
public float[] lightSpotConcentration
public float[][] lightDiffuse
public float[][] lightSpecular
public float[] currentLightSpecular
public float currentLightFalloffConstant
public float currentLightFalloffLinear
public float currentLightFalloffQuadratic
public static final int TRI_DIFFUSE_R
public static final int TRI_DIFFUSE_G
public static final int TRI_DIFFUSE_B
public static final int TRI_DIFFUSE_A
public static final int TRI_SPECULAR_R
public static final int TRI_SPECULAR_G
public static final int TRI_SPECULAR_B
public static final int TRI_COLOR_COUNT
public PSmoothTriangle smoothTriangle
public PLine line
public PTriangle triangle
| Constructor Detail |
|---|
public PGraphics3D()
| Method Detail |
|---|
public void setSize(int iwidth,
int iheight)
setSize in class PGraphicspublic void beginDraw()
PGraphics
beginDraw in class PGraphicspublic void endDraw()
endDraw in class PGraphicspublic void hint(int which)
PGraphicsFor the most part, hints are temporary api quirks, for which a proper api hasn't been properly worked out. for instance SMOOTH_IMAGES existed because smooth() wasn't yet implemented, but it will soon go away.
They also exist for obscure features in the graphics engine, like enabling/disabling single pixel lines that ignore the zbuffer, the way they do in alphabot.
Current hint options:
hint in class PGraphicspublic void beginShape(int kind)
PGraphicsDifferences between beginShape() and line() and point() methods.
beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.
The line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.
From the code side of things, line() may or may not call beginShape() to do the drawing. In the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency &mdash meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.
beginShape in class PGraphicspublic void texture(PImage image)
PGraphics
texture in class PGraphicsimage - reference to a PImage object
public void vertex(float x,
float y)
vertex in class PGraphics
public void vertex(float x,
float y,
float u,
float v)
vertex in class PGraphicspublic void endShape(int mode)
endShape in class PGraphicspublic void flush()
flush in class PGraphics
public void box(float w,
float h,
float d)
box in class PGraphicspublic void sphere(float r)
PGraphicsImplementation notes:
cache all the points of the sphere in a static array top and bottom are just a bunch of triangles that land in the center point
sphere is a series of concentric circles who radii vary along the shape, based on, er.. cos or something
[toxi 031031] new sphere code. removed all multiplies with radius, as scale() will take care of that anyway [toxi 031223] updated sphere code (removed modulos) and introduced sphereAt(x,y,z,r) to avoid additional translate()'s on the user/sketch side [davbol 080801] now using separate sphereDetailU/V
sphere in class PGraphicspublic void smooth()
PGraphics
smooth in class PGraphicspublic void noSmooth()
PGraphics
noSmooth in class PGraphicspublic void pushMatrix()
PGraphics
pushMatrix in class PGraphicspublic void popMatrix()
PGraphics
popMatrix in class PGraphics
public void translate(float tx,
float ty)
PGraphics
translate in class PGraphics
public void translate(float tx,
float ty,
float tz)
PGraphics
translate in class PGraphicspublic void rotate(float angle)
rotate in class PGraphicspublic void rotateX(float angle)
PGraphics
rotateX in class PGraphicspublic void rotateY(float angle)
PGraphics
rotateY in class PGraphicspublic void rotateZ(float angle)
PGraphics
rotateZ in class PGraphics
public void rotate(float angle,
float v0,
float v1,
float v2)
rotate in class PGraphicspublic void scale(float s)
scale in class PGraphics
public void scale(float sx,
float sy)
scale in class PGraphics
public void scale(float x,
float y,
float z)
scale in class PGraphicspublic void resetMatrix()
PGraphics
resetMatrix in class PGraphicspublic void applyMatrix(PMatrix2D source)
applyMatrix in class PGraphics
public void applyMatrix(float n00,
float n01,
float n02,
float n10,
float n11,
float n12)
PGraphics
applyMatrix in class PGraphicspublic void applyMatrix(PMatrix3D source)
applyMatrix in class PGraphics
public void applyMatrix(float n00,
float n01,
float n02,
float n03,
float n10,
float n11,
float n12,
float n13,
float n20,
float n21,
float n22,
float n23,
float n30,
float n31,
float n32,
float n33)
applyMatrix in class PGraphicspublic PMatrix getMatrix()
getMatrix in class PGraphicspublic PMatrix3D getMatrix(PMatrix3D target)
PGraphics
getMatrix in class PGraphicspublic void setMatrix(PMatrix2D source)
PGraphics
setMatrix in class PGraphicspublic void setMatrix(PMatrix3D source)
setMatrix in class PGraphicspublic void printMatrix()
printMatrix in class PGraphicspublic void beginCamera()
Note that the camera matrix is *not* the perspective matrix, it is in front of the modelview matrix (hence the name "model" and "view" for that matrix).
beginCamera() specifies that all coordinate transforms until endCamera() should be pre-applied in inverse to the camera transform matrix. Note that this is only challenging when a user specifies an arbitrary matrix with applyMatrix(). Then that matrix will need to be inverted, which may not be possible. But take heart, if a user is applying a non-invertible matrix to the camera transform, then he is clearly up to no good, and we can wash our hands of those bad intentions.
begin/endCamera clauses do not automatically reset the camera transform matrix. That's because we set up a nice default camera transform int setup(), and we expect it to hold through draw(). So we don't reset the camera transform matrix at the top of draw(). That means that an innocuous-looking clause like
beginCamera(); translate(0, 0, 10); endCamera();at the top of draw(), will result in a runaway camera that shoots infinitely out of the screen over time. In order to prevent this, it is necessary to call some function that does a hard reset of the camera transform matrix inside of begin/endCamera. Two options are
camera(); // sets up the nice default camera transform resetMatrix(); // sets up the identity camera transformSo to rotate a camera a constant amount, you might try
beginCamera(); camera(); rotateY(PI/8); endCamera();
beginCamera in class PGraphicspublic void endCamera()
Note that this will destroy any settings to scale(), translate(), or whatever, because the final camera matrix will be copied (not multiplied) into the modelview.
endCamera in class PGraphicspublic void camera()
Processing camera behavior:
Camera behavior can be split into two separate components, camera transformation, and projection. The transformation corresponds to the physical location, orientation, and scale of the camera. In a physical camera metaphor, this is what can manipulated by handling the camera body (with the exception of scale, which doesn't really have a physcial analog). The projection corresponds to what can be changed by manipulating the lens.
We maintain separate matrices to represent the camera transform and projection. An important distinction between the two is that the camera transform should be invertible, where the projection matrix should not, since it serves to map three dimensions to two. It is possible to bake the two matrices into a single one just by multiplying them together, but it isn't a good idea, since lighting, z-ordering, and z-buffering all demand a true camera z coordinate after modelview and camera transforms have been applied but before projection. If the camera transform and projection are combined there is no way to recover a good camera-space z-coordinate from a model coordinate.
Fortunately, there are no functions that manipulate both camera transformation and projection.
camera() sets the camera position, orientation, and center of the scene. It replaces the camera transform with a new one. This is different from gluLookAt(), but I think the only reason that GLU's lookat doesn't fully replace the camera matrix with the new one, but instead multiplies it, is that GL doesn't enforce the separation of camera transform and projection, so it wouldn't be safe (you'd probably stomp your projection).
The transformation functions are the same ones used to manipulate the modelview matrix (scale, translate, rotate, etc.). But they are bracketed with beginCamera(), endCamera() to indicate that they should apply (in inverse), to the camera transformation matrix.
This differs considerably from camera transformation in OpenGL. OpenGL only lets you say, apply everything from here out to the projection or modelview matrix. This makes it very hard to treat camera manipulation as if it were a physical camera. Imagine that you want to move your camera 100 units forward. In OpenGL, you need to apply the inverse of that transformation or else you'll move your scene 100 units forward--whether or not you've specified modelview or projection matrix. Remember they're just multiplied by model coods one after another. So in order to treat a camera like a physical camera, it is necessary to pre-apply inverse transforms to a matrix that will be applied to model coordinates. OpenGL provides nothing of this sort, but Processing does! This is the camera transform matrix.
camera in class PGraphics
public void camera(float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ)
The actual call is like gluLookat. Here's the real skinny on what does what:
camera(); or camera(ex, ey, ez, cx, cy, cz, ux, uy, uz);do not need to be called from with beginCamera();/endCamera(); That's because they always apply to the camera transformation, and they always totally replace it. That means that any coordinate transforms done before camera(); in draw() will be wiped out. It also means that camera() always operates in untransformed world coordinates. Therefore it is always redundant to call resetMatrix(); before camera(); This isn't technically true of gluLookat, but it's pretty much how it's used.
Now, beginCamera(); and endCamera(); are useful if you want to move the camera around using transforms like translate(), etc. They will wipe out any coordinate system transforms that occur before them in draw(), but they will not automatically wipe out the camera transform. This means that they should be at the top of draw(). It also means that the following:
beginCamera(); rotateY(PI/8); endCamera();will result in a camera that spins without stopping. If you want to just rotate a small constant amount, try this:
beginCamera(); camera(); // sets up the default view rotateY(PI/8); endCamera();That will rotate a little off of the default view. Note that this is entirely equivalent to
camera(); // sets up the default view beginCamera(); rotateY(PI/8); endCamera();because camera() doesn't care whether or not it's inside a begin/end clause. Basically it's safe to use camera() or camera(ex, ey, ez, cx, cy, cz, ux, uy, uz) as naked calls because they do all the matrix resetting automatically.
camera in class PGraphicspublic void printCamera()
printCamera in class PGraphicspublic void ortho()
ortho in class PGraphics
public void ortho(float left,
float right,
float bottom,
float top,
float near,
float far)
Implementation partially based on Mesa's matrix.c.
ortho in class PGraphicspublic void perspective()
Projection functions:
This behavior is pretty much familiar from OpenGL, except where functions replace matrices, rather than multiplying against the previous.
perspective in class PGraphics
public void perspective(float fov,
float aspect,
float zNear,
float zFar)
perspective in class PGraphics
public void frustum(float left,
float right,
float bottom,
float top,
float znear,
float zfar)
Implementation based on the explanation in the OpenGL blue book.
frustum in class PGraphicspublic void printProjection()
printProjection in class PGraphics
public float screenX(float x,
float y)
PGraphics
screenX in class PGraphics
public float screenY(float x,
float y)
PGraphics
screenY in class PGraphics
public float screenX(float x,
float y,
float z)
PGraphicsGiven an (x, y, z) coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
screenX in class PGraphics
public float screenY(float x,
float y,
float z)
PGraphicsGiven an (x, y, z) coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
screenY in class PGraphics
public float screenZ(float x,
float y,
float z)
PGraphicsGiven an (x, y, z) coordinate, returns its z value. This value can be used to determine if an (x, y, z) coordinate is in front or in back of another (x, y, z) coordinate. The units are based on how the zbuffer is set up, and don't relate to anything "real". They're only useful for in comparison to another value obtained from screenZ(), or directly out of the zbuffer[].
screenZ in class PGraphics
public float modelX(float x,
float y,
float z)
PGraphicsThis will give you a coordinate after it has been transformed by translate(), rotate(), and camera(), but not yet transformed by the projection matrix. For instance, his can be useful for figuring out how points in 3D space relate to the edge coordinates of a shape.
modelX in class PGraphics
public float modelY(float x,
float y,
float z)
PGraphics
modelY in class PGraphics
public float modelZ(float x,
float y,
float z)
PGraphics
modelZ in class PGraphicspublic void strokeJoin(int join)
strokeJoin in class PGraphicspublic void strokeCap(int cap)
strokeCap in class PGraphicspublic void lights()
The Lighting Skinny:
The way lighting works is complicated enough that it's worth
producing a document to describe it. Lighting calculations proceed
pretty much exactly as described in the OpenGL red book.
Light-affecting material properties:
AMBIENT COLOR
- multiplies by light's ambient component
- for believability this should match diffuse color
DIFFUSE COLOR
- multiplies by light's diffuse component
SPECULAR COLOR
- multiplies by light's specular component
- usually less colored than diffuse/ambient
SHININESS
- the concentration of specular effect
- this should be set pretty high (20-50) to see really
noticeable specularity
EMISSIVE COLOR
- constant additive color effect
Light types:
AMBIENT
- one color
- no specular color
- no direction
- may have falloff (constant, linear, and quadratic)
- may have position (which matters in non-constant falloff case)
- multiplies by a material's ambient reflection
DIRECTIONAL
- has diffuse color
- has specular color
- has direction
- no position
- no falloff
- multiplies by a material's diffuse and specular reflections
POINT
- has diffuse color
- has specular color
- has position
- no direction
- may have falloff (constant, linear, and quadratic)
- multiplies by a material's diffuse and specular reflections
SPOT
- has diffuse color
- has specular color
- has position
- has direction
- has cone angle (set to half the total cone angle)
- has concentration value
- may have falloff (constant, linear, and quadratic)
- multiplies by a material's diffuse and specular reflections
Normal modes:
All of the primitives (rect, box, sphere, etc.) have their normals
set nicely. During beginShape/endShape normals can be set by the user.
AUTO-NORMAL
- if no normal is set during the shape, we are in auto-normal mode
- auto-normal calculates one normal per triangle (face-normal mode)
SHAPE-NORMAL
- if one normal is set during the shape, it will be used for
all vertices
VERTEX-NORMAL
- if multiple normals are set, each normal applies to
subsequent vertices
- (except for the first one, which applies to previous
and subsequent vertices)
Efficiency consequences:
There is a major efficiency consequence of position-dependent
lighting calculations per vertex. (See below for determining
whether lighting is vertex position-dependent.) If there is no
position dependency then the only factors that affect the lighting
contribution per vertex are its colors and its normal.
There is a major efficiency win if
1) lighting is not position dependent
2) we are in AUTO-NORMAL or SHAPE-NORMAL mode
because then we can calculate one lighting contribution per shape
(SHAPE-NORMAL) or per triangle (AUTO-NORMAL) and simply multiply it
into the vertex colors. The converse is our worst-case performance when
1) lighting is position dependent
2) we are in AUTO-NORMAL mode
because then we must calculate lighting per-face * per-vertex.
Each vertex has a different lighting contribution per face in
which it appears. Yuck.
Determining vertex position dependency:
If any of the following factors are TRUE then lighting is
vertex position dependent:
1) Any lights uses non-constant falloff
2) There are any point or spot lights
3) There is a light with specular color AND there is a
material with specular color
So worth noting is that default lighting (a no-falloff ambient
and a directional without specularity) is not position-dependent.
We should capitalize.
Simon Greenwold, April 2005
lights in class PGraphicspublic void noLights()
noLights in class PGraphics
public void ambientLight(float r,
float g,
float b)
ambientLight in class PGraphics
public void ambientLight(float r,
float g,
float b,
float x,
float y,
float z)
ambientLight in class PGraphics
public void directionalLight(float r,
float g,
float b,
float nx,
float ny,
float nz)
directionalLight in class PGraphics
public void pointLight(float r,
float g,
float b,
float x,
float y,
float z)
pointLight in class PGraphics
public void spotLight(float r,
float g,
float b,
float x,
float y,
float z,
float nx,
float ny,
float nz,
float angle,
float concentration)
spotLight in class PGraphics
public void lightFalloff(float constant,
float linear,
float quadratic)
lightFalloff in class PGraphics
public void lightSpecular(float x,
float y,
float z)
lightSpecular in class PGraphicspublic boolean is2D()
PGraphics
is2D in class PGraphicspublic boolean is3D()
PGraphics
is3D in class PGraphics
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||