summaryrefslogtreecommitdiffstats
path: root/cwd/shaders/block.fs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cwd/shaders/block.fs178
1 files changed, 128 insertions, 50 deletions
diff --git a/cwd/shaders/block.fs b/cwd/shaders/block.fs
index dcc78cc..8795fb2 100644
--- a/cwd/shaders/block.fs
+++ b/cwd/shaders/block.fs
@@ -2,58 +2,101 @@
in vec2 UvPosition;
-uniform float time;
-uniform int block;
+uniform int Block;
+uniform int State;
uniform sampler2D textureAtlas;
+uniform float time;
// TextureIndex: [most significant bit]<-...<-side[3bit]<-id[13]<-state[4]
layout(std140) uniform TextureIndexes { // binding point: 0
int totalTextures;
- int indexes[2047];
+ int indexes[1023];
+};
+layout(std140) uniform TextureData { // binding point: 1
+ vec4 textureData[1024];
};
-// layout(std140) uniform TextureData { vec4 textureData[1024]; }; //binding point: 1
-// layout(std140) uniform TextureData2 { vec4 textureData2[1024]; }; //binddingpoint: 2
-vec4 GetTextureByBlockId(int BlockId);
+
+vec4 GetTextureByBlockId();
vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords);
+vec4 CheckIndexValidness();
+vec4 GetDepthColor();
+vec4 GetCheckerColor();
+vec4 VTC(int value);
+
+in vec3 FragmentPosition;
+int GetBlockSide(){
+ int side=6;
+ if (FragmentPosition.y==-0.5)
+ side=0;
+ else if (FragmentPosition.y==0.5)
+ side=1;
+ else if (FragmentPosition.x==-0.5)
+ side = 3;
+ else if (FragmentPosition.x==0.5)
+ side = 2;
+ else if (FragmentPosition.z==-0.5)
+ side=4;
+ else if (FragmentPosition.z==0.5)
+ side=5;
+ return side;
+}
+int index,side,id,state;
+
+vec3 rgb2hsv(vec3 c)
+{
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
+
+ float d = q.x - min(q.w, q.y);
+ float e = 1.0e-10;
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
+}
+
+vec3 hsv2rgb(vec3 c)
+{
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+
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);
+ vec4 BlockTextureCoords = GetTextureByBlockId();
vec2 AtlasCoords = TransformTextureCoord(BlockTextureCoords, UvPosition);
- gl_FragColor = texture(textureAtlas, AtlasCoords);*/
+ gl_FragColor = texture(textureAtlas, AtlasCoords);
+ if (id==2 && side==1) { //Grass colorizing
+ const float BiomeColor = 0.275;
+ vec3 hsvColor = rgb2hsv(gl_FragColor.xyz);
+ hsvColor[0]+=BiomeColor;
+ hsvColor[1]=0.63;
+ hsvColor[2]+=0.1;
+ gl_FragColor = vec4(hsv2rgb(hsvColor),1);
+ }
}
-vec4 GetTextureByBlockId(int BlockId) {
- 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);
+vec4 GetTextureByBlockId() {
+ int BlockSide = GetBlockSide();
+ for (int i = 0; i < totalTextures; i++) {
+ index = indexes[i];
+ side = (index & 0x70000) >> 16;
+ id = (index & 0xFF0) >> 4;
+ state = index & 0xF;
+
+ if (id != Block)
+ continue;
+ if (state != State)
+ continue;
+ if (side == 6)
+ return textureData[i];
+ if (BlockSide == side)
+ return textureData[i];
+ if (side == 6)
+ return textureData[i];
+ else if (side == BlockSide)
+ return textureData[i];
}
- }
- /*
- TNT texture:
- X 0.0546875
- Y ~0.00442477876106194690
- W 0.0078125
- H ~0.00442477876106194690
- */
+ // Fallback TNT texture
return vec4(0.0546875, 0.00442477876106194690, 0.0078125,
0.00442477876106194690);
}
@@ -75,21 +118,56 @@ vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords) {
return A + UvCoords * (B - A);
}
-/*
+vec4 CheckIndexValidness() {
+ vec4 color = vec4(0, 1, 0, 1);
+ if (totalTextures != 6)
+ return vec4(1, 0, 0, 1);
+ if (indexes[0] != 393248)
+ return vec4(1, 1, 0, 1);
+ for (int i = 1; i < 20; i++)
+ if (indexes[i] != 0)
+ return vec4(0, 0, 1, 1);
+ return vec4(0, 1, 0, 1);
+}
float near = 1.0;
-float far = 100.0;
+float far = 100.0;
-float LinearizeDepth(float depth)
-{
- float z = depth * 2.0 - 1.0; // Back to NDC
- return (2.0 * near * far) / (far + near - z * (far - near));
+float LinearizeDepth(float depth) {
+ 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);
-}*/
+vec4 GetDepthColor() {
+ float depth =
+ LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration
+ return vec4(vec3(depth), 1.0f);
+}
+vec4 GetCheckerColor() {
+ if (UvPosition.x>0.5 && UvPosition.y<0.5 || UvPosition.x<0.5 && UvPosition.y>0.5)
+ return vec4(0.7,0.7,0,1);
+ else
+ return vec4(0,0,0,1);
+}
+vec4 VTC(int value){
+ switch(value)
+ {
+ case 0:
+ return vec4(0,0,0,1);
+ case 1:
+ return vec4(1,0,0,1);
+ case 2:
+ return vec4(0,1,0,1);
+ case 3:
+ return vec4(0,0,1,1);
+ case 4:
+ return vec4(1,1,0,1);
+ case 5:
+ return vec4(1,0,1,1);
+ case 6:
+ return vec4(0,1,1,1);
+ }
+ return vec4(1,1,1,1);
+}