diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-05-10 16:18:23 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-05-10 16:18:23 -0400 |
commit | 05038becbe8907a1364db05c42fc1bc48f66ce56 (patch) | |
tree | ae4908fbb29fadb44e549af52a09d368387477e6 /resources | |
parent | 2820f2a620340feff973dfea26c1eb1172140ada (diff) |
Diffstat (limited to 'resources')
-rw-r--r-- | resources/shaders/foam.frag | 18 | ||||
-rw-r--r-- | resources/shaders/foam.vert | 8 |
2 files changed, 23 insertions, 3 deletions
diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index d6d1cab..53248ac 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -4,6 +4,8 @@ in vec2 constants; in vec2 dir; in vec2 tex; in vec3 pos; +in vec3 norm; +in vec3 camera_worldSpace; uniform float time; @@ -15,6 +17,9 @@ uniform sampler2D foam_texture; uniform vec2 widthBounds; uniform vec2 lengthBounds; +uniform vec4 sunColor = vec4(1.5f, .7, .39f, 1.f); +uniform vec3 lightDir = -normalize(vec3(1, 0, -1)); + out vec4 fragColor; float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ @@ -45,8 +50,19 @@ void main() { // apply foam texture vec4 foam = texture(foam_texture, tex + time*.0003); + + vec4 lightFromSun = vec4(1.f, 1.f, 1.f, 1.f); + vec4 foamAmbient = vec4(.5f, .5f, .5f, 1.f); + + vec3 reflectedLight = lightDir - 2 * dot(lightDir, norm) * norm; + vec3 posToCam = normalize(camera_worldSpace - pos); + float spec = pow(clamp(dot(posToCam, reflectedLight), 0, 1), 2.f); + + float diffuseComp = dot(normalize(norm), lightDir); + lightFromSun = vec4(vec3(diffuseComp * sunColor), 1.f); + vec4 j = vec4(0,0,0,0); - if (saturation > m_threshold) j = g*foam; + if (saturation > m_threshold) j = g * foam * (lightFromSun + foamAmbient + spec * .6f); fragColor = j; diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert index f27c589..4d7f075 100644 --- a/resources/shaders/foam.vert +++ b/resources/shaders/foam.vert @@ -2,7 +2,7 @@ layout(location = 0) in vec3 position; // Position of the vertex layout(location = 1) in vec3 wavelength; // wavelenth adjusted for ocean depth -layout(location = 2) in vec3 wavedirs; // wavelenth adjusted for ocean depth +layout(location = 2) in vec3 normals; // normals //layout(location = 2) in vec2 direction; // wave slope //layout(location = 3) in vec2 texCoords; // texture coords @@ -13,6 +13,8 @@ out vec2 constants; out vec2 dir; out vec2 tex; out vec3 pos; +out vec3 norm; +out vec3 camera_worldSpace; @@ -45,11 +47,13 @@ vec2 calculateTexCoord(vec3 pos){ } void main() { - dir = vec2(wavedirs[0],wavedirs[1]); +// dir = vec2(wavedirs[0],wavedirs[1]); constants = vec2(wavelength[0], phaseC); gl_Position = proj * view * model * vec4(position, 1); pos = vec3(gl_Position); + norm = normalize(normals); + camera_worldSpace = vec3(inverseView * vec4(0.f, 0.f, 0.f, 1.f)); tex = calculateTexCoord(position); |