Skip to content

Commit

Permalink
Gloom: Entity shaders in separate files; texture scale in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 6db9b09 commit 2669882
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 155 deletions.
10 changes: 6 additions & 4 deletions doomsday/tests/test_gloom/gloom/render/maprender.cpp
Expand Up @@ -52,7 +52,7 @@ DENG2_PIMPL(MapRender)
DataBuffer<float> planes {"uPlanes", Image::R_32f};
DataBuffer<TexOffsetData> texOffsets {"uTexOffsets", Image::RGBA_32f};

GLUniform uTexelsPerMeter{"uTexelsPerMeter", GLUniform::Float};
//GLUniform uTexelsPerMeter{"uTexelsPerMeter", GLUniform::Float};
Drawable surfaces;
GLProgram dirShadowProgram;
GLProgram omniShadowProgram;
Expand All @@ -79,13 +79,15 @@ DENG2_PIMPL(MapRender)
textureMetrics.clear();
textures.clear();

const float texelsPerMeter = 200.f;

for (auto i = loadedTextures.begin(); i != loadedTextures.end(); ++i)
{
// Load up metrics in an array.
const Rectanglei rect = self().context().atlas->imageRect(i.value());
const Rectanglef rectf = self().context().atlas->imageRectf(i.value());
const uint32_t texId = textureMetrics.append(
Metrics{{rectf.xywh()}, {Vec4f(rect.width(), rect.height())}});
Metrics{{rectf.xywh()}, {Vec4f(rect.width(), rect.height(), texelsPerMeter)}});
textures.insert(i.key(), texId);
}

Expand Down Expand Up @@ -124,7 +126,7 @@ DENG2_PIMPL(MapRender)

context.shaders->build(surfaces.program(), "gloom.surface.material")
<< planes.var
<< uTexelsPerMeter
//<< uTexelsPerMeter
<< textureMetrics.var
<< texOffsets.var;

Expand All @@ -149,7 +151,7 @@ DENG2_PIMPL(MapRender)
ents .glInit(self().context());
lights.glInit(self().context());

uTexelsPerMeter = 200;
// uTexelsPerMeter = 200;

