Skip to content

Commit

Permalink
Gloom: Added a texels-per-meter scale
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 1626ab4 commit 5d58f81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
12 changes: 7 additions & 5 deletions doomsday/tests/test_gloom/gloom/render/mapgeom.cpp
Expand Up @@ -16,19 +16,19 @@ DENG2_PIMPL(MapGeom)
AtlasTexture *atlas = nullptr;
MapBuild::TextureIds textures;

GLTexture metricsBuf;
QHash<String, Id> loadedTextures;
QHash<String, Id> loadedTextures; // name => atlas ID
GLTexture metricsBuf; // array of metrics for use in shader
struct Metrics {
Vector4f uvRect;
Vector4f texelSize;
};
QVector<Metrics> textureMetrics;
QVector<Metrics> textureMetrics; // contents for metricsBuf

Drawable mapDrawable;
GLUniform uMvpMatrix {"uMvpMatrix", GLUniform::Mat4};
GLUniform uTex {"uTex", GLUniform::Sampler2D};
GLUniform uTextureMetrics {"uTextureMetrics", GLUniform::Sampler2D};
//GLUniform uColor {"uColor", GLUniform::Vec4};
GLUniform uTexelsPerMeter {"uTexelsPerMeter", GLUniform::Float};

Impl(Public *i) : Base(i)
{}
Expand Down Expand Up @@ -76,6 +76,8 @@ DENG2_PIMPL(MapGeom)
{
//uColor = Vector4f(1, 1, 1, 1);

uTexelsPerMeter = 200;

// Load some textures.
{

Expand All @@ -102,7 +104,7 @@ DENG2_PIMPL(MapGeom)
mapDrawable.addBuffer(buf);

GloomApp::shaders().build(mapDrawable.program(), "gloom.surface")
<< uMvpMatrix << uTex << uTextureMetrics;
<< uMvpMatrix << uTex << uTextureMetrics << uTexelsPerMeter;
}

void glDeinit()
Expand Down
Expand Up @@ -4,17 +4,22 @@

uniform sampler2D uTex;
uniform sampler2D uTextureMetrics;
uniform float uTexelsPerMeter;

DENG_VAR highp vec2 vUV;
DENG_VAR highp vec3 vNormal;
DENG_VAR vec2 vUV;
DENG_VAR vec3 vNormal;
flat DENG_VAR uint vTexture;

void main(void) {
highp vec4 uvRect = texelFetch(uTextureMetrics, ivec2(0, vTexture), 0);
highp vec4 texelSize = texelFetch(uTextureMetrics, ivec2(1, vTexture), 0);
vec4 uvRect = texelFetch(uTextureMetrics, ivec2(0, vTexture), 0);
vec4 texelSize = texelFetch(uTextureMetrics, ivec2(1, vTexture), 0);
float texScale = uTexelsPerMeter / texelSize.x;

highp vec2 uv = uvRect.xy + fract(vUV) * uvRect.zw;
highp vec4 color = textureLod(uTex, uv, mipLevel(vUV, texelSize.xy) - 0.5);
vec2 normUV = vUV * texScale;
vec2 uv = uvRect.xy + fract(normUV) * uvRect.zw;

vec4 color = textureLod(uTex, uv, mipLevel(normUV, texelSize.xy) - 0.5);
if (color.a < 0.005) discard;

out_FragColor = color;
}
@@ -1,12 +1,12 @@
uniform highp mat4 uMvpMatrix;
uniform mat4 uMvpMatrix;

DENG_ATTRIB highp vec4 aVertex;
DENG_ATTRIB highp vec2 aUV;
DENG_ATTRIB highp vec3 aNormal;
DENG_ATTRIB highp uint aTexture;
DENG_ATTRIB vec4 aVertex;
DENG_ATTRIB vec2 aUV;
DENG_ATTRIB vec3 aNormal;
DENG_ATTRIB uint aTexture;

DENG_VAR highp vec2 vUV;
DENG_VAR highp vec3 vNormal;
DENG_VAR vec2 vUV;
DENG_VAR vec3 vNormal;
flat DENG_VAR uint vTexture;

void main(void) {
Expand Down

0 comments on commit 5d58f81

Please sign in to comment.