Skip to content

Commit

Permalink
✨ Add day and night mode
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosimon committed Sep 5, 2021
1 parent c585d55 commit 8b77efa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
22 changes: 18 additions & 4 deletions src/Experience/Baked.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export default class CoffeeSteam

this.model.mesh = this.resources.items.roomModel.scene.children[0]

this.model.bakedTexture = this.resources.items.bakedTexture
this.model.bakedTexture.encoding = THREE.sRGBEncoding
this.model.bakedTexture.flipY = false
this.model.bakedDayTexture = this.resources.items.bakedDayTexture
this.model.bakedDayTexture.encoding = THREE.sRGBEncoding
this.model.bakedDayTexture.flipY = false

this.model.bakedNightTexture = this.resources.items.bakedNightTexture
this.model.bakedNightTexture.encoding = THREE.sRGBEncoding
this.model.bakedNightTexture.flipY = false

this.model.lightMapTexture = this.resources.items.lightMapTexture
this.model.lightMapTexture.flipY = false
Expand All @@ -47,9 +51,12 @@ export default class CoffeeSteam
this.model.material = new THREE.ShaderMaterial({
uniforms:
{
uBakedTexture: { value: this.model.bakedTexture },
uBakedDayTexture: { value: this.model.bakedDayTexture },
uBakedNightTexture: { value: this.model.bakedNightTexture },
uLightMapTexture: { value: this.model.lightMapTexture },

uMix: { value: 1 },

uLightTvColor: { value: new THREE.Color(this.colors.tv) },
uLightTvStrength: { value: 1.47 },

Expand All @@ -76,6 +83,13 @@ export default class CoffeeSteam
// Debug
if(this.debug)
{
this.debugFolder
.addInput(
this.model.material.uniforms.uMix,
'value',
{ label: 'uMix', min: 0, max: 1 }
)

this.debugFolder
.addInput(
this.colors,
Expand Down
3 changes: 2 additions & 1 deletion src/Experience/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default [

{ name: 'macScreenModel', source: '/assets/macScreenModel.glb', type: 'model' },

{ name: 'bakedTexture', source: '/assets/baked.jpg', type: 'texture' },
{ name: 'bakedDayTexture', source: '/assets/bakedDay.jpg', type: 'texture' },
{ name: 'bakedNightTexture', source: '/assets/bakedNight.jpg', type: 'texture' },
{ name: 'lightMapTexture', source: '/assets/lightMap.jpg', type: 'texture' },
{ name: 'roomModel', source: '/assets/roomModel.glb' },
]
Expand Down
9 changes: 7 additions & 2 deletions src/Experience/shaders/baked/fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
uniform sampler2D uBakedTexture;
uniform sampler2D uBakedDayTexture;
uniform sampler2D uBakedNightTexture;
uniform sampler2D uLightMapTexture;

uniform float uMix;

uniform vec3 uLightTvColor;
uniform float uLightTvStrength;

Expand All @@ -19,7 +22,9 @@ varying vec2 vUv;

void main()
{
vec3 bakedColor = texture2D(uBakedTexture, vUv).rgb;
vec3 bakedDayColor = texture2D(uBakedDayTexture, vUv).rgb;
vec3 bakedNightColor = texture2D(uBakedNightTexture, vUv).rgb;
vec3 bakedColor = mix(bakedDayColor, bakedNightColor, uMix);
vec3 lightMapColor = texture2D(uLightMapTexture, vUv).rgb;

float lightTvStrength = lightMapColor.r * uLightTvStrength;
Expand Down
Binary file added static/assets/bakedDay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes

1 comment on commit 8b77efa

@vercel
Copy link

@vercel vercel bot commented on 8b77efa Sep 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.