-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment 2
Gabriel Ivanica edited this page Jan 5, 2019
·
10 revisions
Implement a Screen-Space-Reflections demo where reflections can be seen on the surface of the terrain only in the certain areas (puddles).
- 14 December 2018 23:59 (soft deadline)
- After the soft deadline, penalty is 10 pct/per day up to a maximum of 50% (100 pct)
- Create a simple scene for simulating screen-space reflections as in the demo [20 pct]
- Render a sky-box (as shown in the
Environment Mappingassignment) [15 pct] - Render the scene in an FBO using a custom Render to Target shader [10 pct]
- 1 output texture for diffuse color
- 1 output texture for world positions
- 1 output texture for world normals
- Screen-space reflections will be applied only on the terrain mesh. [20pct]
- Render the terrain mesh with a special shader in order to simulate puddles
- The shader should render into the same FBO used previously
- In order to simulate puddles 2 textures are required
- original texture: used only for coloring the terrain: ground.jpg
- grayscale noise texture: used for creating the puddle effect: heightmap.png
- use a simple scaled quad for rendering the terrain
- output the required data to the FBO (diffuse color, positions, normals)
- for the diffuse color channel
- sample both color texture and heightmap texture
- output a combination of the 2 texture using the terrain color and water color (a custom color declared in shader)
- ouput the noise value to the alpha channel in order to use it later when computing the SSR (screen-space reflections)
- for the diffuse color channel
// water_color: color of the water, in demo is vec3(0.2, 0.6, 0.9)
// noise.r: grayscale component of the sampled noise texture
// darkening_factor: value between [0, 1] useful to improve scene atmosphere (demo uses 0.5)
out_color = water_color * noise.r + (1 - noise.r) * terrain_color * darkening_factor
out_color.a = noise.r;
// Fell free to play with values or even use a different method- Compute screen-space reflections in a second screen pass (render a full-screen quad) [100 pct]
- bind all the textures from the first pass FBO
diffuse, world_positions, world_normals, Z depth
- use a different FBO for outputing the reflections pixels
- compute reflection only for terrain pixels
- use geometric information (position in world space of pixels) or the
diffuse.achannel and only compute the reflection for the terrain- by outputting 0 in the diffuse.a channel in the 0 for all the other scene objects and a grayscale [0, 1] value for terrain it's easy to make the distinctions
- use geometric information (position in world space of pixels) or the
- bind all the textures from the first pass FBO
// Screen space reflection algorithm
// Please read the provided documentation as well to better understand the technique
-> for each terrain sample
-> test if pixel is reflective (diffuse.a > 0)
-> if true
-> get the world position
-> compute the reflected ray
-> reflectedRay = reflect(eyeToFragment, normalize(pixel_world_normal));
-> reflectedRay = normalize(reflectedRay);
-> define sampling step
-> small enough or based on the distance to the pixel
-> in demo is set to (distance_to_point / 300)
// test using different values to see what happens
-> while no reflected surface is found
// stop after a certain number of steps if nothing is found (can be 100, 500, 1000 ... depends on the scene/sampling step)
-> compute next world position (starting from the terrain point)
samplePos += reflectedRay * samplingStep;
-> compute the NDC space for new samplePos
vec4 ndc = Projection * View * vec4(pos, 1);
ndc = ndc / ndc.w;
-> compute [0, 1] space (for texturing and depth information)
vec4 smc = ndc * 0.5 + 0.5;
-> sample the depth information for the new point (from the depth texture)
-> compare sampled depth (from the depthTexture using the smc.xy coordinates) with the current sample depth (smc.z)
-> if the 2 values are very close (in demo: 0.00005) it means that a reflected point was found
float nDepth = texture(depthTexture, smc.xy).x;
(smc.z - nDepth < 0.00005 && smc.z > nDepth)
-> sample the diffuse_color texture
-> output the diffuse.rgb for the reflected point multiplied by the pixel reflective factor (terrain diffuse.a)
-> if no reflective sample was found output default non-reflective information: vec4(0)- Compute the final output image by composing the SSR output with the rest of the scene data [10 pct]
- Apply a small blur effect (kernel size of 3) over the SSR before composing (can be a naive bluring with 2 fors)
- Simulate any kind of image distortion on the surface of the water [15 pct]
- In demo it's used a combination of
sinandcosto affect - Should look plausible... (not exaggerated)
- In demo it's used a combination of
- Update FBO resolution when the screen/window is resized [5 pct] **
- README: [5 pct]
- Add scene illumination using Phong model in Fragment shader
- Any other effect that improves the realism of the scene (related to the simulation)
- Improved surface
- make sure you don't include temporary compiled files in the archive
- right of Solution Explorer → Clean Solution
- delete
/Visual Studio/objand/Visual Studio/.vsfolder
- the archive should only contain
/Visual Studio/Source/Resources/libs-
README.txt- readme for the assignment