-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
832 additions
and
120 deletions.
There are no files selected for viewing
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,91 @@ | ||
import RenderTexture from "./lib/textures/RenderTexture"; | ||
import ColorAttachment from "./lib/textures/ColorAttachment"; | ||
import {TextureFormat} from "./lib/WebGPUConstants"; | ||
import DepthStencilAttachment from "./lib/textures/DepthStencilAttachment"; | ||
import RenderPass from "./lib/core/RenderPass"; | ||
import Renderer from "./lib/Renderer"; | ||
import ModelRenderer from "./lib/model/ModelRenderer"; | ||
|
||
|
||
|
||
export default class extends RenderPass { | ||
|
||
public modelRenderer: ModelRenderer; | ||
public colorTarget: RenderTexture; | ||
public depthTarget: RenderTexture; | ||
public normalTarget: RenderTexture; | ||
public mraTarget: RenderTexture; | ||
private colorAttachment: ColorAttachment; | ||
private normalAttachment: ColorAttachment; | ||
private mraAttachment: ColorAttachment; | ||
private positionTarget: RenderTexture; | ||
private positionAttachment: ColorAttachment; | ||
|
||
|
||
constructor(renderer: Renderer) { | ||
|
||
super(renderer, "GbufferRenderPass"); | ||
|
||
this.modelRenderer = new ModelRenderer(renderer) | ||
|
||
this.colorTarget = new RenderTexture(renderer, "GColor", { | ||
format: TextureFormat.RGBA8Unorm, | ||
sampleCount: this.sampleCount, | ||
scaleToCanvas: true, | ||
|
||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.colorAttachment = new ColorAttachment(this.colorTarget); | ||
|
||
|
||
this.normalTarget = new RenderTexture(renderer, "GNormal", { | ||
format: TextureFormat.RGBA8Unorm, | ||
sampleCount: this.sampleCount, | ||
scaleToCanvas: true, | ||
|
||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.normalAttachment = new ColorAttachment(this.normalTarget); | ||
|
||
this.mraTarget = new RenderTexture(renderer, "GMRA", { | ||
format: TextureFormat.RGBA8Unorm, | ||
sampleCount: this.sampleCount, | ||
scaleToCanvas: true, | ||
|
||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.mraAttachment = new ColorAttachment(this.mraTarget); | ||
|
||
|
||
|
||
this.positionTarget = new RenderTexture(renderer, "GPosition", { | ||
format: TextureFormat.RGBA16Float, | ||
sampleCount: this.sampleCount, | ||
scaleToCanvas: true, | ||
|
||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.positionAttachment = new ColorAttachment(this.positionTarget); | ||
|
||
this.colorAttachments = [this.colorAttachment, this.normalAttachment, this.mraAttachment, this.positionAttachment]; | ||
|
||
|
||
this.depthTarget = new RenderTexture(renderer, "GDepth", { | ||
format: TextureFormat.Depth16Unorm, | ||
sampleCount: 1, | ||
scaleToCanvas: true, | ||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.depthStencilAttachment = new DepthStencilAttachment(this.depthTarget); | ||
|
||
|
||
} | ||
|
||
draw() { | ||
|
||
this.modelRenderer.draw(this); | ||
|
||
|
||
} | ||
|
||
} |
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,90 @@ | ||
import RenderPass from "./lib/core/RenderPass"; | ||
import ModelRenderer from "./lib/model/ModelRenderer"; | ||
import RenderTexture from "./lib/textures/RenderTexture"; | ||
import ColorAttachment from "./lib/textures/ColorAttachment"; | ||
import Renderer from "./lib/Renderer"; | ||
import {LoadOp, StoreOp, TextureFormat} from "./lib/WebGPUConstants"; | ||
import DepthStencilAttachment from "./lib/textures/DepthStencilAttachment"; | ||
import Model from "./lib/model/Model"; | ||
import Material from "./lib/core/Material"; | ||
import LightShader from "./shaders/LightShader"; | ||
import Sphere from "./lib/meshes/Sphere"; | ||
import {Vector2, Vector3, Vector4} from "math.gl"; | ||
import {IResizable} from "./lib/IResizable"; | ||
import Timer from "./lib/Timer"; | ||
|
||
export default class extends RenderPass implements IResizable { | ||
|
||
|
||
public target: RenderTexture; | ||
private colorAttachment: ColorAttachment; | ||
private modelRenderer:ModelRenderer | ||
private shader:LightShader | ||
private material: Material; | ||
private mesh: Sphere; | ||
private model: Model; | ||
|
||
|
||
constructor(renderer: Renderer) { | ||
|
||
super(renderer, "LightRenderPass"); | ||
this.target = new RenderTexture(renderer, "LightPass", { | ||
format: TextureFormat.RGBA8Unorm, | ||
sampleCount: this.sampleCount, | ||
scaleToCanvas: true, | ||
|
||
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | ||
}); | ||
this.colorAttachment= new ColorAttachment(this.target); | ||
this.colorAttachments = [this.colorAttachment]; | ||
|
||
|
||
this.depthStencilAttachment = new DepthStencilAttachment(this.renderer.texturesByLabel["GDepth"] as RenderTexture,{ depthLoadOp: LoadOp.Load, | ||
depthStoreOp: StoreOp.Store, | ||
depthReadOnly: true}); | ||
|
||
|
||
this.modelRenderer =new ModelRenderer(renderer) | ||
this.shader =new LightShader(renderer,"lightShader"); | ||
this.mesh =new Sphere(renderer); | ||
|
||
|
||
|
||
this.material =new Material(renderer,"testLight",this.shader) | ||
this.material.depthWrite =false; | ||
this.model =new Model(renderer,"testLight"); | ||
|
||
let radius =3; | ||
let position =new Vector3(-1,1,-2) | ||
this.model.setPosition(position.x,position.y,position.z) | ||
this.model.setScale(radius,radius,radius) | ||
this.model.material =this.material; | ||
this.model.mesh =this.mesh; | ||
|
||
this.model.material.uniforms.setUniform("position",new Vector4(position.x,position.y,position.z,radius)) | ||
|
||
this.material.uniforms.setTexture("gPosition",this.renderer.texturesByLabel["GPosition"]) | ||
this.material.uniforms.setTexture("gNormal",this.renderer.texturesByLabel["GNormal"]) | ||
this.material.uniforms.setTexture("gMRA",this.renderer.texturesByLabel["GMRA"]) | ||
this.material.uniforms.setTexture("gColor",this.renderer.texturesByLabel["GColor"]) | ||
this.modelRenderer.addModel(this.model); | ||
|
||
|
||
} | ||
onScreenResize(size: Vector2) { | ||
this.material.uniforms.setUniform("textureSize",new Vector2(this.renderer.width,this.renderer.height)) | ||
} | ||
|
||
update() | ||
{ | ||
let position =new Vector3(Math.sin(Timer.time)*2.0,Math.cos(Timer.time*0.5),-2+Math.cos(Timer.time*0.3)*0.5) | ||
this.model.setPosition(position.x,position.y,position.z) | ||
this.model.material.uniforms.setUniform("position",new Vector4(position.x,position.y,position.z,3)) | ||
} | ||
draw() { | ||
|
||
this.modelRenderer.draw(this); | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.