generated from ThomasBurgess2000/babylonian
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Dynamic terrain getting started * infinite dynamic terrain * working without fog * Cleaned up shader loading * done
- Loading branch information
1 parent
baffd96
commit e3c6d83
Showing
22 changed files
with
256,826 additions
and
46,195 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
varying float vHeight; | ||
uniform float lowestPoint; | ||
uniform float highestPoint; | ||
uniform float seaLevel; | ||
uniform float mountainLevel; | ||
varying vec2 vUV; | ||
uniform sampler2D noiseTexture; | ||
|
||
void main(void) { | ||
vec3 color; | ||
float noise = texture2D(noiseTexture, vUV).r; | ||
if (vHeight <= seaLevel) { | ||
float depthFactor = (vHeight - lowestPoint) / (seaLevel - lowestPoint); | ||
color = mix(vec3(0.0, 0.0, 0.3), vec3(0.0, 0.0, 1.0), depthFactor); | ||
} else if (vHeight <= mountainLevel) { | ||
float noiseFactor = mix(0.4, 0.6, noise); | ||
color = vec3(0.0, noiseFactor, 0.0); | ||
} else { | ||
color = vec3(1.0, 1.0, 1.0); | ||
} | ||
|
||
gl_FragColor = vec4(color, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
precision highp float; | ||
|
||
attribute vec3 position; | ||
attribute vec2 uv; | ||
|
||
uniform mat4 worldViewProjection; | ||
|
||
varying float vHeight; | ||
varying vec2 vUV; | ||
|
||
void main() { | ||
vHeight = position.y; | ||
vUV = uv; | ||
gl_Position = worldViewProjection * vec4(position, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
precision highp float; | ||
|
||
// Varying variables for lighting calculations | ||
varying vec2 vUV; | ||
varying vec3 vPositionW; | ||
varying vec3 vNormalW; | ||
|
||
// Uniforms | ||
uniform sampler2D textureSampler; | ||
uniform vec3 u_color; | ||
uniform vec3 vLightPosition; // Add a light position uniform | ||
|
||
void main(void) { | ||
// Toon shader thresholds and brightness levels | ||
float ToonThresholds[4]; | ||
ToonThresholds[0] = 0.95; | ||
ToonThresholds[1] = 0.5; | ||
ToonThresholds[2] = 0.2; | ||
ToonThresholds[3] = 0.03; | ||
|
||
float ToonBrightnessLevels[5]; | ||
ToonBrightnessLevels[0] = 1.0; | ||
ToonBrightnessLevels[1] = 0.8; | ||
ToonBrightnessLevels[2] = 0.6; | ||
ToonBrightnessLevels[3] = 0.35; | ||
ToonBrightnessLevels[4] = 0.2; | ||
|
||
// Light calculation | ||
vec3 lightVectorW = normalize(vPositionW - vLightPosition); | ||
float ndl = max(0., dot(vNormalW, lightVectorW)); | ||
|
||
// Apply toon shading | ||
vec3 color = texture2D(textureSampler, vUV).rgb; | ||
for (int i = 0; i < 4; i++) { | ||
if (ndl > ToonThresholds[i]) { | ||
color *= ToonBrightnessLevels[i]; | ||
break; | ||
} | ||
} | ||
|
||
// Original luminance and transparency logic | ||
float luminance = dot(color, vec3(0.299, 0.587, 0.114)); | ||
if (luminance < 0.75) { | ||
discard; | ||
} | ||
|
||
gl_FragColor = vec4(u_color * color, luminance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
attribute vec3 position; | ||
attribute vec2 uv; | ||
attribute vec3 normal; | ||
|
||
#include<instancesDeclaration> | ||
uniform mat4 view; | ||
uniform float u_effectBlend; | ||
uniform float u_remap; | ||
uniform float u_normalize; | ||
uniform mat4 projection; | ||
|
||
varying vec2 vUV; | ||
varying vec3 vPositionW; | ||
varying vec3 vNormalW; | ||
|
||
float inverseLerp(float v, float minValue, float maxValue) { | ||
return (v - minValue) / (maxValue - minValue); | ||
} | ||
|
||
float remap(float v, float inMin, float inMax, float outMin, float outMax) { | ||
float t = inverseLerp(v, inMin, inMax); | ||
return mix(outMin, outMax, t); | ||
} | ||
|
||
void main() { | ||
#include<instancesVertex> | ||
vec2 vertexOffset = vec2( | ||
remap(uv.x, 0.0, 1.0, -u_remap, 1.0), | ||
remap(uv.y, 0.0, 1.0, -u_remap, 1.0) | ||
); | ||
|
||
vertexOffset *= vec2(-1.0, 1.0); | ||
|
||
if (u_remap == 1.0) { | ||
vertexOffset = mix(vertexOffset, normalize(vertexOffset), u_normalize); | ||
} | ||
|
||
vec4 worldPosition = finalWorld * vec4(position, 1.0); | ||
vPositionW = worldPosition.xyz; | ||
|
||
vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0))); | ||
|
||
vec4 worldViewPosition = view * finalWorld * vec4(position, 1.0); | ||
|
||
worldViewPosition += vec4(mix(vec3(0.0), vec3(vertexOffset, 1.0), u_effectBlend), 0.0); | ||
|
||
vUV = uv; | ||
|
||
gl_Position = projection * worldViewPosition; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Vector3 } from '@babylonjs/core'; | ||
import { DynamicTerrain } from '../externals/babylon.dynamicTerrain_modular'; | ||
import { InitializationStatus } from '../utils/types'; | ||
|
||
export class DynamicTerrainComponent { | ||
public dynamicTerrain: DynamicTerrain | null = null; | ||
public initializationStatus: InitializationStatus = InitializationStatus.NotInitialized; | ||
constructor(public flatPoints: Vector3[] = []) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.