// Load some textures.
for (const char *name :
Expand Down

This file was deleted.

@@ -1,5 +1,5 @@
#ifndef GLOOM_PLANES_H
#define GLOOM_PLANES_H
#ifndef GLOOM_SURFACE_H
#define GLOOM_SURFACE_H

uniform sampler2D uPlanes;

Expand Down Expand Up @@ -27,7 +27,7 @@ float Gloom_FetchPlaneY(uint planeIndex) {

Surface Gloom_LoadVertexSurface(void) {
Surface surface;

surface.flags = floatBitsToUint(aFlags);
surface.vertex = aVertex;

Expand All @@ -46,4 +46,4 @@ Surface Gloom_LoadVertexSurface(void) {
return surface;
}

#endif // GLOOM_PLANES_H
#endif // GLOOM_SURFACE_H
108 changes: 0 additions & 108 deletions doomsday/tests/test_gloom/net.dengine.gloom.pack/shaders/entity.dei

This file was deleted.

@@ -0,0 +1,16 @@
#version 330 core

#include "common/gbuffer_out.glsl"

uniform sampler2D uTex;

DENG_VAR vec2 vUV;
DENG_VAR vec4 vInstanceColor;
DENG_VAR vec3 vNormal;

void main(void) {
vec4 color = texture(uTex, vUV);
if (color.a < 0.5) discard;
out_FragColor = color * vInstanceColor;
GBuffer_SetFragNormal(vNormal);
}
@@ -0,0 +1,26 @@
#version 330 core

#include "common/bones.glsl"

uniform mat4 uMvpMatrix;

DENG_ATTRIB mat4 aInstanceMatrix;
DENG_ATTRIB vec4 aInstanceColor;

DENG_ATTRIB vec4 aVertex;
DENG_ATTRIB vec3 aNormal;
DENG_ATTRIB vec2 aUV;
DENG_ATTRIB vec4 aBounds0;

DENG_VAR vec2 vUV;
DENG_VAR vec4 vInstanceColor;
DENG_VAR vec3 vNormal;

void main(void) {
vNormal = aNormal;
vec4 modelPos = Gloom_BoneTransform(aVertex, vNormal);
gl_Position = uMvpMatrix * (aInstanceMatrix * modelPos);
vNormal = (aInstanceMatrix * vec4(vNormal, 0.0)).xyz;
vUV = aBounds0.xy + aUV * aBounds0.zw;
vInstanceColor = aInstanceColor;
}
@@ -0,0 +1,10 @@
#version 330 core

uniform sampler2D uTex;

DENG_VAR vec2 vUV;

void main(void) {
float alpha = texture(uTex, vUV).a;
if (alpha < 0.75) discard;
}
@@ -0,0 +1,19 @@
#version 330 core

#include "common/bones.glsl"

uniform mat4 uLightMatrix;

DENG_ATTRIB mat4 aInstanceMatrix;
DENG_ATTRIB vec4 aInstanceColor;
DENG_ATTRIB vec4 aVertex;
DENG_ATTRIB vec2 aUV;
DENG_ATTRIB vec4 aBounds0;

DENG_VAR vec2 vUV;

void main(void) {
mat4 bone = Gloom_BoneMatrix();
gl_Position = uLightMatrix * (aInstanceMatrix * (bone * aVertex));
vUV = aBounds0.xy + aUV * aBounds0.zw;
}
@@ -0,0 +1,17 @@
#version 330 core

uniform sampler2D uTex;

uniform vec3 uLightOrigin; // world space
uniform float uFarPlane;

in vec4 vWorldPos;
in vec2 vFaceUV;

void main(void) {
float alpha = texture(uTex, vFaceUV).a;
if (alpha < 0.75) discard;

// Normalized distance.
gl_FragDepth = distance(vWorldPos.xyz, uLightOrigin) / uFarPlane;
}
@@ -0,0 +1,17 @@
#version 330 core

#include "common/bones.glsl"

in mat4 aInstanceMatrix;
in vec4 aInstanceColor;
in vec4 aVertex;
in vec2 aUV;
in vec4 aBounds0;

out vec2 vUV;

void main(void) {
mat4 bone = Gloom_BoneMatrix();
gl_Position = aInstanceMatrix * (bone * aVertex);
vUV = aBounds0.xy + aUV * aBounds0.zw;
}
39 changes: 33 additions & 6 deletions doomsday/tests/test_gloom/net.dengine.gloom.pack/shaders/gloom.dei
@@ -1,18 +1,47 @@
# Gloom Renderer Shaders
#
# - sky
# - surface
# - entity
# - light
# - ssao
# - tonemap

group gloom {
shader sky { path = "sky" }
shader sky { path = "sky" }

group surface {
shader material { path = "surface_material" }
shader shadow.dir { path = "surface_shadow_dir" }
shader material {
path = "surface_material"
}
shader shadow.dir {
path = "surface_shadow_dir"
}
shader shadow.omni {
path.vertex = "surface_shadow_omni.vsh"
path.geometry = "common/cube_faces.gsh"
path.fragment = "surface_shadow_omni.fsh"
}
}

group entity {
shader material {
path = "entity_material"
}
shader shadow.dir {
path = "entity_shadow_dir"
}
shader shadow.omni {
path.vertex = "entity_shadow_omni.vsh"
path.geometry = "common/cube_faces_uv.gsh"
path.fragment = "entity_shadow_omni.fsh"
}
}

group light {
shader global { path = "light_gi" }
shader global {
path = "light_global"
}
shader stencil {
path.vertex = "light_sources.vsh"
fragment = "void main(void) {}"
Expand Down Expand Up @@ -44,5 +73,3 @@ group gloom {
}
}
}

@include <entity.dei>
Expand Up @@ -5,19 +5,20 @@

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

DENG_VAR vec2 vUV;
DENG_VAR vec3 vNormal;
flat DENG_VAR float vTexture;
flat DENG_VAR float vMaterial;
flat DENG_VAR uint vFlags;

void main(void) {
uint texIndex = uint(vTexture + 0.5);
uint matIndex = uint(vMaterial + 0.5);

vec4 uvRect = texelFetch(uTextureMetrics, ivec2(0, texIndex), 0);
vec4 texelSize = texelFetch(uTextureMetrics, ivec2(1, texIndex), 0);
vec2 texScale = vec2(uTexelsPerMeter) / texelSize.xy;
// Albedo color.
vec4 uvRect = texelFetch(uTextureMetrics, ivec2(0, matIndex), 0);
vec3 texelSize = texelFetch(uTextureMetrics, ivec2(1, matIndex), 0).xyz;
float texelsPerMeter = texelSize.z;
vec2 texScale = vec2(texelsPerMeter) / texelSize.xy;

vec2 normUV = vUV * texScale;
vec2 uv = uvRect.xy + fract(normUV) * uvRect.zw;
Expand Down

0 comments on commit 2669882

Please sign in to comment.