Skip to content

Commit

Permalink
Merge pull request #24 from BarthPaleologue/WIP
Browse files Browse the repository at this point in the history
1.4.1 - Fixes and stability
  • Loading branch information
BarthPaleologue authored Feb 12, 2024
2 parents 782c67c + 462959e commit 5ece24f
Show file tree
Hide file tree
Showing 31 changed files with 454 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: [BarthPaleologue] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: cosmosjourneyer
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"version": "1.4.0",
"version": "1.4.1",
"description": "CosmosJourneyer",
"name": "cosmos-journeyer",
"scripts": {
Expand Down
15 changes: 8 additions & 7 deletions src/html/pauseMenu.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<div id="pauseMask"></div>
<div id="pauseMask">
<ul id="pauseMenu" class="leftSideMenu">
<li id="resumeButton" class="button">Resume</li>

<ul id="pauseMenu" class="leftSideMenu">
<li id="resumeButton" class="button">Resume</li>
<li id="saveButton" class="button">Save Game</li>

<li id="saveButton" class="button">Save Game</li>
<li id="screenshotButton" class="button">Take Screenshot</li>

<li id="screenshotButton" class="button">Take Screenshot</li>
<li id="shareButton" class="button">Share Position</li>
</ul>
</div>

<li id="shareButton" class="button">Share Position</li>
</ul>
24 changes: 13 additions & 11 deletions src/shaders/blackhole.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ void main() {

vec4 colOut = vec4(0.0);

vec3 positionBHS = camera_position - object_position;// position of the camera in blackhole space
vec3 rayPositionBlackHoleSpace = camera_position - object_position;// position of the camera in blackhole space

bool suckedInBH = false;
bool escapedBH = false;
bool occluded = false;

if (maximumDistance < length(positionBHS)) occluded = true;
if (maximumDistance < length(rayPositionBlackHoleSpace)) occluded = true;

vec4 col = vec4(0.0);
vec4 glow = vec4(0.0);
Expand All @@ -193,12 +193,12 @@ void main() {

for (int h = 0; h < 6; h++) {
//reduces tests for exit conditions (to minimise branching)
distanceToCenter = customLength(positionBHS);//distance to BH
vec3 blackholeDir = -positionBHS / distanceToCenter;//direction to BH
distanceToCenter = customLength(rayPositionBlackHoleSpace);//distance to BH
vec3 blackholeDir = -rayPositionBlackHoleSpace / distanceToCenter;//direction to BH
float distanceToCenter2 = distanceToCenter * distanceToCenter;

projectedPosition = projectOnPlane(positionBHS, object_rotationAxis);
projectedDistance = length(projectedPosition - positionBHS);
projectedPosition = projectOnPlane(rayPositionBlackHoleSpace, object_rotationAxis);
projectedDistance = length(projectedPosition - rayPositionBlackHoleSpace);

projectedRayDir = projectOnPlane(rayDir, object_rotationAxis);
rayDirProjectedDistance = length(projectedRayDir - rayDir);
Expand All @@ -209,7 +209,7 @@ void main() {
stepSize = min(stepSize, min(farLimit, closeLimit));

rayDir = bendRay(rayDir, blackholeDir, distanceToCenter2, maxBendDistance, stepSize);
positionBHS += stepSize * rayDir;
rayPositionBlackHoleSpace += stepSize * rayDir;

//TODO: improve glow
//glow += vec4(1.2,1.1,1, 1.0) * (0.2 * (object_radius / distanceToCenter2) * stepSize * clamp(distanceToCenter / object_radius - 1.2, 0.0, 1.0)); //adds fairly cheap glow
Expand All @@ -223,8 +223,8 @@ void main() {
break;
} else if (projectedDistance <= accretionDiskHeight) {
//ray hit accretion disk //FIXME: Break when rotate around edge of disk
vec4 diskCol = raymarchDisk(rayDir, positionBHS);//render disk
positionBHS += accretionDiskHeight * rayDir / rayDirProjectedDistance;// we get out of the disk
vec4 diskCol = raymarchDisk(rayDir, rayPositionBlackHoleSpace);//render disk
rayPositionBlackHoleSpace += accretionDiskHeight * rayDir / rayDirProjectedDistance;// we get out of the disk
col += diskCol * (1.0 - col.a);
}

Expand All @@ -233,7 +233,7 @@ void main() {
}

// getting the screen coordinate of the end of the bended ray
vec2 uv = uvFromWorld(positionBHS, camera_projection, camera_view);
vec2 uv = uvFromWorld(rayPositionBlackHoleSpace, camera_projection, camera_view);
// check if there is an object occlusion
vec3 pixelWorldPositionEndRay = worldFromUV(uv, camera_inverseProjection, camera_inverseView);// the pixel position in world space (near plane)
vec3 rayDirToEndRay = normalize(pixelWorldPositionEndRay - camera_position);// normalized direction of the ray
Expand All @@ -249,8 +249,10 @@ void main() {
float maximumDistanceEndRay = length(closestPointEndRay);// the maxium ray length due to occlusion
float BHDistance = length(camera_position - object_position);

bool behindBH = dot(closestPointEndRay - camera_position, closestPointEndRay - object_position) >= 0.0;

vec4 bg = vec4(0.0);
if(uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0 && maximumDistanceEndRay > BHDistance - object_radius) {
if(uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0 && behindBH) {
bg = texture2D(textureSampler, uv);
} else {
rayDir = vec3(starfieldRotation * vec4(rayDir, 1.0));
Expand Down
20 changes: 8 additions & 12 deletions src/styles/pauseMenu/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#pauseMask {
z-index: 40;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: transparent;
backdrop-filter: blur(4px);
}

#pauseMenu {
z-index: 41;
z-index: 40;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(4px);
}
8 changes: 3 additions & 5 deletions src/ts/alphaTestis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ import { RingsUniforms } from "./postProcesses/rings/ringsUniform";
import { getMoonSeed } from "./planets/common";
import { SystemSeed } from "./utils/systemSeed";

const engine = new CosmosJourneyer();
const engine = await CosmosJourneyer.CreateAsync();

await engine.setup();

const starSystemView = engine.getStarSystemView();
const starSystemView = engine.starSystemView;

const spaceshipController = starSystemView.getSpaceshipControls();

Expand All @@ -54,7 +52,7 @@ const starSystemSeed = new SystemSeed(0, 0, 0, 0);
const starSystem = new StarSystemController(starSystemSeed, starSystemView.scene);
starSystem.model.setName("Alpha Testis");

engine.getStarSystemView().setStarSystem(starSystem, false);
starSystemView.setStarSystem(starSystem, false);

const sunModel = new StarModel(0.51);
const sun = StarSystemHelper.makeStar(starSystem, sunModel);
Expand Down
11 changes: 11 additions & 0 deletions src/ts/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture";
import { createButterfly } from "./proceduralAssets/butterfly/butterfly";
import { createGrassBlade } from "./proceduralAssets/grass/grassBlade";
import { ButterflyMaterial } from "./proceduralAssets/butterfly/butterflyMaterial";
import { GrassMaterial } from "./proceduralAssets/grass/grassMaterial";

export class Assets {
static IS_READY = false;
Expand Down Expand Up @@ -114,6 +116,9 @@ export class Assets {
public static Butterfly: Mesh;
public static GrassBlade: Mesh;

public static ButterflyMaterial: ButterflyMaterial;
public static GrassMaterial: GrassMaterial;

public static OuchSound: Sound;
public static EngineRunningSound: Sound;

Expand Down Expand Up @@ -212,6 +217,7 @@ export class Assets {
Assets.Rock.position.y = 0.1;
Assets.Rock.scaling.scaleInPlace(0.2);
Assets.Rock.bakeCurrentTransformIntoVertices();
Assets.Rock.checkCollisions = true;
Assets.Rock.isVisible = false;

console.log("Rock loaded");
Expand All @@ -235,6 +241,7 @@ export class Assets {
Assets.Tree.position.y = -1;
Assets.Tree.scaling.scaleInPlace(3);
Assets.Tree.bakeCurrentTransformIntoVertices();
Assets.Tree.checkCollisions = true;

const treeMaterial = new StandardMaterial("treeMaterial", scene);

Expand All @@ -255,8 +262,12 @@ export class Assets {
};

Assets.Butterfly = createButterfly(scene);
Assets.ButterflyMaterial = new ButterflyMaterial(scene);
Assets.Butterfly.material = Assets.ButterflyMaterial;

Assets.GrassBlade = createGrassBlade(scene, 3);
Assets.GrassMaterial = new GrassMaterial(scene);
Assets.GrassBlade.material = Assets.GrassMaterial;

const ouchSoundTask = Assets.manager.addBinaryFileTask("ouchSoundTask", ouchSound);
ouchSoundTask.onSuccess = function (task) {
Expand Down
6 changes: 2 additions & 4 deletions src/ts/blackHoleDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import { CosmosJourneyer } from "./cosmosJourneyer";
import { StarSystemHelper } from "./starSystem/starSystemHelper";
import { SystemSeed } from "./utils/systemSeed";

const engine = new CosmosJourneyer();
const engine = await CosmosJourneyer.CreateAsync();

await engine.setup();

const starSystemView = engine.getStarSystemView();
const starSystemView = engine.starSystemView;

const scene = starSystemView.scene;

Expand Down
Loading

0 comments on commit 5ece24f

Please sign in to comment.