diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-31 16:17:09 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-31 16:17:09 +0200 |
commit | f721ed0e3c6be33670fe330c029a2d4c3353f635 (patch) | |
tree | 5afad5a292171d546d9ded16de6151a014883d84 /cwd/shaders | |
parent | 2017-05-28 (diff) | |
download | AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar.gz AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar.bz2 AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar.lz AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar.xz AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.tar.zst AltCraft-f721ed0e3c6be33670fe330c029a2d4c3353f635.zip |
Diffstat (limited to '')
-rw-r--r-- | cwd/shaders/block.fs | 95 | ||||
-rw-r--r-- | cwd/shaders/block.vs | 8 |
2 files changed, 86 insertions, 17 deletions
diff --git a/cwd/shaders/block.fs b/cwd/shaders/block.fs index 4df9b7b..dcc78cc 100644 --- a/cwd/shaders/block.fs +++ b/cwd/shaders/block.fs @@ -1,28 +1,95 @@ #version 330 core -struct TextureCoordData { - int blockId; - int blockState; - int blockSide; - vec4 texture; -}; - in vec2 UvPosition; -uniform sampler2D textureAtlas; +uniform float time; uniform int block; +uniform sampler2D textureAtlas; + +// TextureIndex: [most significant bit]<-...<-side[3bit]<-id[13]<-state[4] +layout(std140) uniform TextureIndexes { // binding point: 0 + int totalTextures; + int indexes[2047]; +}; +// layout(std140) uniform TextureData { vec4 textureData[1024]; }; //binding point: 1 +// layout(std140) uniform TextureData2 { vec4 textureData2[1024]; }; //binddingpoint: 2 +vec4 GetTextureByBlockId(int BlockId); +vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords); + +void main() { +vec4 bad = vec4(1,0,0,1); + vec4 color = vec4(0,1,0,1); + if (totalTextures!=6) + color = bad; + if (indexes[0]!=393248) + color = bad; + for (int i=1;i<2047;i++) + if (indexes[i]!=0) + color=bad; + gl_FragColor = color; + /*vec4 BlockTextureCoords = GetTextureByBlockId(block); + vec2 AtlasCoords = TransformTextureCoord(BlockTextureCoords, UvPosition); + gl_FragColor = texture(textureAtlas, AtlasCoords);*/ +} vec4 GetTextureByBlockId(int BlockId) { - return vec4(0,0,0,0); + if (indexes[0] == 0) + return vec4(0.05, 0.004, 0.007, 0.004); + + if (totalTextures == 0) + return vec4(0, 0, 0.1, 0.1); + for (int i = 0; i < totalTextures; i++) { + int index = indexes[i + 1]; + int side = (index & 0xE0000) >> 16; + int id = (index & 0xFF0) >> 4; + int state = index & 0xF; + if (id == BlockId) { + return vec4(i, 0, 1, 1); + } + } + /* + TNT texture: + X 0.0546875 + Y ~0.00442477876106194690 + W 0.0078125 + H ~0.00442477876106194690 + */ + return vec4(0.0546875, 0.00442477876106194690, 0.0078125, + 0.00442477876106194690); } -vec4 TransformTextureCoord(vec4 TextureAtlasCoords){ - return vec4(0,0,0,0); +vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords) { + float x = TextureAtlasCoords.x; + float y = TextureAtlasCoords.y; + float w = TextureAtlasCoords.z; + float h = TextureAtlasCoords.w; + vec2 A = vec2(x, y); + vec2 B = vec2(x + w, y + h); + + const bool isTextureFlippedVertically = true; + if (isTextureFlippedVertically) { + y = 1 - y; + A = vec2(x, y - h); + B = vec2(x + w, y); + } + return A + UvCoords * (B - A); } -void main() +/* + +float near = 1.0; +float far = 100.0; + +float LinearizeDepth(float depth) { - vec4 TextureCoords = GetTextureByBlockId(block); - gl_FragColor = texture(textureAtlas,UvPosition); + float z = depth * 2.0 - 1.0; // Back to NDC + return (2.0 * near * far) / (far + near - z * (far - near)); } +void main() +{ + float depth = LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration + gl_FragColor = vec4(vec3(depth), 1.0f); +}*/ + + diff --git a/cwd/shaders/block.vs b/cwd/shaders/block.vs index 7a36a5d..09d5b3f 100644 --- a/cwd/shaders/block.vs +++ b/cwd/shaders/block.vs @@ -4,12 +4,14 @@ layout (location = 2) in vec2 UvCoordinates; out vec2 UvPosition; + +uniform mat4 view; +uniform mat4 projection; +uniform float time; uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(position, 1.0f); UvPosition = vec2(UvCoordinates.x,UvCoordinates.y); -}
\ No newline at end of file +} |