mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Fix grid antialiasing
This commit is contained in:
parent
07a5c7bd16
commit
9daefbdb94
4 changed files with 18 additions and 17 deletions
|
@ -81,7 +81,7 @@ void Grid3DOverlay::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const render::ShapeKey Grid3DOverlay::getShapeKey() {
|
const render::ShapeKey Grid3DOverlay::getShapeKey() {
|
||||||
return render::ShapeKey::Builder().withTranslucent();
|
return render::ShapeKey::Builder().withOwnPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
|
|
|
@ -600,9 +600,9 @@ void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, co
|
||||||
gridBuffer.edit<GridSchema>().offset.y = -(majorEdge / majorCols) / 2;
|
gridBuffer.edit<GridSchema>().offset.y = -(majorEdge / majorCols) / 2;
|
||||||
gridBuffer.edit<GridSchema>().offset.z = -(minorEdge / minorRows) / 2;
|
gridBuffer.edit<GridSchema>().offset.z = -(minorEdge / minorRows) / 2;
|
||||||
gridBuffer.edit<GridSchema>().offset.w = -(minorEdge / minorCols) / 2;
|
gridBuffer.edit<GridSchema>().offset.w = -(minorEdge / minorCols) / 2;
|
||||||
gridBuffer.edit<GridSchema>().balance = glm::vec4(glm::vec2(1.0f - majorEdge),
|
gridBuffer.edit<GridSchema>().edge = glm::vec4(glm::vec2(majorEdge),
|
||||||
// If rows or columns are not set, do not draw minor gridlines
|
// If rows or columns are not set, do not draw minor gridlines
|
||||||
glm::vec2((minorRows != 0 && minorCols != 0) ? 1.0f - minorEdge : 0.0f));
|
glm::vec2((minorRows != 0 && minorCols != 0) ? minorEdge : 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the grid pipeline
|
// Set the grid pipeline
|
||||||
|
|
|
@ -322,7 +322,7 @@ private:
|
||||||
// data is arranged as majorRow, majorCol, minorRow, minorCol
|
// data is arranged as majorRow, majorCol, minorRow, minorCol
|
||||||
glm::vec4 period;
|
glm::vec4 period;
|
||||||
glm::vec4 offset;
|
glm::vec4 offset;
|
||||||
glm::vec4 balance;
|
glm::vec4 edge;
|
||||||
};
|
};
|
||||||
using GridBuffer = gpu::BufferView;
|
using GridBuffer = gpu::BufferView;
|
||||||
void useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer);
|
void useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer);
|
||||||
|
|
|
@ -11,36 +11,37 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
float paintStripe(float value, float offset, float scale, float balance) {
|
float paintStripe(float value, float offset, float scale, float edge) {
|
||||||
float width = fwidth(value);
|
float width = fwidth(value);
|
||||||
float normalizedWidth = width * scale;
|
float normalizedWidth = width * scale;
|
||||||
|
|
||||||
float x0 = (value + offset) * scale - normalizedWidth / 2;
|
float x0 = (value + offset) * scale - normalizedWidth / 2;
|
||||||
float x1 = x0 + normalizedWidth;
|
float x1 = x0 + normalizedWidth;
|
||||||
|
|
||||||
float i0 = balance * floor(x0) + max(0.0, fract(x0) - balance);
|
float balance = 1.0 - edge;
|
||||||
float i1 = balance * floor(x1) + max(0.0, fract(x1) - balance);
|
float i0 = edge * floor(x0) + max(0.0, fract(x0) - balance);
|
||||||
|
float i1 = edge * floor(x1) + max(0.0, fract(x1) - balance);
|
||||||
float strip = (i1 - i0) / normalizedWidth;
|
float strip = (i1 - i0) / normalizedWidth;
|
||||||
|
|
||||||
return clamp(strip, 0.0, 1.0);
|
return clamp(strip, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float paintGrid(vec2 value, vec2 offset, vec2 scale, vec2 balance) {
|
float paintGrid(vec2 value, vec2 offset, vec2 scale, vec2 edge) {
|
||||||
return max(
|
return max(
|
||||||
paintStripe(value.x, offset.x, scale.x, balance.x),
|
paintStripe(value.x, offset.x, scale.x, edge.x),
|
||||||
paintStripe(value.y, offset.y, scale.y, balance.y));
|
paintStripe(value.y, offset.y, scale.y, edge.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
float paintGridMajorMinor(vec2 value, vec4 offset, vec4 scale, vec4 balance) {
|
float paintGridMajorMinor(vec2 value, vec4 offset, vec4 scale, vec4 edge) {
|
||||||
return max(
|
return max(
|
||||||
paintGrid(value, offset.xy, scale.xy, balance.xy),
|
paintGrid(value, offset.xy, scale.xy, edge.xy),
|
||||||
paintGrid(value, offset.zw, scale.zw, balance.zw));
|
paintGrid(value, offset.zw, scale.zw, edge.zw));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Grid {
|
struct Grid {
|
||||||
vec4 period;
|
vec4 period;
|
||||||
vec4 offset;
|
vec4 offset;
|
||||||
vec4 balance;
|
vec4 edge;
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform gridBuffer { Grid grid; };
|
uniform gridBuffer { Grid grid; };
|
||||||
|
@ -55,10 +56,10 @@ void main(void) {
|
||||||
Grid grid = getGrid();
|
Grid grid = getGrid();
|
||||||
|
|
||||||
float alpha;
|
float alpha;
|
||||||
if (grid.balance.z == 0.0) {
|
if (grid.edge.z == 0.0) {
|
||||||
alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.balance.xy);
|
alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy);
|
||||||
} else {
|
} else {
|
||||||
alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.balance);
|
alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge);
|
||||||
}
|
}
|
||||||
if (alpha == 0.0) {
|
if (alpha == 0.0) {
|
||||||
discard;
|
discard;
|
||||||
|
|
Loading…
Reference in a new issue