mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
perspective correction can be disabled/enabled for points
This commit is contained in:
@@ -510,40 +510,40 @@ public interface PConstants {
|
||||
// hints - hint values are positive for the alternate version,
|
||||
// negative of the same value returns to the normal/default state
|
||||
|
||||
static final int ENABLE_NATIVE_FONTS = 1;
|
||||
static final int DISABLE_NATIVE_FONTS = -1;
|
||||
static final int ENABLE_NATIVE_FONTS = 1;
|
||||
static final int DISABLE_NATIVE_FONTS = -1;
|
||||
|
||||
static final int DISABLE_DEPTH_TEST = 2;
|
||||
static final int ENABLE_DEPTH_TEST = -2;
|
||||
static final int DISABLE_DEPTH_TEST = 2;
|
||||
static final int ENABLE_DEPTH_TEST = -2;
|
||||
|
||||
static final int ENABLE_DEPTH_SORT = 3;
|
||||
static final int DISABLE_DEPTH_SORT = -3;
|
||||
static final int ENABLE_DEPTH_SORT = 3;
|
||||
static final int DISABLE_DEPTH_SORT = -3;
|
||||
|
||||
static final int DISABLE_OPENGL_ERROR_REPORT = 4;
|
||||
static final int ENABLE_OPENGL_ERROR_REPORT = -4;
|
||||
static final int DISABLE_OPENGL_ERROR_REPORT = 4;
|
||||
static final int ENABLE_OPENGL_ERROR_REPORT = -4;
|
||||
|
||||
static final int ENABLE_ACCURATE_TEXTURES = 5;
|
||||
static final int DISABLE_ACCURATE_TEXTURES = -5;
|
||||
static final int ENABLE_ACCURATE_TEXTURES = 5;
|
||||
static final int DISABLE_ACCURATE_TEXTURES = -5;
|
||||
|
||||
static final int DISABLE_DEPTH_MASK = 6;
|
||||
static final int ENABLE_DEPTH_MASK = -6;
|
||||
static final int DISABLE_DEPTH_MASK = 6;
|
||||
static final int ENABLE_DEPTH_MASK = -6;
|
||||
|
||||
static final int ENABLE_ACCURATE_2D = 7;
|
||||
static final int DISABLE_ACCURATE_2D = -7;
|
||||
static final int ENABLE_ACCURATE_2D = 7;
|
||||
static final int DISABLE_ACCURATE_2D = -7;
|
||||
|
||||
static final int DISABLE_TEXTURE_CACHE = 8;
|
||||
static final int ENABLE_TEXTURE_CACHE = -8;
|
||||
static final int DISABLE_TEXTURE_CACHE = 8;
|
||||
static final int ENABLE_TEXTURE_CACHE = -8;
|
||||
|
||||
static final int DISABLE_TRANSFORM_CACHE = 9;
|
||||
static final int ENABLE_TRANSFORM_CACHE = -9;
|
||||
static final int DISABLE_TRANSFORM_CACHE = 9;
|
||||
static final int ENABLE_TRANSFORM_CACHE = -9;
|
||||
|
||||
static final int ENABLE_PERSPECTIVE_CORRECTED_LINES = 10;
|
||||
static final int DISABLE_PERSPECTIVE_CORRECTED_LINES = -10;
|
||||
static final int ENABLE_PERSPECTIVE_CORRECTED_STROKE = 10;
|
||||
static final int DISABLE_PERSPECTIVE_CORRECTED_STROKE = -10;
|
||||
|
||||
static final int DISABLE_TEXTURE_MIPMAPS = 11;
|
||||
static final int ENABLE_TEXTURE_MIPMAPS = -11;
|
||||
static final int DISABLE_TEXTURE_MIPMAPS = 11;
|
||||
static final int ENABLE_TEXTURE_MIPMAPS = -11;
|
||||
|
||||
static final int HINT_COUNT = 12;
|
||||
static final int HINT_COUNT = 12;
|
||||
|
||||
// error messages
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
|
||||
|
||||
public PGraphics2D() {
|
||||
super();
|
||||
hints[ENABLE_PERSPECTIVE_CORRECTED_LINES] = false;
|
||||
hints[ENABLE_PERSPECTIVE_CORRECTED_STROKE] = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
|
||||
|
||||
|
||||
public void hint(int which) {
|
||||
if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES) {
|
||||
if (which == ENABLE_PERSPECTIVE_CORRECTED_STROKE) {
|
||||
showWarning("2D lines cannot be perspective-corrected.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ import processing.core.PVector;
|
||||
|
||||
public class PGraphics3D extends PGraphicsOpenGL {
|
||||
|
||||
public PGraphics3D() {
|
||||
super();
|
||||
hints[ENABLE_PERSPECTIVE_CORRECTED_STROKE] = true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// RENDERER SUPPORT QUERIES
|
||||
|
||||
@@ -2093,12 +2093,12 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
setFlushMode(FLUSH_CONTINUOUSLY);
|
||||
} else if (which == DISABLE_TEXTURE_CACHE) {
|
||||
flush();
|
||||
} else if (which == DISABLE_PERSPECTIVE_CORRECTED_LINES) {
|
||||
} else if (which == DISABLE_PERSPECTIVE_CORRECTED_STROKE) {
|
||||
if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
|
||||
// We flush the geometry using the previous line setting.
|
||||
flush();
|
||||
}
|
||||
} else if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES) {
|
||||
} else if (which == ENABLE_PERSPECTIVE_CORRECTED_STROKE) {
|
||||
if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
|
||||
// We flush the geometry using the previous line setting.
|
||||
flush();
|
||||
@@ -5447,9 +5447,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
if (maskShader == null) {
|
||||
maskShader = new PolyTexShader(parent,
|
||||
defPolyTexShaderVertURL,
|
||||
maskShaderFragURL);
|
||||
maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL,
|
||||
maskShaderFragURL);
|
||||
}
|
||||
maskShader.set("maskSampler", alpha);
|
||||
filter(maskShader);
|
||||
@@ -6846,7 +6845,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
float h = pgCurrent.viewport[3];
|
||||
setUniformValue(viewportLoc, x, y, w, h);
|
||||
|
||||
if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_LINES)) {
|
||||
if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_STROKE)) {
|
||||
setUniformValue(perspectiveLoc, 1);
|
||||
} else {
|
||||
setUniformValue(perspectiveLoc, 0);
|
||||
@@ -6880,6 +6879,9 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
protected int modelviewMatrixLoc;
|
||||
protected int projectionMatrixLoc;
|
||||
|
||||
protected int viewportLoc;
|
||||
protected int perspectiveLoc;
|
||||
|
||||
protected int inVertexLoc;
|
||||
protected int inColorLoc;
|
||||
protected int inPointLoc;
|
||||
@@ -6907,6 +6909,9 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
|
||||
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
|
||||
projectionMatrixLoc = getUniformLoc("projectionMatrix");
|
||||
|
||||
viewportLoc = getUniformLoc("viewport");
|
||||
perspectiveLoc = getUniformLoc("perspective");
|
||||
}
|
||||
|
||||
public void setVertexAttribute(int vboId, int size, int type,
|
||||
@@ -6950,6 +6955,18 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
pgCurrent.updateGLProjection();
|
||||
setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection);
|
||||
}
|
||||
|
||||
float x = pgCurrent.viewport[0];
|
||||
float y = pgCurrent.viewport[1];
|
||||
float w = pgCurrent.viewport[2];
|
||||
float h = pgCurrent.viewport[3];
|
||||
setUniformValue(viewportLoc, x, y, w, h);
|
||||
|
||||
if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_STROKE)) {
|
||||
setUniformValue(perspectiveLoc, 1);
|
||||
} else {
|
||||
setUniformValue(perspectiveLoc, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
|
||||
@@ -21,16 +21,33 @@
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 modelviewMatrix;
|
||||
|
||||
uniform vec4 viewport;
|
||||
uniform int perspective;
|
||||
|
||||
attribute vec4 inVertex;
|
||||
attribute vec4 inColor;
|
||||
attribute vec2 inPoint;
|
||||
|
||||
varying vec4 vertColor;
|
||||
|
||||
vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) {
|
||||
vec2 xypos = (window / viewport.zw) * 2.0;
|
||||
return vec4(xypos, 0.0, 0.0) * clip_w;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 pos = modelviewMatrix * inVertex;
|
||||
pos.xy += inPoint.xy;
|
||||
gl_Position = projectionMatrix * pos;
|
||||
vec4 clip = projectionMatrix * pos;
|
||||
|
||||
if (0 < perspective) {
|
||||
// Perspective correction (points will look thiner as they move away
|
||||
// from the view position).
|
||||
gl_Position = clip + projectionMatrix * vec4(inPoint.xy, 0, 0);
|
||||
} else {
|
||||
// No perspective correction.
|
||||
vec4 offset = windowToClipVector(inPoint.xy, viewport, clip.w);
|
||||
gl_Position = clip + offset;
|
||||
}
|
||||
|
||||
vertColor = inColor;
|
||||
}
|
||||
Reference in New Issue
Block a user