mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +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() {
|
||||
return render::ShapeKey::Builder().withTranslucent();
|
||||
return render::ShapeKey::Builder().withOwnPipeline();
|
||||
}
|
||||
|
||||
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.z = -(minorEdge / minorRows) / 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
|
||||
glm::vec2((minorRows != 0 && minorCols != 0) ? 1.0f - minorEdge : 0.0f));
|
||||
glm::vec2((minorRows != 0 && minorCols != 0) ? minorEdge : 0.0f));
|
||||
}
|
||||
|
||||
// Set the grid pipeline
|
||||
|
|
|
@ -322,7 +322,7 @@ private:
|
|||
// data is arranged as majorRow, majorCol, minorRow, minorCol
|
||||
glm::vec4 period;
|
||||
glm::vec4 offset;
|
||||
glm::vec4 balance;
|
||||
glm::vec4 edge;
|
||||
};
|
||||
using GridBuffer = gpu::BufferView;
|
||||
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
|
||||
//
|
||||
|
||||
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 normalizedWidth = width * scale;
|
||||
|
||||
float x0 = (value + offset) * scale - normalizedWidth / 2;
|
||||
float x1 = x0 + normalizedWidth;
|
||||
|
||||
float i0 = balance * floor(x0) + max(0.0, fract(x0) - balance);
|
||||
float i1 = balance * floor(x1) + max(0.0, fract(x1) - balance);
|
||||
float balance = 1.0 - edge;
|
||||
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;
|
||||
|
||||
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(
|
||||
paintStripe(value.x, offset.x, scale.x, balance.x),
|
||||
paintStripe(value.y, offset.y, scale.y, balance.y));
|
||||
paintStripe(value.x, offset.x, scale.x, edge.x),
|
||||
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(
|
||||
paintGrid(value, offset.xy, scale.xy, balance.xy),
|
||||
paintGrid(value, offset.zw, scale.zw, balance.zw));
|
||||
paintGrid(value, offset.xy, scale.xy, edge.xy),
|
||||
paintGrid(value, offset.zw, scale.zw, edge.zw));
|
||||
}
|
||||
|
||||
struct Grid {
|
||||
vec4 period;
|
||||
vec4 offset;
|
||||
vec4 balance;
|
||||
vec4 edge;
|
||||
};
|
||||
|
||||
uniform gridBuffer { Grid grid; };
|
||||
|
@ -55,10 +56,10 @@ void main(void) {
|
|||
Grid grid = getGrid();
|
||||
|
||||
float alpha;
|
||||
if (grid.balance.z == 0.0) {
|
||||
alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.balance.xy);
|
||||
if (grid.edge.z == 0.0) {
|
||||
alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy);
|
||||
} else {
|
||||
alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.balance);
|
||||
alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge);
|
||||
}
|
||||
if (alpha == 0.0) {
|
||||
discard;
|
||||
|
|
Loading…
Reference in a new issue