Skip to content

Commit

Permalink
improved waving
Browse files Browse the repository at this point in the history
  • Loading branch information
null511 committed Mar 20, 2023
1 parent 51180b8 commit 4ad66c6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 67 deletions.
13 changes: 8 additions & 5 deletions shaders/entity.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ entity.0=minecraft:player
# ENTITY_BLAZE
entity.10=blaze

# ENTITY_MAGMA_CUBE
entity.11=magma_cube

# ENTITY_END_CRYSTAL
entity.12=end_crystal
entity.11=end_crystal

# ENTITY_LIGHTNING_BOLT
entity.12=lightning_bolt

# ENTITY_MAGMA_CUBE
entity.13=magma_cube

# ENTITY_TNT
entity.13=tnt
entity.14=tnt
7 changes: 4 additions & 3 deletions shaders/lib/entities.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define ENTITY_PLAYER 0
#define ENTITY_BLAZE 10
#define ENTITY_MAGMA_CUBE 11
#define ENTITY_END_CRYSTAL 12
#define ENTITY_TNT 13
#define ENTITY_END_CRYSTAL 11
#define ENTITY_LIGHTNING_BOLT 12
#define ENTITY_MAGMA_CUBE 13
#define ENTITY_TNT 14
14 changes: 11 additions & 3 deletions shaders/lib/lighting/dynamic_blocks.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ vec3 GetSceneBlockLightColor(const in int blockId, const in vec2 noiseSample) {
break;
case BLOCK_GLOW_LICHEN:
case ITEM_GLOW_LICHEN:
lightColor = vec3(0.256, 0.389, 0.288);
lightColor = vec3(0.173, 0.374, 0.252);
break;
case BLOCK_JACK_O_LANTERN:
case ITEM_JACK_O_LANTERN:
Expand Down Expand Up @@ -675,7 +675,7 @@ float GetSceneBlockEmission(const in int blockId) {
case BLOCK_STONECUTTER:
blockType = BLOCKTYPE_STONECUTTER;
break;

case BLOCK_SNOW_LAYERS_1:
blockType = BLOCKTYPE_LAYERS_2;
break;
Expand All @@ -697,7 +697,9 @@ float GetSceneBlockEmission(const in int blockId) {
case BLOCK_SNOW_LAYERS_7:
blockType = BLOCKTYPE_LAYERS_14;
break;

}

switch (blockId) {
case BLOCK_BUTTON_FLOOR_N_S:
blockType = BLOCKTYPE_BUTTON_FLOOR_N_S;
break;
Expand Down Expand Up @@ -874,7 +876,9 @@ float GetSceneBlockEmission(const in int blockId) {
case BLOCK_STAIRS_TOP_OUTER_S_E:
blockType = BLOCKTYPE_STAIRS_TOP_OUTER_S_E;
break;
}

switch (blockId) {
case BLOCK_FENCE_POST:
blockType = BLOCKTYPE_FENCE_POST;
break;
Expand Down Expand Up @@ -930,7 +934,9 @@ float GetSceneBlockEmission(const in int blockId) {
case BLOCK_FENCE_GATE_CLOSED_W_E:
blockType = BLOCKTYPE_FENCE_GATE_CLOSED_W_E;
break;
}

switch (blockId) {
case BLOCK_WALL_POST:
blockType = BLOCKTYPE_WALL_POST;
break;
Expand Down Expand Up @@ -1046,7 +1052,9 @@ float GetSceneBlockEmission(const in int blockId) {
case BLOCK_CHORUS_OTHER:
blockType = BLOCKTYPE_CHORUS_OTHER;
break;
}

switch (blockId) {
case BLOCK_AMETHYST:
blockType = BLOCKTYPE_AMETHYST;
break;
Expand Down
11 changes: 2 additions & 9 deletions shaders/lib/lighting/tracing.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ vec3 TraceDDA(vec3 origin, const in vec3 endPos, const in float range) {
vec3 nextDist = (stepDir * 0.5 + 0.5 - fract(origin)) / direction;

float traceRayLen2 = pow2(traceRayLen);
vec3 currPos = origin;

uint blockTypeLast = BLOCKTYPE_EMPTY;
vec3 color = vec3(1.0);
vec3 currPos = origin;
bool hit = false;

for (int i = 0; i < STEP_COUNT && !hit; i++) {
Expand Down Expand Up @@ -120,8 +118,6 @@ vec3 TraceDDA(vec3 origin, const in vec3 endPos, const in float range) {
hit = TraceHitTest(blockType, rayStart - voxelPos, rayInv);
if (hit) color = vec3(0.0);
}

blockTypeLast = blockType;
}
}

Expand All @@ -134,12 +130,11 @@ vec3 TraceRay(const in vec3 origin, const in vec3 endPos, const in float range)
if (traceRayLen < EPSILON) return vec3(1.0);

int stepCount = int(0.5 * DYN_LIGHT_RAY_QUALITY * range);
float dither = InterleavedGradientNoise(gl_FragCoord.xy);// + frameCounter);
float dither = InterleavedGradientNoise(gl_FragCoord.xy);
vec3 stepSize = traceRay / stepCount;
vec3 color = vec3(1.0);
bool hit = false;

//vec3 lastGridPos = origin;
uint blockTypeLast;
for (int i = 1; i < stepCount && !hit; i++) {
vec3 gridPos = (i + dither) * stepSize + origin;
Expand All @@ -160,8 +155,6 @@ vec3 TraceRay(const in vec3 origin, const in vec3 endPos, const in float range)

blockTypeLast = blockType;
}

//lastGridPos = gridPos;
}

return color;
Expand Down
74 changes: 30 additions & 44 deletions shaders/lib/world/waving.glsl
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
vec3 waving_noise(vec3 p) {
vec3 f = fract(p);
p = floor(p);
return mix(
mix(
mix(
hash33(p + vec3(0, 0, 0)),
hash33(p + vec3(0, 0, 1)),
f.z
),
mix(
hash33(p + vec3(0, 1, 0)),
hash33(p + vec3(0, 1, 1)),
f.z
),
f.y
),
mix(
mix(
hash33(p + vec3(1, 0, 0)),
hash33(p + vec3(1, 0, 1)),
f.z
),
mix(
hash33(p + vec3(1, 1, 0)),
hash33(p + vec3(1, 1, 1)),
f.z
),
f.y
),
f.x
);
}
const float wavingScale = 8.0;
const float wavingHeight = 0.6;

vec3 waving_fbm(const in vec3 worldPos) {
vec2 position = worldPos.xz * rcp(wavingScale);

vec3 waving_fbm(vec3 pos) {
vec3 val = vec3(0);
float weight = 0.8;
float totalWeight = 0.0;
float frequency = 0.8;
float iter = 0.0;
float frequency = 3.0;
float speed = 1.0;
float weight = 1.0;
float height = 0.0;
float waveSum = 0.0;

float time = frameTimeCounter / 3.6;

for (int i = 0; i < 8; i++) {
val += waving_noise(pos * frequency) * weight;
totalWeight += weight;
vec2 direction = vec2(sin(iter), cos(iter));
float x = dot(direction, position) * frequency + time * speed;
float wave = exp(sin(x) - 1.0);
float result = wave * cos(x);
vec2 force = result * weight * direction;

position -= force * 0.03;
height += wave * weight;
iter += 12.0;
waveSum += weight;
weight *= 0.8;
frequency *= 1.2;
frequency *= 1.1;
speed *= 1.3;
}
return val / totalWeight;

position = (position * wavingScale) - worldPos.xz;
return vec3(position.x, height / waveSum * wavingHeight - 0.5 * wavingHeight, position.y);
}

float GetWavingRange(const in int blockId, out uint attachment) {
Expand Down Expand Up @@ -120,8 +107,7 @@ void ApplyWavingOffset(inout vec3 position, const in int blockId) {
vec3 worldPos = localPos + cameraPosition;
#endif

vec3 hash = mod(waving_fbm(worldPos) * 2.0 * PI + 1.2 * frameTimeCounter, 2.0 * PI);
vec3 offset = sin(hash) * range;
vec3 offset = waving_fbm(worldPos);

if (attachment != 0) {
float attachOffset = 0.0;
Expand Down
5 changes: 2 additions & 3 deletions shaders/program/shadow.gsh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ uniform float far;

void main() {
#if defined IRIS_FEATURE_SSBO && DYN_LIGHT_MODE != DYN_LIGHT_NONE

if (renderStage == MC_RENDER_STAGE_TERRAIN_SOLID
|| renderStage == MC_RENDER_STAGE_TERRAIN_CUTOUT
|| renderStage == MC_RENDER_STAGE_TERRAIN_CUTOUT_MIPPED
Expand All @@ -89,14 +88,14 @@ void main() {
#endif
}
else if (renderStage == MC_RENDER_STAGE_ENTITIES) {
if (entityId == ENTITY_LIGHTNING_BOLT) return;

vec4 light = GetSceneEntityLightColor(entityId, vVertexId);
if (light.a > EPSILON) AddSceneBlockLight(0, vOriginPos[0], light.rgb, light.a);
}
#endif

#if defined WORLD_SHADOW_ENABLED && SHADOW_TYPE != SHADOW_TYPE_NONE
//if (vEntityId[0] == MATERIAL_LIGHTNING_BOLT) return;

vec3 originShadowViewPos = (shadowModelView * vec4(vOriginPos[0], 1.0)).xyz;

#if defined IRIS_FEATURE_SSBO && DYN_LIGHT_MODE != DYN_LIGHT_NONE && SHADOW_TYPE == SHADOW_TYPE_DISTORTED
Expand Down

0 comments on commit 4ad66c6

Please sign in to comment.