-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Material Type For Threejs #28543
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,16 @@ | ||
import { MeshLambertMaterial } from './MeshLambertMaterial'; | ||
|
||
class MeshSphereLambertMaterial extends MeshLambertMaterial { | ||
|
||
constructor( parameters ) { | ||
|
||
super( parameters ); | ||
this.type = 'MeshSphereLambertMaterial'; | ||
this.isMeshLambertMaterial = false; | ||
this.isMeshSphereLambertMaterial = true; | ||
|
||
} | ||
|
||
} | ||
|
||
export { MeshSphereLambertMaterial }; |
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
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
5 changes: 5 additions & 0 deletions
5
src/renderers/shaders/ShaderChunk/lights_spherelambert_fragment.glsl.js
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,5 @@ | ||
export default /* glsl */` | ||
LambertMaterial material; | ||
material.diffuseColor = diffuseColor.rgb; | ||
material.specularStrength = specularStrength; | ||
`; |
77 changes: 77 additions & 0 deletions
77
src/renderers/shaders/ShaderChunk/lights_spherelambert_pars_fragment.glsl.js
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,77 @@ | ||
export default /* glsl */` | ||
varying vec3 vViewPosition; | ||
|
||
struct LambertMaterial { | ||
|
||
vec3 diffuseColor; | ||
float specularStrength; | ||
|
||
}; | ||
float safeacos(const float x) { | ||
return acos(clamp(x, -1.0, 1.0)); | ||
} | ||
|
||
float phase(float u) { | ||
return (2.0*(sqrt(1.0 - u*u) - u*acos(u)))/(3.0*PI*PI); | ||
} | ||
vec3 shadeLambertianSphereBRDF(vec3 wi, vec3 wo, vec3 norm,vec3 kd) { | ||
|
||
float ui = dot(wi, norm); | ||
float uo = dot(wo, norm); | ||
if (ui < 0.0 || uo < 0.0) return vec3(0.0); | ||
|
||
float uIuO = ui*uo; | ||
vec3 c = (1.0 - pow(1.0 - kd, vec3(2.73556))) / (1.0 - 0.184096*pow(1.0 - kd, vec3(2.48423))); | ||
float minusiodot = -dot(wi, wo); | ||
float ui2 = ui*ui; | ||
float uo2 = uo*uo; | ||
float S = sqrt((1.0-ui2)*(1.0-uo2)); | ||
float cp = -((minusiodot + uIuO)/S); | ||
float phi = safeacos(cp); | ||
|
||
|
||
// Single-Scattering component, corresponds to "f_1" in the paper. | ||
vec3 SS = c*(phase(minusiodot) / (ui + uo)); | ||
|
||
// The block is a literal coding of Equation 48 from the paper. | ||
|
||
vec3 fr = max( | ||
vec3(0.0), | ||
SS + 0.234459*pow(kd, vec3(1.85432)) \ | ||
+ (0.0151829*(c-0.24998)*(abs(phi)+sqrt(uIuO))) / (0.113706 + (safeacos(S)/S)) | ||
); | ||
return PI * uo * fr; | ||
|
||
} | ||
/* struct IncidentLight { | ||
vec3 direction; | ||
}; | ||
|
||
struct ReflectedLight { | ||
vec3 directDiffuse; | ||
vec3 directSpecular; | ||
vec3 indirectDiffuse; | ||
vec3 indirectSpecular; | ||
}; */ | ||
void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { | ||
|
||
|
||
vec3 kd = material.diffuseColor; | ||
vec3 wo = directLight.direction; | ||
vec3 wi = geometryViewDir; | ||
vec3 color = shadeLambertianSphereBRDF(wi,wo,geometryNormal,kd); | ||
reflectedLight.directDiffuse += color; // no need to multiply with BRDF_Lambert( material.diffuseColor ); | ||
|
||
} | ||
|
||
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { | ||
|
||
|
||
|
||
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); | ||
|
||
} | ||
|
||
#define RE_Direct RE_Direct_Lambert | ||
#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert | ||
`; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.