-
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.
added shaders to render island with shadows
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
precision mediump float; | ||
|
||
varying vec2 pos; | ||
|
||
uniform sampler2D colorMap; | ||
uniform sampler2D heightMap; | ||
uniform float width; | ||
uniform vec3 lightDir; | ||
void main() { | ||
vec2 newPos = pos; | ||
newPos.y = 1. - newPos.y; | ||
vec4 col = texture2D(colorMap, newPos); | ||
float d = 1./width; | ||
vec2 posdx = newPos; | ||
posdx.x = posdx.x+d; | ||
vec2 posdy = newPos; | ||
posdy.y = posdy.y+d; | ||
float height = texture2D(heightMap, newPos).x*100.; | ||
float heightdx = texture2D(heightMap, posdx).x*100.; | ||
float heightdy = texture2D(heightMap, posdy).x*100.; | ||
vec3 unnormal = vec3((heightdx-height),(heightdy-height),1); | ||
vec3 normal = normalize(unnormal); | ||
float brightness = dot(lightDir,normal); | ||
brightness = clamp(brightness, 0.2, 1.); | ||
col.rgb = col.rgb*brightness; | ||
gl_FragColor = col; | ||
} |
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,13 @@ | ||
attribute vec3 aPosition; | ||
attribute vec2 aTexCoord; | ||
|
||
varying vec2 pos; | ||
|
||
void main() { | ||
pos = aTexCoord; | ||
|
||
vec4 position = vec4(aPosition,1.0); | ||
position.xy = position.xy*2.-1.; | ||
|
||
gl_Position = position; | ||
} |
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