Skip to content

Commit

Permalink
💄 Baked > Improve light blending
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosimon committed Sep 5, 2021
1 parent c295e64 commit c585d55
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"license": "UNLICENSED",
"scripts": {
"build": "webpack --config ./bundler/webpack.prod.js",
"dev": "webpack serve --config ./bundler/webpack.dev.js"
"dev": "webpack serve --config ./bundler/webpack.dev.js",
"prod": "git switch prod; git merge main; git push; git switch main"
},
"dependencies": {
"@babel/core": "^7.14.6",
Expand All @@ -13,6 +14,7 @@
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^5.2.6",
"file-loader": "^6.2.0",
"glsl-blend": "^1.0.3",
"glslify-loader": "^2.0.0",
"gsap": "^3.7.1",
"html-loader": "^2.1.2",
Expand Down
10 changes: 5 additions & 5 deletions src/Experience/Baked.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export default class CoffeeSteam
this.model.lightMapTexture.flipY = false

this.colors = {}
this.colors.tv = '#de11ff'
this.colors.desk = '#ff7c00'
this.colors.pc = '#4cbdff'
this.colors.tv = '#ff115e'
this.colors.desk = '#ff9b00'
this.colors.pc = '#0082ff'

this.model.material = new THREE.ShaderMaterial({
uniforms:
Expand All @@ -54,10 +54,10 @@ export default class CoffeeSteam
uLightTvStrength: { value: 1.47 },

uLightDeskColor: { value: new THREE.Color(this.colors.desk) },
uLightDeskStrength: { value: 1.86 },
uLightDeskStrength: { value: 1.36 },

uLightPcColor: { value: new THREE.Color(this.colors.pc) },
uLightPcStrength: { value: 1.27 }
uLightPcStrength: { value: 1.4 }
},
vertexShader: vertexShader,
fragmentShader: fragmentShader
Expand Down
15 changes: 10 additions & 5 deletions src/Experience/shaders/baked/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ uniform float uLightPcStrength;

varying vec2 vUv;

// #pragma glslify: blend = require(glsl-blend/add)
#pragma glslify: blend = require(glsl-blend/lighten)
// #pragma glslify: blend = require(glsl-blend/normal)
// #pragma glslify: blend = require(glsl-blend/screen)

void main()
{
vec3 bakedColor = texture2D(uBakedTexture, vUv).rgb;
vec3 lightMapColor = texture2D(uLightMapTexture, vUv).rgb;

float lightTvStrength = lightMapColor.r * uLightTvStrength;
bakedColor = mix(bakedColor, uLightTvColor, lightTvStrength);

float lightDeskStrength = lightMapColor.g * uLightDeskStrength;
bakedColor = mix(bakedColor, uLightDeskColor, lightDeskStrength);
bakedColor = blend(bakedColor, uLightTvColor, lightTvStrength);

float lightPcStrength = lightMapColor.b * uLightPcStrength;
bakedColor = mix(bakedColor, uLightPcColor, lightPcStrength);
bakedColor = blend(bakedColor, uLightPcColor, lightPcStrength);

float lightDeskStrength = lightMapColor.g * uLightDeskStrength;
bakedColor = blend(bakedColor, uLightDeskColor, lightDeskStrength);

gl_FragColor = vec4(bakedColor, 1.0);
}

0 comments on commit c585d55

Please sign in to comment.