Skip to content

Commit

Permalink
-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
neuroprod committed Dec 7, 2023
1 parent 0fd6174 commit b1efca6
Show file tree
Hide file tree
Showing 33 changed files with 2,421 additions and 2,912 deletions.
Binary file modified frontend/public/outside.bin
Binary file not shown.
5,176 changes: 2,323 additions & 2,853 deletions frontend/public/outside.json

Large diffs are not rendered by default.

Binary file modified frontend/public/textures/bigtree_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fens_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed frontend/public/textures/grassMain_Color.png
Binary file not shown.
Binary file removed frontend/public/textures/grassMain_MRA.png
Binary file not shown.
Binary file removed frontend/public/textures/grassMain_Normal.png
Binary file not shown.
Binary file added frontend/public/textures/grass_AC_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/textures/grass_AC_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/textures/grass_AC_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/ground_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/ground_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/ground_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/midGround_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/pineLeaves_AC_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/pineLeaves_AC_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/pineLeaves_AC_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/GameCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class GameCamera{


this.mouseTarget.lerp(mp, 0.1);
let cameraPositionMap = new Vector3(-this.mouseTarget.x * 2.0, GameModel.yMouseCenter + this.mouseTarget.y+1.5, 10);
let cameraPositionMap = new Vector3(-this.mouseTarget.x * 2.0, GameModel.yMouseCenter + this.mouseTarget.y, 10);
this.camera.cameraWorld = cameraPositionMap.clone();
this.camera.cameraWorld.x+=offsetX
//this.camera.cameraWorld.y-=1.5;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ImagePreloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import TextureLoader from "./lib/textures/TextureLoader";

let name = "textures/"+img+".png";
if(renderer.texturesByLabel[name]== undefined){
new TextureLoader(renderer,preloader,"textures/"+img+".png",{mipLevelCount:5});
new TextureLoader(renderer,preloader,"textures/"+img+".png",{mipLevelCount:6});
}
}
console.log(renderer.texturesByLabel)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ export default class Main {

this.room.makeTransParent();
this.outside.makeTransParent();
this.lightOutsidePass.lightGrave =this.outside.lightGrave;

//this.gBufferPass.modelRenderer =this.outside.modelRenderer;
this.shadowPass.init();
this.dofPass.init();
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/Outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class Outside {
root: Object3D
private renderer: Renderer;
private glFTLoader: GLFTLoader;
public lightGrave: Object3D;

constructor(renderer: Renderer, preloader: PreLoader) {

Expand All @@ -30,7 +31,7 @@ export default class Outside {

this.root = this.glFTLoader.root


this.lightGrave = this.glFTLoader.objectsByName["lightGrave"];
for (let m of this.glFTLoader.models) {
this.modelRenderer.addModel(m)

Expand All @@ -42,7 +43,7 @@ export default class Outside {
let pos =-GameModel.characterPos.x;


GameModel.dayNight =clamp((pos-13)/8,0,1);
GameModel.dayNight =clamp((pos-13)/5,0,1);
//GameModel.dayNight
// UI.LFloat('offset',0)
// this.glFTLoader.root.setPosition(this.renderer.ratio * 4 / 2 +UI.LFloat('offset',0), -1.5, 0)
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/PreloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export const preloadImages = [
"chartest_Color",
"chartest_MRA",
"chartest_Normal",
"clover_AC.010_Color",
"clover_AC.010_MRA",
"clover_AC.010_Normal",
"clover_AC_Color",
"clover_AC_MRA",
"clover_AC_Normal",
Expand Down Expand Up @@ -84,7 +81,9 @@ export const preloadImages = [
"grassBase_Color",
"grassBase_MRA",
"grassBase_Normal",

"grass_AC_Color",
"grass_AC_MRA",
"grass_AC_Normal",
"grinder_Color",
"grinder_MRA",
"grinder_Normal",
Expand Down Expand Up @@ -136,7 +135,6 @@ export const preloadImages = [
"paperWallLeft_Color",
"paperWallLeft_MRA",
"paperWallLeft_Normal",

"pineLeaves_AC_Color",
"pineLeaves_AC_MRA",
"pineLeaves_AC_Normal",
Expand Down Expand Up @@ -200,4 +198,4 @@ export const preloadImages = [
"wireTest_Color",
"wireTest_MRA",
"wireTest_Normal"
]
]
1 change: 1 addition & 0 deletions frontend/src/lib/textures/MipMapQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class MipMapQueue{
if(this.textures.length==0)return;
let texture = this.textures.pop()
let targetMips = texture.options.mipLevelCount;
if (targetMips==0)return;
if(texture.options.width !=texture.options.height){console.log("only squares");return;}
let maxMips =Math.log2(texture.options.width)-1;

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/textures/TextureLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default class TextureLoader extends Texture{
const imageBitmap = await createImageBitmap(await response.blob());
this.options.width = imageBitmap.width;
this.options.height = imageBitmap.height;
if(this.options.mipLevelCount>Math.log2(imageBitmap.height)-2){
this.options.mipLevelCount =Math.max(Math.log2(imageBitmap.height)-2,0);
console.log( this.options.mipLevelCount,imageBitmap.height )
}

this.options.usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT ;

this.make();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/renderPasses/AORenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class AORenderPass extends RenderPass{
format: TextureFormat.R8Unorm,
sampleCount: this.sampleCount,
scaleToCanvas: true,
sizeMultiplier:0.5,
sizeMultiplier:1,

usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
});
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/renderPasses/LightOutsideRenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import MainLight from "../MainLight";
import GlobalLightOutsideShader from "../shaders/GlobalLightOutsideShader";
import RenderSettings from "../RenderSettings";
import GameModel from "../GameModel";
import Object3D from "../lib/core/Object3D";

export default class LightOutsideRenderPass extends RenderPass {

Expand All @@ -49,11 +50,13 @@ export default class LightOutsideRenderPass extends RenderPass {
private bottomColorNight: ColorV = new ColorV( 0.01,0.40,1.00, 0.1*0.5);



private lightColor: ColorV = new ColorV( 0.85,0.75,0.55,1.00);
private lightStrength: number =3;



public sunDir =new Vector3(-0.172996,-0.694981,-0.697907);
public lightGrave: Object3D;


constructor(renderer: Renderer, target: RenderTexture) {
Expand Down Expand Up @@ -143,14 +146,26 @@ export default class LightOutsideRenderPass extends RenderPass {
UI.LColor("midLightNight", this.midColorNight)
UI.LColor("bottomLightNight", this.bottomColorNight)


UI.separator("Light")
this.lightColor.w =1;
UI.LColor("lightColor", this.lightColor)
this.lightColor.w=this.lightStrength = UI.LFloatSlider("strength Light", this.lightStrength , 0, 20);



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.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)
this.globalLightMaterial.uniforms.setUniform( "shadowMatrix",matrix);

this.globalLightMaterial.uniforms.setUniform("pointlightColor",this.lightColor);
this.globalLightMaterial.uniforms.setUniform("pointlightPos",this.lightGrave.getWorldPos());

UI.popWindow()
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/shaders/GBufferShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn mainFragment(@location(0) uv0: vec2f,@location(1) normal: vec3f,@location(2)
{
var output : GBufferOutput;
output.color = textureSample(colorTexture, mySampler, uv0);
if(output.color.w<0.5){discard;}
if(output.color.w<0.9){discard;}
var normalText = textureSample(normalTexture, mySampler, uv0).xyz* 2. - 1.;
Expand Down
58 changes: 18 additions & 40 deletions frontend/src/shaders/GlobalLightInsideShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Shader from "../lib/core/Shader";
import {ShaderType} from "../lib/core/ShaderTypes";
import DefaultTextures from "../lib/textures/DefaultTextures";
import {Vector3, Vector4} from "math.gl";
import {getWorldFromUVDepth} from "./ShaderChunks";
import {getWorldFromUVDepth, pointLight} from "./ShaderChunks";
import Camera from "../lib/Camera";
import {TextureViewDimension} from "../lib/WebGPUConstants";

Expand Down Expand Up @@ -110,6 +110,7 @@ fn GeometrySchlickGGX(NdotV:f32, roughness:f32)-> f32
${Camera.getShaderText(0)}
${this.getShaderUniforms(1)}
${getWorldFromUVDepth()}
${pointLight()}
@vertex
fn mainVertex( ${this.getShaderAttributes()} ) -> VertexOutput
{
Expand All @@ -128,6 +129,9 @@ fn mainVertex( ${this.getShaderAttributes()} ) -> VertexOutput
fn random(st : vec2f ) -> f32 {
return fract(sin(dot(st.xy, vec2f(12.9898, 78.233))) * 43758.5453123)-0.5;
}
@fragment
fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
{
Expand All @@ -149,7 +153,7 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
let uvPosAO = vec2<i32>(floor(uv0*textureSizeAO));
let ao = textureLoad(aoTexture, uvPosAO ,0).x ;
let l = dot(N,vec3(0,1.0,0));
let l = dot(N,vec3(0.0,1.0,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 color = albedo*light*ao*(1.0-mra.x) +albedo*pow(mra.z,2.0)*10.0;
Expand All @@ -158,26 +162,20 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
var dir = uniforms.lightPos.xyz-world;
/* let near =0.01;
let far =10.0;
var dd =(((1/distToLight)*(near*far))-far) /(near - far);
let shadow = textureSampleCompare(shadowCube, mySamplerComp,normalize(dir)+0.01, dd);
*/
var shadowColor =0.0;
let dirN = normalize(dir);
let distToLight=distance (uniforms.lightPos.xyz,world);
var shadowColor =0.0;
let dirN = normalize(dir);
let distToLight=distance (uniforms.lightPos.xyz,world);
let randomVec =normalize(vec3f(random(uv0),random(uv0.yx +vec2f(3.9333)),random(uv0.yx+vec2f(0.9))));
let tangent = normalize(randomVec - N * dot(randomVec, N));
let bitangent = cross(N, tangent);
let TBN = mat3x3<f32>(tangent, bitangent, N);
let randomVec =normalize(vec3f(random(uv0),random(uv0.yx +vec2f(3.9333)),random(uv0.yx+vec2f(0.9))));
let tangent = normalize(randomVec - N * dot(randomVec, N));
let bitangent = cross(N, tangent);
let TBN = mat3x3<f32>(tangent, bitangent, N);
for(var i=0;i<16;i++){
let distToLightL=distance (uniforms.lightPos.xyz,world);
let shadowDist = textureSample(shadowCubeDebug, mySampler,normalize(dirN +TBN*kernel[i])).x;
if(shadowDist>distToLightL-0.05){shadowColor +=1.0;};
Expand All @@ -187,37 +185,17 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
if(shadowColor==0.0)
{
// return vec4(color,1.0);
}
let roughness = mra.y;
let metallic = mra.x;
let V = normalize(camera.worldPosition.xyz - world);
let F0 = mix(vec3(0.04), albedo, metallic);
let lightVec = uniforms.lightPos.xyz - world;
let L = normalize(lightVec);
let H = normalize(V + L);
let NdotV = max(0.0, dot(N, V));
let NDF = DistributionGGX(N, H, roughness);
let G = GeometrySmith(N, V, L, roughness);
let F = fresnelSchlick(max(dot(H, V), 0.0), F0);
let kS = F;
let kD = vec3(1.0) - kS;
let numerator = NDF * G * F;
let denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;
let specular = numerator / denominator;
let an =1.0/pow( distToLight,2.0);
let radiance =uniforms.lightColor.xyz *uniforms.lightColor.w*an;
let NdotL = max(dot(N, L), 0.0);
let lightL= (kD * albedo / PI + specular) * radiance * NdotL *shadowColor;
let lightL = pointLight(uniforms.lightPos.xyz,uniforms.lightColor,albedo,world,N,V,F0,roughness)*shadowColor;
return vec4(color+lightL,0.0) ;
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/shaders/GlobalLightOutsideShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Shader from "../lib/core/Shader";
import {ShaderType} from "../lib/core/ShaderTypes";
import DefaultTextures from "../lib/textures/DefaultTextures";
import {Vector3, Vector4} from "math.gl";
import {getWorldFromUVDepth} from "./ShaderChunks";
import {getWorldFromUVDepth, pointLight} from "./ShaderChunks";
import Camera from "../lib/Camera";
import {TextureViewDimension} from "../lib/WebGPUConstants";

Expand All @@ -22,6 +22,8 @@ export default class GlobalLightOutsideShader extends Shader{
this.addUniform("shadowMatrix",0,GPUShaderStage.FRAGMENT,ShaderType.mat4)
this.addUniform("lightDir",new Vector4(1,0.7,0.7,0.1))
this.addUniform("lightColor",new Vector4(1,0.7,0.7,0.1))
this.addUniform("pointlightColor",new Vector4(1,0.7,0.7,0.1))
this.addUniform("pointlightPos",new Vector4(1,0.7,0.7,0.1))
this.addUniform("topColor",new Vector4(1,0.7,0.7,0.1))
this.addUniform("midColor",new Vector4(1,1,1,0.05))
this.addUniform("bottomColor",new Vector4(1,1,1,0.02))
Expand Down Expand Up @@ -111,6 +113,7 @@ fn GeometrySchlickGGX(NdotV:f32, roughness:f32)-> f32
${Camera.getShaderText(0)}
${this.getShaderUniforms(1)}
${getWorldFromUVDepth()}
${pointLight()}
@vertex
fn mainVertex( ${this.getShaderAttributes()} ) -> VertexOutput
{
Expand Down Expand Up @@ -195,12 +198,12 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
let radiance =uniforms.lightColor.xyz *uniforms.lightColor.w;
let NdotL = max(dot(N, L), 0.0);
let lightL= (kD * albedo / PI + specular) * radiance * NdotL ;
let lightL= (kD * albedo / PI + specular) * radiance * NdotL *shadowVal;
let lightP = pointLight(uniforms.pointlightPos.xyz,uniforms.pointlightColor,albedo,world,N,V,F0,roughness);
return vec4(color+lightL*shadowVal*ao,smoothstep(uniforms.dof.x,uniforms.dof.y,depth) );
//return vec4( color,smoothstep(uniforms.dof.x,uniforms.dof.y,depth) );
return vec4(color+(lightL+lightP)*ao,smoothstep(uniforms.dof.x,uniforms.dof.y,depth) );
}
///////////////////////////////////////////////////////////
`
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/shaders/ShaderChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,39 @@ fn ssr(world:vec3f,N:vec3f,V:vec3f,metallic:f32,roughness:f32,textureSize:vec2f)
}
`
}

export function pointLight(){
return /* wgsl */ `
fn pointLight(lightPos:vec3f ,lightColor:vec4f,albedo:vec3f,world:vec3f,N:vec3f,V:vec3f,F0:vec3f,roughness:f32)->vec3f
{ let distToLight=distance (lightPos.xyz,world);
let lightVec = lightPos - world;
let L = normalize(lightVec);
let H = normalize(V + L);
let NdotV = max(0.0, dot(N, V));
let NDF = DistributionGGX(N, H, roughness);
let G = GeometrySmith(N, V, L, roughness);
let F = fresnelSchlick(max(dot(H, V), 0.0), F0);
let kS = F;
let kD = vec3(1.0) - kS;
let numerator = NDF * G * F;
let denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;
let specular = numerator / denominator;
let an =1.0/pow( distToLight,2.0);
let radiance =lightColor.xyz *lightColor.w*an;
let NdotL = max(dot(N, L), 0.0);
let lightL= (kD * albedo / PI + specular) * radiance * NdotL ;
return lightL;
}
`
}

0 comments on commit b1efca6

Please sign in to comment.