-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from pixiv/fix-rim-lighting
[1.0] Fix rim lighting
- Loading branch information
Showing
5 changed files
with
156 additions
and
96 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
24 changes: 24 additions & 0 deletions
24
packages/three-vrm-materials-mtoon/src/utils/getEncodingComponents.ts
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,24 @@ | ||
import * as THREE from 'three'; | ||
|
||
export const getEncodingComponents = (encoding: THREE.TextureEncoding): [string, string] => { | ||
switch (encoding) { | ||
case THREE.LinearEncoding: | ||
return ['Linear', '( value )']; | ||
case THREE.sRGBEncoding: | ||
return ['sRGB', '( value )']; | ||
case THREE.RGBEEncoding: | ||
return ['RGBE', '( value )']; | ||
case THREE.RGBM7Encoding: | ||
return ['RGBM', '( value, 7.0 )']; | ||
case THREE.RGBM16Encoding: | ||
return ['RGBM', '( value, 16.0 )']; | ||
case THREE.RGBDEncoding: | ||
return ['RGBD', '( value, 256.0 )']; | ||
case THREE.GammaEncoding: | ||
return ['Gamma', '( value, float( GAMMA_FACTOR ) )']; | ||
case THREE.LogLuvEncoding: | ||
return ['LogLuv', '( value )']; | ||
default: | ||
throw new Error('unsupported encoding: ' + encoding); | ||
} | ||
}; |
22 changes: 1 addition & 21 deletions
22
packages/three-vrm-materials-mtoon/src/utils/getTexelDecodingFunction.ts
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
36 changes: 36 additions & 0 deletions
36
packages/three-vrm-materials-mtoon/src/utils/getTextureEncodingFromMap.ts
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,36 @@ | ||
import * as THREE from 'three'; | ||
|
||
/** | ||
* Retrieved from https://github.com/mrdoob/three.js/blob/88b6328998d155fa0a7c1f1e5e3bd6bff75268c0/src/renderers/webgl/WebGLPrograms.js#L92 | ||
* | ||
* Diff: | ||
* - Remove WebGLRenderTarget handler because it increases code complexities on TypeScript | ||
* - Add a boolean `isWebGL2` as a second argument. | ||
*/ | ||
export function getTextureEncodingFromMap(map: THREE.Texture, isWebGL2: boolean): THREE.TextureEncoding { | ||
let encoding; | ||
|
||
if (map && map.isTexture) { | ||
encoding = map.encoding; | ||
// } else if ( map && map.isWebGLRenderTarget ) { | ||
// console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' ); | ||
// encoding = map.texture.encoding; | ||
} else { | ||
encoding = THREE.LinearEncoding; | ||
} | ||
|
||
if (parseInt(THREE.REVISION, 10) >= 133) { | ||
if ( | ||
isWebGL2 && | ||
map && | ||
map.isTexture && | ||
map.format === THREE.RGBAFormat && | ||
map.type === THREE.UnsignedByteType && | ||
map.encoding === THREE.sRGBEncoding | ||
) { | ||
encoding = THREE.LinearEncoding; // disable inline decode for sRGB textures in WebGL 2 | ||
} | ||
} | ||
|
||
return encoding; | ||
} |