Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gloom: Fetching material texture colors in shaders
- Loading branch information
Showing
6 changed files
with
50 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
doomsday/tests/test_gloom/net.dengine.gloom.pack/shaders/common/material.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef GLOOM_MATERIAL_H | ||
#define GLOOM_MATERIAL_H | ||
|
||
#include "defs.glsl" | ||
#include "miplevel.glsl" | ||
|
||
uniform sampler2D uTextureAtlas[4]; | ||
uniform sampler2D uTextureMetrics; | ||
|
||
struct Metrics { | ||
vec4 uvRect; | ||
vec2 sizeInTexels; | ||
float texelsPerMeter; | ||
vec2 scale; | ||
}; | ||
|
||
Metrics Gloom_TextureMetrics(uint matIndex, int texture) { | ||
Metrics metrics; | ||
int x = texture * 2; | ||
metrics.uvRect = texelFetch(uTextureMetrics, ivec2(x, matIndex), 0); | ||
vec3 texelSize = texelFetch(uTextureMetrics, ivec2(x + 1, matIndex), 0).xyz; | ||
metrics.sizeInTexels = texelSize.xy; | ||
metrics.texelsPerMeter = texelSize.z; | ||
metrics.scale = vec2(metrics.texelsPerMeter) / metrics.sizeInTexels; | ||
return metrics; | ||
} | ||
|
||
vec4 Gloom_FetchTexture(uint matIndex, int texture, vec2 uv) { | ||
Metrics metrics = Gloom_TextureMetrics(matIndex, texture); | ||
vec2 normUV = uv * metrics.scale; | ||
vec2 atlasUV = metrics.uvRect.xy + fract(normUV) * metrics.uvRect.zw; | ||
return textureLod(uTextureAtlas[texture], atlasUV, | ||
mipLevel(normUV, metrics.sizeInTexels.xy) - 0.5); | ||
} | ||
|
||
#endif // GLOOM_MATERIAL_H |
5 changes: 2 additions & 3 deletions
5
doomsday/tests/test_gloom/net.dengine.gloom.pack/shaders/entity_material.fsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
doomsday/tests/test_gloom/net.dengine.gloom.pack/shaders/entity_shadow_dir.fsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#version 330 core | ||
|
||
uniform sampler2D uDiffuseAtlas; | ||
#include "common/material.glsl" | ||
|
||
DENG_VAR vec2 vUV; | ||
|
||
void main(void) { | ||
float alpha = texture(uDiffuseAtlas, vUV).a; | ||
float alpha = texture(uTextureAtlas[Texture_Diffuse], vUV).a; | ||
if (alpha < 0.75) discard; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters