Skip to content

Commit

Permalink
Add subtle animation
Browse files Browse the repository at this point in the history
  • Loading branch information
onnowhere committed Mar 27, 2021
1 parent 6da7465 commit c7a3277
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
63 changes: 63 additions & 0 deletions VertexFadeRP/assets/minecraft/shaders/core/convert_rendertype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os

shaders = [
"rendertype_beacon_beam",
"rendertype_crumbling",
"rendertype_cutout_mipped",
"rendertype_cutout",
#"rendertype_entity_alpha",
#"rendertype_entity_cutout_no_cull_z_offset",
#"rendertype_entity_cutout_no_cull",
#"rendertype_entity_cutout",
#"rendertype_entity_decal",
#"rendertype_entity_glint_direct",
#"rendertype_entity_glint",
#"rendertype_entity_no_outline",
#"rendertype_entity_shadow",
#"rendertype_entity_smooth_cutout",
#"rendertype_entity_solid",
#"rendertype_entity_translucent_cull",
#"rendertype_entity_translucent",
#"rendertype_eyes",
"rendertype_solid",
"rendertype_translucent_moving_block",
"rendertype_translucent_no_crumbling",
"rendertype_translucent",
"rendertype_water_mask"
]

for file in os.listdir('.'):
rendertype_block = False
for shader in shaders:
if file.find(shader) != -1 and file.startswith("rendertype_") and file.endswith(".json"):
rendertype_block = True
break

if True:
if not file.endswith(".json"):
continue
with open(file, 'r') as f:
fread = f.readlines()
modify = True
for line in fread:
if line.find("main/rendertype_block") != -1 or line.find("main/rendertype_entity") != -1:
modify = False
if not modify:
continue
gread = fread.copy()
for i,line in enumerate(fread):
if line.find("vertex") != -1:
if rendertype_block:
line = ' "vertex": "main/rendertype_block",\n'
else:
line = ' "vertex": "main/rendertype_entity",\n'
gread[i] = line
if line.find("]\n") != -1 and i > len(fread) - 5:
gread[i-1] = gread[i-1].replace("}","},")
gread.insert(i, ' { "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }\n')
with open(file, 'w') as f:
f.write("".join(gread))




Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ uniform sampler2D Sampler2;
uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform vec3 ChunkOffset;
uniform float GameTime;

out float vertexDistance;
out vec4 vertexColor;
Expand Down Expand Up @@ -73,7 +74,8 @@ void main() {
float blockDistance = max(0.0, length((ModelViewMat * vec4(Position - uvOffset + vec3(0.5) + ChunkOffset, 1.0)).xyz) - distanceThreshold);
blockDistance *= blockDistance;

float scale = clamp(blockDistance * 0.1 / fadeScale, 0.0, 1.0);
float animation = (sin((rand(Position - uvOffset) + GameTime) * 1600.0) / 8.0) * 0.25 + 0.75;
float scale = clamp(blockDistance * animation * 0.1 / fadeScale, 0.0, 1.0);
vec3 uvScale = vec3(0.5 - uv.x, 0.0, 0.5 - uv.y) * scale;
if (Normal == vec3(1.0, 0.0, 0.0)) { // Positive X
uvScale = vec3(0.0, uv.y - 0.5, uv.x - 0.5) * scale;
Expand All @@ -95,7 +97,7 @@ void main() {
} else {
gl_Position = ProjMat * ModelViewMat * vec4(floor(Position) + uvScale + ChunkOffset, 1.0);
}
gl_Position += normal * blockDistance * 0.2 / fadeScale * rand(Position - uvOffset);
gl_Position += normal * blockDistance * animation * 0.2 / fadeScale * rand(Position - uvOffset);
if (blockDistance > 10.0 * fadeScale) {
gl_Position = vec4(0.0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ uniform sampler2D Sampler2;

uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform float GameTime;

uniform vec3 Light0_Direction;
uniform vec3 Light1_Direction;
Expand All @@ -25,7 +26,6 @@ out vec4 lightMapColor;
out vec4 overlayColor;
out vec2 texCoord0;
out vec4 normal;
out vec3 light0;

float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
Expand Down Expand Up @@ -54,7 +54,6 @@ float rand(vec3 p){
}

void main() {
light0 = Light0_Direction;
vec2 uv = mod(UV0, 16.0/1024.0) * 1024.0/16.0;

vertexDistance = length((ModelViewMat * vec4(Position, 1.0)).xyz);
Expand Down Expand Up @@ -83,7 +82,8 @@ void main() {
float blockDistance = max(0.0, length((ModelViewMat * vec4(Position - uvOffset + vec3(0.5), 1.0)).xyz) - distanceThreshold);
blockDistance *= blockDistance;

float scale = clamp(blockDistance * 0.1 / fadeScale, 0.0, 1.0);
float animation = (sin((rand(Position - uvOffset) + GameTime) * 1600.0) / 8.0) * 0.25 + 0.75;
float scale = clamp(blockDistance * animation * 0.1 / fadeScale, 0.0, 1.0);
vec3 uvScale = vec3(0.5 - uv.x, 0.0, 0.5 - uv.y) * scale;
if (Normal == vec3(1.0, 0.0, 0.0)) { // Positive X
uvScale = vec3(0.0, uv.y - 0.5, uv.x - 0.5) * scale;
Expand All @@ -102,7 +102,7 @@ void main() {
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
// Skip inventory items
if (Light0_Direction.y > 67.0/255.0 || (Light0_Direction.y < 66.0/255.0 && Light0_Direction.y > 44.0/255.0) || Light0_Direction.y < 43.0/255.0) {
gl_Position += normal * blockDistance * 0.2 / fadeScale * rand(Position - uvOffset);
gl_Position += normal * blockDistance * animation * 0.2 / fadeScale * rand(Position - uvOffset);
if (blockDistance > 10.0 * fadeScale) {
gl_Position = vec4(0.0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{ "name": "Light1_Direction", "type": "float", "count": 3, "values": [0.0, 0.0, 0.0] },
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] }
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{ "name": "Light1_Direction", "type": "float", "count": 3, "values": [0.0, 0.0, 0.0] },
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] }
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
]
}

0 comments on commit c7a3277

Please sign in to comment.