forked from equinor/webviz-subsurface-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Fix of [NGRM] - move shader code to local shader module equ…
- Loading branch information
Showing
6 changed files
with
60 additions
and
45 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
1 change: 1 addition & 0 deletions
1
typescript/packages/subsurface-viewer/src/layers/shader_modules/index.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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as decoder } from "./decoder"; | ||
export { default as localPhongLighting } from "./localPhongLighting"; |
46 changes: 46 additions & 0 deletions
46
typescript/packages/subsurface-viewer/src/layers/shader_modules/lighting.fs.glsl.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,46 @@ | ||
const fs = ` | ||
// Note: modification of luma.gl's functions to get two sided phong lighting. | ||
// Ref original file modules/shadertools/src/modules/phong-lighting/phong-lighting.glsl.ts in luma source. | ||
vec3 getPhongLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) { | ||
vec3 halfway_direction = normalize(light_direction + view_direction); | ||
float lambertian = abs(dot(light_direction, normal_worldspace)); | ||
float specular_angle = abs(dot(normal_worldspace, halfway_direction)); | ||
float specular = pow(specular_angle, lighting_uShininess); | ||
return (lambertian * lighting_uDiffuse * surfaceColor + specular * lighting_uSpecularColor) * color; | ||
} | ||
vec3 getPhongLightColor(vec3 surfaceColor,vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) { | ||
vec3 lightColor = surfaceColor; | ||
if (lighting_uEnabled) { | ||
vec3 view_direction = normalize(cameraPosition - position_worldspace); | ||
lightColor = lighting_uAmbient * surfaceColor * lighting_uAmbientLight.color; | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting_uPointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_uPointLight[i]; | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += getPhongLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting_uDirectionalLightCount) { | ||
break; | ||
} | ||
DirectionalLight directionalLight = lighting_uDirectionalLight[i]; | ||
lightColor += getPhongLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
return lightColor; | ||
} | ||
`; | ||
|
||
export default fs; |
8 changes: 8 additions & 0 deletions
8
typescript/packages/subsurface-viewer/src/layers/shader_modules/localPhongLighting.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,8 @@ | ||
import fs from "./lighting.fs.glsl"; | ||
import { phongLighting } from "@luma.gl/shadertools"; | ||
|
||
export default { | ||
name: "localPhongLighting", | ||
fs, | ||
dependencies: [phongLighting], | ||
}; |
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