Skip to content

Commit

Permalink
-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
neuroprod committed Dec 6, 2023
1 parent 5ad4252 commit 7c778b7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 53 deletions.
9 changes: 8 additions & 1 deletion frontend/src/GameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import StartGame from "./transitions/StartGame";
import {Vector2, Vector3} from "math.gl";
import Main from "./Main";
import GoInside from "./transitions/GoInside";
import mapRange = gsap.utils.mapRange;



Expand All @@ -23,6 +24,7 @@ export enum Scenes
class GameModel {



public currentScene:Scenes =Scenes.ROOM
public yMouseCenter: number = 1;
public yMouseScale: number = 1;
Expand All @@ -31,10 +33,15 @@ class GameModel {
public mouseDownThisFrame: boolean =false;
public mousePos: Vector2=new Vector2();

characterPos: Vector3 = new Vector3(0, 0, 0);
public characterPos: Vector3 = new Vector3(0, 0, 0);
dayNight: number = 0;
constructor() {
}





public setScene(scenes:Scenes){
this.main.setScene(scenes);
this.currentScene =scenes;
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,7 @@ export default class Main {
}


UI.pushWindow("Scenes")
if (UI.LButton("Inside")) {
this.setScene(0);
}
if (UI.LButton("Outside")) {
this.setScene(1);
}
UI.popWindow()



UI.pushWindow("Performance")
Expand All @@ -286,9 +279,7 @@ export default class Main {
UI.popWindow()

this.lightRoomPass.onUI();

this.lightOutsidePass.onUI(this.shadowPass.camera.viewProjection);

this.shadowPass.onUI()


Expand Down
42 changes: 26 additions & 16 deletions frontend/src/Outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ import PreLoader from "./lib/PreLoader";
import GLFTLoader from "./GLFTLoader";
import ModelRenderer from "./lib/model/ModelRenderer";
import Object3D from "./lib/core/Object3D";
import UI from "./lib/UI/UI";
import GameModel from "./GameModel";
import mapRange = gsap.utils.mapRange;
import {clamp} from "math.gl";


export default class Outside{
private renderer: Renderer;
private glFTLoader: GLFTLoader;

export default class Outside {
modelRenderer: ModelRenderer;
modelRendererTrans: ModelRenderer;
root:Object3D
constructor(renderer:Renderer,preloader:PreLoader) {
root: Object3D
private renderer: Renderer;
private glFTLoader: GLFTLoader;

this.renderer=renderer;
constructor(renderer: Renderer, preloader: PreLoader) {

this.renderer = renderer;
this.glFTLoader = new GLFTLoader(this.renderer, "outside", preloader);

}
init(){
this.modelRenderer =new ModelRenderer(this.renderer,"outside");
this.modelRendererTrans =new ModelRenderer(this.renderer,"outsideTrans");

this.root =this.glFTLoader.root
init() {
this.modelRenderer = new ModelRenderer(this.renderer, "outside");
this.modelRendererTrans = new ModelRenderer(this.renderer, "outsideTrans");

this.root = this.glFTLoader.root


for (let m of this.glFTLoader.models) {
Expand All @@ -33,16 +37,22 @@ this.root =this.glFTLoader.root
}
}

public update(){
// UI.LFloat('offset',0)
// this.glFTLoader.root.setPosition(this.renderer.ratio * 4 / 2 +UI.LFloat('offset',0), -1.5, 0)
public update() {

let pos =-GameModel.characterPos.x;


GameModel.dayNight =clamp((pos-13)/8,0,1);
//GameModel.dayNight
// UI.LFloat('offset',0)
// this.glFTLoader.root.setPosition(this.renderer.ratio * 4 / 2 +UI.LFloat('offset',0), -1.5, 0)
}

makeTransParent() {
for (let m of this.glFTLoader.modelsGlass) {

m.material.uniforms.setTexture("gDepth",this.renderer.texturesByLabel["GDepth"])
m.material.uniforms.setTexture("reflectTexture",this.renderer.texturesByLabel["LightPass"])
m.material.uniforms.setTexture("gDepth", this.renderer.texturesByLabel["GDepth"])
m.material.uniforms.setTexture("reflectTexture", this.renderer.texturesByLabel["LightPass"])
this.modelRendererTrans.addModel(m)

}
Expand Down
80 changes: 55 additions & 25 deletions frontend/src/renderPasses/LightOutsideRenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MainLight from "../MainLight";

import GlobalLightOutsideShader from "../shaders/GlobalLightOutsideShader";
import RenderSettings from "../RenderSettings";
import GameModel from "../GameModel";

export default class LightOutsideRenderPass extends RenderPass {

Expand All @@ -32,13 +33,28 @@ export default class LightOutsideRenderPass extends RenderPass {
private globalLightMaterial: Material;
private blitGlobalLight: Blit;

private topColor: ColorV = new ColorV( 0.73,0.99,0.95,0.40);
private midColor: ColorV = new ColorV(1.00, 0.91, 0.82, 0.19);
private bottomColor: ColorV = new ColorV(1.00, 0.91, 0.82, 0.1);
private sunLightColor: ColorV = new ColorV(0.99,0.88,0.73,1.00);
private sunLightStrength: number = 4;

private topColorDay: ColorV = new ColorV( 0.73,0.99,0.95,0.40);
private midColorDay: ColorV = new ColorV(1.00, 0.91, 0.82, 0.19);
private bottomColorDay: ColorV = new ColorV(1.00, 0.91, 0.82, 0.1);


private moonLightColor: ColorV = new ColorV( 0.00,0.40,1.00,1.00);
private moonLightStrength: number = 2.4;

private topColorNight: ColorV = new ColorV( 0.01,0.40,1.00,0.40*0.5);
private midColorNight: ColorV = new ColorV( 0.01,0.96,1.00,0.10);
private bottomColorNight: ColorV = new ColorV( 0.01,0.40,1.00, 0.1*0.5);






private mainLightColor: ColorV = new ColorV(0.99,0.88,0.73,1.00);
public sunDir =new Vector3(-0.172996,-0.694981,-0.697907);
private mainLightStrength: number = 4;


constructor(renderer: Renderer, target: RenderTexture) {

Expand All @@ -63,11 +79,11 @@ export default class LightOutsideRenderPass extends RenderPass {

this.globalLightMaterial = new Material(this.renderer, "blitGlobalLight", new GlobalLightOutsideShader(this.renderer, "globalLightOutside"))

this.globalLightMaterial.uniforms.setUniform("topColor", this.topColor);
this.globalLightMaterial.uniforms.setUniform("midColor", this.midColor);
this.globalLightMaterial.uniforms.setUniform("bottomColor", this.bottomColor);
this.globalLightMaterial.uniforms.setUniform("topColor", this.topColorDay);
this.globalLightMaterial.uniforms.setUniform("midColor", this.midColorDay);
this.globalLightMaterial.uniforms.setUniform("bottomColor", this.bottomColorDay);

this.globalLightMaterial.uniforms.setUniform("lightColor", this.mainLightColor);
this.globalLightMaterial.uniforms.setUniform("lightColor", this.sunLightColor);
this.globalLightMaterial.uniforms.setUniform("lightDir", new Vector4( this.sunDir.x,this.sunDir.y,this.sunDir.z, 1));
this.globalLightMaterial.uniforms.setTexture("shadow", this.renderer.texturesByLabel["Shadow"]);
this.globalLightMaterial.uniforms.setTexture("aoTexture", this.renderer.texturesByLabel["OABlurPass"]);
Expand Down Expand Up @@ -104,30 +120,44 @@ export default class LightOutsideRenderPass extends RenderPass {
UI.pushWindow("Light Outside")

UI.separator("Sun Light")
this.mainLightColor.w =1;
UI.LColor("color", this.mainLightColor)
this.mainLightStrength = UI.LFloatSlider("strength", this.mainLightStrength, 0, 20);
UI.LVector("dir",this.sunDir,true);

UI.separator("Global Light")
UI.LColor("topLight", this.topColor)
UI.LColor("midLight", this.midColor)
UI.LColor("bottomLight", this.bottomColor)
this.mainLightColor.w = this.mainLightStrength;
this.globalLightMaterial.uniforms.setUniform("lightColor", this.mainLightColor)
// GameModel.dayNight =UI.LFloatSlider("dayNight", GameModel.dayNight,0,1);
UI.separator("Day")
this.sunLightColor.w =1;
UI.LColor("sunColor", this.sunLightColor)
this.sunLightColor.w=this.sunLightStrength = UI.LFloatSlider("strength", this.sunLightStrength, 0, 20);

UI.separator("Global Light Day")
UI.LColor("topLightDay",this.midColorDay)
UI.LColor("midLightDay", this.midColorDay)
UI.LColor("bottomLightDay", this.bottomColorDay)

UI.separator("Night")
this.moonLightColor.w =1;
UI.LColor("moonColor", this.moonLightColor)
this.moonLightColor.w=this.moonLightStrength = UI.LFloatSlider("strength Moon", this.moonLightStrength , 0, 20);

UI.separator("Global Light Night")
UI.LColor("topLightNight",this.midColorNight)
UI.LColor("midLightNight", this.midColorNight)
UI.LColor("bottomLightNight", this.bottomColorNight)

this.globalLightMaterial.uniforms.setUniform("lightColor", this.sunLightColor.clone().lerp(this.moonLightColor,GameModel.dayNight))
this.globalLightMaterial.uniforms.setUniform("lightDir", new Vector4( this.sunDir.x,this.sunDir.y,this.sunDir.z, 1));

this.globalLightMaterial.uniforms.setUniform("topColor", this.topColor)
this.globalLightMaterial.uniforms.setUniform("midColor", this.midColor)
this.globalLightMaterial.uniforms.setUniform("bottomColor", this.bottomColor)
this.globalLightMaterial.uniforms.setUniform("topColor", this.topColorDay.clone().lerp(this.topColorNight,GameModel.dayNight))
this.globalLightMaterial.uniforms.setUniform("midColor", this.midColorDay.clone().lerp(this.midColorNight,GameModel.dayNight))
this.globalLightMaterial.uniforms.setUniform("bottomColor", this.bottomColorDay.clone().lerp(this.bottomColorNight,GameModel.dayNight))

this.globalLightMaterial.uniforms.setUniform( "shadowMatrix",matrix)
UI.popWindow()
}
onSettingsChange() {
super.onSettingsChange();
this.globalLightMaterial.uniforms.setUniform("dof",RenderSettings.dof_Settings)
}

onSettingsChange() {
super.onSettingsChange();
this.globalLightMaterial.uniforms.setUniform("dof",RenderSettings.dof_Settings)
}

draw() {

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/shaders/GlobalLightOutsideShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
}
}
shadowVal/=9.0;
//
let albedo =pow(textureLoad(gColor, uvPos ,0).xyz,vec3(2.2));;
let N = normalize((textureLoad(gNormal, uvPos ,0).xyz-0.5) *2.0);
Expand All @@ -166,7 +167,7 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
let ao = textureLoad(aoTexture, uvPosAO ,0).x ;
let l = dot(N,vec3(0,1.0,0));
let light =mix( mix(uniforms.midColor.xyz*uniforms.midColor.w,uniforms.topColor.xyz*uniforms.topColor.w,max(0.0,l)),uniforms.bottomColor.xyz*uniforms.bottomColor.w,max(0.0,-l));
let light =mix( mix(uniforms.midColor.xyz*uniforms.midColor.w,uniforms.topColor.xyz*uniforms.topColor.w,max(0.0,l)),uniforms.bottomColor.xyz*uniforms.bottomColor.w,max(0.0,-l));
let color = albedo*light*ao*(1.0-mra.x) +albedo*pow(mra.z,2.0)*10.0;
Expand Down

0 comments on commit 7c778b7

Please sign in to comment.