#extension GL_EXT_gpu_shader4 : enable /** * Real-time Realistic Ocean Lighting using Seamless Transitions from Geometry to BRDF * Copyright (c) 2009 INRIA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /** * Author: Eric Bruneton */ uniform mat4 screenToCamera; // screen space to camera space uniform mat4 cameraToWorld; // camera space to world space uniform mat4 worldToScreen; // world space to screen space uniform vec3 worldCamera; // camera position in world space uniform vec2 gridSize; uniform float choppy; uniform sampler2DArray fftWavesSampler; uniform vec4 GRID_SIZES; in vec4 vertex; out vec2 u; // coordinates in world space used to compute P(u) out vec3 P; // wave point P(u) in world space vec2 oceanPos(vec4 vertex) { vec3 cameraDir = normalize((screenToCamera * vertex).xyz); vec3 worldDir = (cameraToWorld * vec4(cameraDir, 0.0)).xyz; float t = -worldCamera.z / worldDir.z; return worldCamera.xy + t * worldDir.xy; } void main() { gl_Position = vertex; u = oceanPos(vertex); vec2 ux = oceanPos(vertex + vec4(gridSize.x, 0.0, 0.0, 0.0)); vec2 uy = oceanPos(vertex + vec4(0.0, gridSize.y, 0.0, 0.0)); vec2 dux = abs(ux - u) * 2.0; vec2 duy = abs(uy - u) * 2.0; vec3 dP = vec3(0.0); dP.z += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.x, 0.0), dux / GRID_SIZES.x, duy / GRID_SIZES.x).x; dP.z += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.y, 0.0), dux / GRID_SIZES.y, duy / GRID_SIZES.y).y; dP.z += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.z, 0.0), dux / GRID_SIZES.z, duy / GRID_SIZES.z).z; dP.z += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.w, 0.0), dux / GRID_SIZES.w, duy / GRID_SIZES.w).w; if (choppy > 0.0) { dP.xy += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.x, 3.0), dux / GRID_SIZES.x, duy / GRID_SIZES.x).xy; dP.xy += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.y, 3.0), dux / GRID_SIZES.y, duy / GRID_SIZES.y).zw; dP.xy += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.z, 4.0), dux / GRID_SIZES.z, duy / GRID_SIZES.z).xy; dP.xy += textureGrad(fftWavesSampler, vec3(u / GRID_SIZES.w, 4.0), dux / GRID_SIZES.w, duy / GRID_SIZES.w).zw; } P = vec3(u + dP.xy, dP.z); gl_Position = worldToScreen * vec4(P, 1.0); }