Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
32 changes: 21 additions & 11 deletions
32
modules/mesh-layers/src/simple-mesh-layer/simple-mesh-layer-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 |
---|---|---|
@@ -1,27 +1,37 @@ | ||
export default ` | ||
export default `#version 300 es | ||
#define SHADER_NAME simple-mesh-layer-fs | ||
precision highp float; | ||
uniform bool hasTexture; | ||
uniform sampler2D sampler; | ||
uniform vec4 color; | ||
uniform bool flatShading; | ||
varying vec2 vTexCoord; | ||
varying vec3 cameraPosition; | ||
varying vec3 normals_commonspace; | ||
varying vec4 position_commonspace; | ||
varying vec4 vColor; | ||
in vec2 vTexCoord; | ||
in vec3 cameraPosition; | ||
in vec3 normals_commonspace; | ||
in vec4 position_commonspace; | ||
in vec4 vColor; | ||
out vec4 fragColor; | ||
void main(void) { | ||
vec4 color = hasTexture ? texture2D(sampler, vTexCoord) : vColor / 255.; | ||
vec3 lightColor = lighting_getLightColor(color.rgb * 255., cameraPosition, position_commonspace.xyz, normals_commonspace); | ||
gl_FragColor = vec4(lightColor / 255., color.a); | ||
vec3 normal; | ||
if (flatShading) { | ||
normal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz))); | ||
} else { | ||
normal = normals_commonspace; | ||
} | ||
vec4 color = hasTexture ? texture(sampler, vTexCoord) : vColor / 255.; | ||
vec3 lightColor = lighting_getLightColor(color.rgb * 255., cameraPosition, position_commonspace.xyz, normal); | ||
fragColor = vec4(lightColor / 255., color.a); | ||
// use highlight color if this fragment belongs to the selected object. | ||
gl_FragColor = picking_filterHighlightColor(gl_FragColor); | ||
fragColor = picking_filterHighlightColor(fragColor); | ||
// use picking color if rendering to picking FBO. | ||
gl_FragColor = picking_filterPickingColor(gl_FragColor); | ||
fragColor = picking_filterPickingColor(fragColor); | ||
} | ||
`; |
35 changes: 35 additions & 0 deletions
35
modules/mesh-layers/src/simple-mesh-layer/simple-mesh-layer-fragment.glsl1.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,35 @@ | ||
export default ` | ||
#define SHADER_NAME simple-mesh-layer-fs | ||
precision highp float; | ||
uniform bool hasTexture; | ||
uniform sampler2D sampler; | ||
uniform vec4 color; | ||
uniform bool flatShading; | ||
varying vec2 vTexCoord; | ||
varying vec3 cameraPosition; | ||
varying vec3 normals_commonspace; | ||
varying vec4 position_commonspace; | ||
varying vec4 vColor; | ||
void main(void) { | ||
vec3 normal; | ||
if (flatShading) { | ||
normal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz))); | ||
} else { | ||
normal = normals_commonspace; | ||
} | ||
vec4 color = hasTexture ? texture2D(sampler, vTexCoord) : vColor / 255.; | ||
vec3 lightColor = lighting_getLightColor(color.rgb * 255., cameraPosition, position_commonspace.xyz, normal); | ||
gl_FragColor = vec4(lightColor / 255., color.a); | ||
// use highlight color if this fragment belongs to the selected object. | ||
gl_FragColor = picking_filterHighlightColor(gl_FragColor); | ||
// use picking color if rendering to picking FBO. | ||
gl_FragColor = picking_filterPickingColor(gl_FragColor); | ||
} | ||
`; |
30 changes: 15 additions & 15 deletions
30
modules/mesh-layers/src/simple-mesh-layer/simple-mesh-layer-vertex.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
40 changes: 40 additions & 0 deletions
40
modules/mesh-layers/src/simple-mesh-layer/simple-mesh-layer-vertex.glsl1.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,40 @@ | ||
export default ` | ||
#define SHADER_NAME simple-mesh-layer-vs | ||
// Scale the model | ||
uniform float sizeScale; | ||
// Primitive attributes | ||
attribute vec3 positions; | ||
attribute vec3 normals; | ||
attribute vec2 texCoords; | ||
// Instance attributes | ||
attribute vec3 instancePositions; | ||
attribute vec2 instancePositions64xy; | ||
attribute vec4 instanceColors; | ||
attribute vec3 instancePickingColors; | ||
attribute mat3 instanceModelMatrix; | ||
attribute vec3 instanceTranslation; | ||
// Outputs to fragment shader | ||
varying vec2 vTexCoord; | ||
varying vec3 cameraPosition; | ||
varying vec3 normals_commonspace; | ||
varying vec4 position_commonspace; | ||
varying vec4 vColor; | ||
void main(void) { | ||
vec3 pos = (instanceModelMatrix * positions) * sizeScale + instanceTranslation; | ||
pos = project_size(pos); | ||
vTexCoord = texCoords; | ||
cameraPosition = project_uCameraPosition; | ||
normals_commonspace = project_normal(instanceModelMatrix * normals); | ||
vColor = instanceColors; | ||
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64xy, pos, position_commonspace); | ||
picking_setPickingColor(instancePickingColors); | ||
} | ||
`; |
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