Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 - WebGPU Only #98

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/shaders/atmosphericScatteringFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

precision lowp float;
precision highp float;

#define DISABLE_UNIFORMITY_ANALYSIS

Expand All @@ -37,8 +37,6 @@ uniform sampler2D depthSampler;// the depth map of the camera

#include "./utils/atmosphere.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/rayIntersectSphere.glsl";
Expand Down Expand Up @@ -160,12 +158,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

// Cohabitation avec le shader d'océan (un jour je merge)
float waterImpact, waterEscape;
Expand Down
17 changes: 7 additions & 10 deletions src/shaders/blackhole.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ uniform mat4 starfieldRotation;

#include "./utils/camera.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/uvFromWorld.glsl";
Expand Down Expand Up @@ -156,14 +154,13 @@ float customLength(vec3 v) {

void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);// normalized direction of the ray

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

float maxBendDistance = max(accretionDiskRadius * 3.0, schwarzschildRadius * 15.0);

Expand Down Expand Up @@ -255,17 +252,17 @@ void main() {

// getting the screen coordinate of the end of the bended ray
vec2 uv = uvFromWorld(rayPositionBlackHoleSpace + object_position, camera_projection, camera_view);
float depthEndRay = texture2D(depthSampler, uv).r;// the depth corresponding to the pixel in the depth map
// check if there is an object occlusion
vec3 pixelWorldPositionEndRay = worldFromUV(uv, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPositionEndRay = worldFromUV(uv, depthEndRay, camera_inverseProjectionView);// the pixel position in world space (near plane)
vec3 rayDirToEndRay = normalize(pixelWorldPositionEndRay - camera_position);// normalized direction of the ray

float depthEndRay = texture2D(depthSampler, uv).r;// the depth corresponding to the pixel in the depth map
for(int i = 0; i < 10; i++) {
vec2 offset = (vec2(hash(float(i)), hash(float(i + 1))) - 0.5) * 0.01;
depthEndRay = min(depthEndRay, texture2D(depthSampler, uv + offset).r);
}
// closest physical point from the camera in the direction of the pixel (occlusion)
vec3 closestPointEndRay = (pixelWorldPositionEndRay - camera_position) * remap(depthEndRay, 0.0, 1.0, camera_near, camera_far);
vec3 closestPointEndRay = pixelWorldPositionEndRay - camera_position;
float maximumDistanceEndRay = length(closestPointEndRay);// the maxium ray length due to occlusion
float BHDistance = length(camera_position - object_position);

Expand Down
8 changes: 3 additions & 5 deletions src/shaders/flatCloudsFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ uniform float time;

#include "./utils/saturate.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/rayIntersectSphere.glsl";
Expand Down Expand Up @@ -164,12 +162,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// closest physical point from the camera in the direction of the pixel (occlusion)
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);// normalized direction of the ray

vec3 closestPoint = camera_position + rayDir * maximumDistance;
float t0, t1;
Expand Down
1 change: 0 additions & 1 deletion src/shaders/grassMaterial/grassVertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ uniform sampler2D perlinNoise;
varying vec3 vPosition;
varying vec3 vPositionW;

varying mat4 normalMatrix;
varying vec3 vNormalW;

varying float vPlanetNdl;
Expand Down
10 changes: 6 additions & 4 deletions src/shaders/juliaSet.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ float getShadow(vec3 rayOrigin, vec3 rayDir, vec3 starPosition) {
void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

float impactPoint, escapePoint;
if (!(rayIntersectSphere(camera_position, rayDir, object_position, object_radius * object_scaling_determinant, impactPoint, escapePoint))) {
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/lensflare.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void main() {
return;
}

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);
vec3 pixelWorldPosition = worldFromUV(vUV, 1.0, camera_inverseProjectionView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

vec3 objectDirection = normalize(object_position - camera_position);

Expand Down
10 changes: 6 additions & 4 deletions src/shaders/mandelbox.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ float distanceEstimator(vec3 position) {
void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

float impactPoint, escapePoint;
if (!(rayIntersectSphere(camera_position, rayDir, object_position, object_radius * object_scaling_determinant, impactPoint, escapePoint))) {
gl_FragColor = screenColor;
Expand Down
12 changes: 6 additions & 6 deletions src/shaders/mandelbulb.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ uniform sampler2D depthSampler;

#include "./utils/camera.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/rayIntersectSphere.glsl";
Expand Down Expand Up @@ -180,12 +178,14 @@ float getShadow(vec3 rayOrigin, vec3 rayDir, vec3 starPosition) {
void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

float impactPoint, escapePoint;
if (!(rayIntersectSphere(camera_position, rayDir, object_position, object_radius * object_scaling_determinant, impactPoint, escapePoint))) {
Expand Down
8 changes: 3 additions & 5 deletions src/shaders/matterjet.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ uniform float dipoleTilt;

#include "./utils/rotateAround.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/removeAxialTilt.glsl";
Expand Down Expand Up @@ -230,12 +228,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);// normalized direction of the ray

float scaling_factor = object_radius * 10000.0;

Expand Down
10 changes: 6 additions & 4 deletions src/shaders/mengerSponge.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ float distanceEstimator( in vec3 p ) {
void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

float impactPoint, escapePoint;
if (!(rayIntersectSphere(camera_position, rayDir, object_position, object_radius * object_scaling_determinant, impactPoint, escapePoint))) {
gl_FragColor = screenColor;
Expand Down
6 changes: 4 additions & 2 deletions src/shaders/metalSectionMaterial/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ void main() {

vec2 uv = vec2(fract(6.0 * vUV.x), fract(vPosition.y / 50.0));

float gamma = 2.2;

vec3 normalFromMap = texture(normalMap, uv).rgb;
normalFromMap.y = 1.0 - normalFromMap.y;
normalFromMap = normalFromMap * 2.0 - 1.0;
vec3 normalW = normalize(vTBN * normalFromMap);

vec3 albedo = pow(texture(albedoMap, uv).rgb, vec3(2.2));
vec3 albedo = pow(texture(albedoMap, uv).rgb, vec3(gamma));
float roughness = texture(roughnessMap, uv).r;
float metallic = texture(metallicMap, uv).r;

Expand All @@ -53,7 +55,7 @@ void main() {
Lo += calculateLight(albedo, normalW, roughness, metallic, lightDirectionW, viewDirectionW, star_colors[i]);
}

Lo = pow(Lo, vec3(1.0 / 2.2));
Lo = pow(Lo, vec3(1.0 / gamma));

gl_FragColor = vec4(Lo, 1.0);
}
1 change: 0 additions & 1 deletion src/shaders/metalSectionMaterial/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ attribute vec3 normal;
attribute vec2 uv;

uniform mat4 world;
uniform mat4 view;
uniform mat4 worldViewProjection;

varying vec3 vPositionW;
Expand Down
10 changes: 4 additions & 6 deletions src/shaders/oceanFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ uniform float ocean_waveBlendingSharpness;

uniform float time;

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/rayIntersectSphere.glsl";
Expand All @@ -68,12 +66,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

vec4 finalColor = screenColor;

Expand Down Expand Up @@ -109,7 +107,7 @@ void main() {
vec3 ambiant = mix(oceanColor, screenColor.rgb, alpha);

// if the camera is not inside the ocean
if(impactPoint > 0.0) {
if (impactPoint > 0.0) {
// color of the sky
vec3 reflectedSkyColor = vec3(0.6, 0.8, 0.95);

Expand Down
6 changes: 3 additions & 3 deletions src/shaders/ringsFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);// normalized direction of the ray

vec4 finalColor = screenColor;

Expand Down
6 changes: 3 additions & 3 deletions src/shaders/shadowFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void main() {

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// closest physical point from the camera in the direction of the pixel (occlusion)
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray
vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);// normalized direction of the ray

vec4 finalColor = screenColor;

Expand Down
12 changes: 6 additions & 6 deletions src/shaders/sierpinski.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ uniform sampler2D depthSampler;

#include "./utils/camera.glsl";

#include "./utils/remap.glsl";

#include "./utils/worldFromUV.glsl";

#include "./utils/rayIntersectSphere.glsl";
Expand Down Expand Up @@ -78,13 +76,15 @@ float distanceEstimator(vec3 z) {
void main() {
vec4 screenColor = texture2D(textureSampler, vUV);// the current screen color

vec3 pixelWorldPosition = worldFromUV(vUV, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDir = normalize(pixelWorldPosition - camera_position);// normalized direction of the ray

float depth = texture2D(depthSampler, vUV).r;// the depth corresponding to the pixel in the depth map

vec3 pixelWorldPosition = worldFromUV(vUV, depth, camera_inverseProjectionView);// the pixel position in world space (near plane)

// actual depth of the scene
float maximumDistance = length(pixelWorldPosition - camera_position) * remap(depth, 0.0, 1.0, camera_near, camera_far);
float maximumDistance = length(pixelWorldPosition - camera_position);

vec3 rayDir = normalize(worldFromUV(vUV, 1.0, camera_inverseProjectionView) - camera_position);

float impactPoint, escapePoint;
if (!(rayIntersectSphere(camera_position, rayDir, object_position, object_radius * object_scaling_determinant, impactPoint, escapePoint))) {
gl_FragColor = screenColor;
Expand Down
4 changes: 0 additions & 4 deletions src/shaders/solarPanelMaterial/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ uniform sampler2D roughnessMap;

uniform vec3 cameraPosition;

#include "../utils/pi.glsl";

#include "../utils/stars.glsl";

#include "../utils/remap.glsl";

#include "../utils/textureNoTile.glsl";

#include "../utils/pbr.glsl";
Expand Down
Loading
Loading