Skip to content
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

color and normal blocks are executed regardless of lighting mode #647

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/resources/scene.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ styles:
lighting: vertex
shaders:
blocks:
color: "color.rgb += vec3(position.z / 800.);"
color: "color.rgb += vec3(worldPosition().z / 800.);"
heightglowline:
base: lines
mix: heightglow
Expand Down
24 changes: 13 additions & 11 deletions core/resources/shaders/polygon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ varying vec3 v_normal;
#pragma tangram: lighting
#pragma tangram: global

vec4 worldPosition() {
return v_world_position;
}

vec3 worldNormal() {
return normalize(u_inverse_normal_matrix * v_normal);
}
Expand All @@ -57,20 +61,18 @@ void main(void) {
calculateNormal(normal);
#endif

// Modify normal before lighting
#pragma tangram: normal

// Modify color and material properties before lighting
#ifndef TANGRAM_LIGHTING_VERTEX
#pragma tangram: color
// Modify normal before lighting if not already modified in vertex shader
#if !defined(TANGRAM_LIGHTING_VERTEX)
#pragma tangram: normal
#endif

#ifdef TANGRAM_LIGHTING_FRAGMENT
// Modify color before lighting is applied
#pragma tangram: color

#if defined(TANGRAM_LIGHTING_FRAGMENT)
color = calculateLighting(v_position.xyz, normal, color);
#else
#ifdef TANGRAM_LIGHTING_VERTEX
color = v_lighting;
#endif
#elif defined(TANGRAM_LIGHTING_VERTEX)
color *= v_lighting;
#endif

// Modify color after lighting (filter-like effects that don't require a additional render passes)
Expand Down
13 changes: 3 additions & 10 deletions core/resources/shaders/polygon.vs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,12 @@ void main() {
// Set position varying to the camera-space vertex position
v_position = u_view * position;

#ifdef TANGRAM_LIGHTING_VERTEX
vec4 color = v_color;
vec3 normal = v_normal;

#if defined(TANGRAM_LIGHTING_VERTEX)
// Modify normal before lighting
vec3 normal = v_normal;
#pragma tangram: normal

// Modify color and material properties before lighting
#pragma tangram: color

v_lighting = calculateLighting(v_position.xyz, normal, color);
v_color = color;
v_normal = normal;
v_lighting = calculateLighting(v_position.xyz, normal, vec4(1.));
#endif

gl_Position = u_proj * v_position;
Expand Down
24 changes: 13 additions & 11 deletions core/resources/shaders/polyline.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ varying vec3 v_normal;
varying vec4 v_lighting;
#endif

vec4 worldPosition() {
return v_world_position;
}

vec3 worldNormal() {
return normalize(u_inverse_normal_matrix * v_normal);
}
Expand All @@ -57,20 +61,18 @@ void main(void) {
calculateNormal(normal);
#endif

// Modify normal before lighting
#pragma tangram: normal

// Modify color and material properties before lighting
#ifndef TANGRAM_LIGHTING_VERTEX
#pragma tangram: color
// Modify normal before lighting if not already modified in vertex shader
#if !defined(TANGRAM_LIGHTING_VERTEX)
#pragma tangram: normal
#endif

#ifdef TANGRAM_LIGHTING_FRAGMENT
// Modify color before lighting is applied
#pragma tangram: color

#if defined(TANGRAM_LIGHTING_FRAGMENT)
color = calculateLighting(v_position.xyz, normal, color);
#else
#ifdef TANGRAM_LIGHTING_VERTEX
color = v_lighting;
#endif
#elif defined(TANGRAM_LIGHTING_VERTEX)
color *= v_lighting;
#endif

// Modify color after lighting (filter-like effects that don't require a additional render passes)
Expand Down
11 changes: 2 additions & 9 deletions core/resources/shaders/polyline.vs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,11 @@ void main() {
v_position = u_view * position;

#ifdef TANGRAM_LIGHTING_VERTEX
vec4 color = v_color;
vec3 normal = v_normal;

// Modify normal before lighting
vec3 normal = v_normal;
#pragma tangram: normal

// Modify color and material properties before lighting
#pragma tangram: color

v_lighting = calculateLighting(v_position.xyz, normal, color);
v_color = color;
v_normal = normal;
v_lighting = calculateLighting(v_position.xyz, normal, vec4(1.));
#endif

gl_Position = u_proj * v_position;
Expand Down