From 94006e599c8d591096b768d1cd0c8b75eb763c45 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 17 Sep 2017 20:50:36 +0500 Subject: 2017-09-17 --- cwd/shaders/block.fs | 179 -------------------------------------------------- cwd/shaders/block.gs | 32 --------- cwd/shaders/block.vs | 31 --------- cwd/shaders/face.fs | 9 +-- cwd/shaders/face.vs | 11 ++-- cwd/shaders/gui.fs | 21 ------ cwd/shaders/gui.vs | 27 -------- cwd/shaders/simple.fs | 7 -- cwd/shaders/simple.vs | 9 --- 9 files changed, 11 insertions(+), 315 deletions(-) delete mode 100644 cwd/shaders/block.fs delete mode 100644 cwd/shaders/block.gs delete mode 100644 cwd/shaders/block.vs delete mode 100644 cwd/shaders/gui.fs delete mode 100644 cwd/shaders/gui.vs delete mode 100644 cwd/shaders/simple.fs delete mode 100644 cwd/shaders/simple.vs (limited to 'cwd') diff --git a/cwd/shaders/block.fs b/cwd/shaders/block.fs deleted file mode 100644 index 15fd217..0000000 --- a/cwd/shaders/block.fs +++ /dev/null @@ -1,179 +0,0 @@ -#version 330 core - -in VS_OUT { - vec2 UvPosition; - vec3 FragmentPosition; - flat int Block; - flat int State; - vec4 ndcPos; -} fs_in; - -uniform sampler2D textureAtlas; -uniform float time; -uniform int isInside; -uniform vec2 windowSize; - -// TextureIndex: [most significant bit]<-...<-side[3bit]<-id[13]<-state[4] -layout(std140) uniform TextureIndexes { // binding point: 0 - int totalTextures; - int indexes[1023]; -}; -layout(std140) uniform TextureData { // binding point: 1 - vec4 textureData[1024]; -}; - -vec4 GetTextureByBlockId(); -vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords); -vec4 CheckIndexValidness(); -vec4 GetDepthColor(); -vec4 GetCheckerColor(); -vec4 VTC(int value); - -int GetBlockSide(){ - int side=6; - if (fs_in.FragmentPosition.y==-0.5) - side=0; - else if (fs_in.FragmentPosition.y==0.5) - side=1; - else if (fs_in.FragmentPosition.x==-0.5) - side = 3; - else if (fs_in.FragmentPosition.x==0.5) - side = 2; - else if (fs_in.FragmentPosition.z==-0.5) - side=4; - else if (fs_in.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 BlockTextureCoords = GetTextureByBlockId(); - vec2 AtlasCoords = TransformTextureCoord(BlockTextureCoords, fs_in.UvPosition); - gl_FragColor = texture(textureAtlas, AtlasCoords); - if (gl_FragColor.a<0.1) discard; - if (fs_in.Block==2 && side==1 || fs_in.Block==18 || fs_in.Block==31 && state==1 || fs_in.Block==31 && state==2) { //Grass and leaves 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 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 != fs_in.Block) - continue; - if (state != fs_in.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]; - } - // Fallback TNT texture - return vec4(0.0546875, 0.00442477876106194690, 0.0078125, - 0.00442477876106194690); -} - -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); -} - -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 LinearizeDepth(float depth) { - float z = depth * 2.0 - 1.0; // Back to NDC - return (2.0 * near * far) / (far + near - z * (far - near)); -} - -vec4 GetDepthColor() { - float depth = - LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration - return vec4(vec3(depth), 1.0f); -} - -vec4 GetCheckerColor() { - if (fs_in.UvPosition.x>0.5 && fs_in.UvPosition.y<0.5 || fs_in.UvPosition.x<0.5 && fs_in.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); -} diff --git a/cwd/shaders/block.gs b/cwd/shaders/block.gs deleted file mode 100644 index 17d61c3..0000000 --- a/cwd/shaders/block.gs +++ /dev/null @@ -1,32 +0,0 @@ -#version 330 core - -in gl_Vertex -{ - vec4 gl_Position; - float gl_PointSize; - float gl_ClipDistance[]; -} gl_in[]; - -in VS_OUT { - vec2 UvPosition; - vec3 FragmentPosition; - flat int Block; - flat int State; - vec4 ndcPos; -} gs_in[]; - -out GS_OUT { - vec2 UvPosition; - vec3 FragmentPosition; - flat int Block; - flat int State; - vec4 ndcPos; -} gs_out[]; - -void main() { - gs_out[0].UvPosition = gs_in[0].UvPosition; - gs_out[0].FragmentPosition = gs_in[0].FragmentPosition; - gs_out[0].Block = gs_in[0].Block; - gs_out[0].State = gs_in[0].State; - gs_out[0].ndcPos = gs_in[0].ndcPos; -} \ No newline at end of file diff --git a/cwd/shaders/block.vs b/cwd/shaders/block.vs deleted file mode 100644 index 457d5dd..0000000 --- a/cwd/shaders/block.vs +++ /dev/null @@ -1,31 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 position; -layout (location = 2) in vec2 UvCoordinates; -layout (location = 7) in vec2 BlockId; -layout (location = 8) in mat4 model; -//layout (location = 12) in something.... - -out VS_OUT { - vec2 UvPosition; - vec3 FragmentPosition; - flat int Block; - flat int State; - vec4 ndcPos; -} vs_out; - -uniform mat4 view; -uniform mat4 projection; -uniform float time; - -void main() -{ - vs_out.UvPosition = vec2(UvCoordinates.x,UvCoordinates.y); - vs_out.FragmentPosition = position; - vs_out.Block = int(BlockId.x); - vs_out.State = int(BlockId.y); - - vec4 sourcePosition = vec4(position,1.0f); - vs_out.ndcPos = (projection*view*model) * sourcePosition; - gl_Position = projection * view * model * sourcePosition; - -} diff --git a/cwd/shaders/face.fs b/cwd/shaders/face.fs index aa45997..ae2eb56 100644 --- a/cwd/shaders/face.fs +++ b/cwd/shaders/face.fs @@ -2,9 +2,10 @@ in VS_OUT { vec2 UvPosition; - vec4 Texture; - vec3 Color; - vec2 Light; + flat vec4 Texture; + flat vec3 Color; + flat vec2 Light; + flat int Face; } fs_in; uniform sampler2D textureAtlas; @@ -47,4 +48,4 @@ void main() { gl_FragColor = vec4(hsv2rgb(hsvColor),1); //float faceLight = clamp((fs_in.Light.x + fs_in.Light.y) / 15.0,0.2,1.0); //gl_FragColor = vec4(gl_FragColor.rgb * faceLight,gl_FragColor.a); -} \ No newline at end of file +} diff --git a/cwd/shaders/face.vs b/cwd/shaders/face.vs index 9bf2639..4cf4e75 100644 --- a/cwd/shaders/face.vs +++ b/cwd/shaders/face.vs @@ -2,15 +2,15 @@ layout (location = 0) in vec3 position; layout (location = 2) in vec2 UvCoordinates; layout (location = 7) in vec4 Texture; -layout (location = 8) in mat4 model; layout (location = 12) in vec3 color; layout (location = 13) in vec2 light; out VS_OUT { vec2 UvPosition; - vec4 Texture; - vec3 Color; - vec2 Light; + flat vec4 Texture; + flat vec3 Color; + flat vec2 Light; + flat int Face; } vs_out; uniform mat4 view; @@ -19,10 +19,11 @@ uniform mat4 projection; void main() { vec4 sourcePosition = vec4(position,1.0f); - gl_Position = projection * view * model * sourcePosition; + gl_Position = projection * view * sourcePosition; vs_out.UvPosition = vec2(UvCoordinates.x,UvCoordinates.y); vs_out.Texture = Texture; vs_out.Color = color; vs_out.Light = light; + vs_out.Face = gl_VertexID / 6; } diff --git a/cwd/shaders/gui.fs b/cwd/shaders/gui.fs deleted file mode 100644 index 95196b9..0000000 --- a/cwd/shaders/gui.fs +++ /dev/null @@ -1,21 +0,0 @@ -#version 330 core - -in vec2 uv; - -uniform vec4 widgetTexture; -uniform sampler2D textureAtlas; - -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, 1 - y - h); - vec2 B = vec2(x + w, 1 - y); - return A + UvCoords * (B - A); -} - -void main(){ - vec4 color = texture(textureAtlas,TransformTextureCoord(widgetTexture,uv)); - gl_FragColor = color; -} \ No newline at end of file diff --git a/cwd/shaders/gui.vs b/cwd/shaders/gui.vs deleted file mode 100644 index b6f848b..0000000 --- a/cwd/shaders/gui.vs +++ /dev/null @@ -1,27 +0,0 @@ -#version 330 core - -uniform vec4 transform; - -layout (location = 0) in vec3 position; -layout (location = 1) in vec2 UvCoordinates; - -out vec2 uv; - -vec2 TransfromWidgetCoord() { - vec2 origin = vec2((transform.x * 2.0f) - 1.0f, (0.5 - transform.y) * 2.0f); - - float x = transform.x; - float y = transform.y; - float w = transform.z; - float h = transform.w; - vec2 A = vec2(x, 1 - y - h); - vec2 B = vec2(x + w, 1 - y); - vec2 ret = vec2(A + position.xy * (B - A)); - return vec2(ret.x-1.0f,ret.y); -} - -void main(){ - uv = UvCoordinates; - - gl_Position = vec4(TransfromWidgetCoord(),0,1); -} \ No newline at end of file diff --git a/cwd/shaders/simple.fs b/cwd/shaders/simple.fs deleted file mode 100644 index 34cc192..0000000 --- a/cwd/shaders/simple.fs +++ /dev/null @@ -1,7 +0,0 @@ -#version 330 core - -uniform vec3 color; - -void main(){ - gl_FragColor = vec4(color,1); -} \ No newline at end of file diff --git a/cwd/shaders/simple.vs b/cwd/shaders/simple.vs deleted file mode 100644 index 8c9f37f..0000000 --- a/cwd/shaders/simple.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 core - -uniform mat4 view; -uniform mat4 projection; -layout (location = 0) in vec3 position; - -void main(){ - gl_Position = vec4(position,1);//projection*view*vec4(position,1); -} \ No newline at end of file -- cgit v1.2.3