Skip to content

Assignment 2

Gabriel Ivanica edited this page Jan 5, 2019 · 10 revisions

Tema 2 - Screen Space Reflection

Description

Implement a Screen-Space-Reflections demo where reflections can be seen on the surface of the terrain only in the certain areas (puddles).

Resources

Deadline

  • 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)

Tasks

  • Create a simple scene for simulating screen-space reflections as in the demo [20 pct]
  • Render a sky-box (as shown in the Environment Mapping assignment) [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)
	// 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.a channel 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
// 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 sin and cos to affect
    • Should look plausible... (not exaggerated)
  • Update FBO resolution when the screen/window is resized [5 pct] **
  • README: [5 pct]

Total: 200 pct

Bonuses

  • 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

Project Archive

  • make sure you don't include temporary compiled files in the archive
    • right of Solution Explorer → Clean Solution
    • delete /Visual Studio/obj and /Visual Studio/.vs folder
  • the archive should only contain
    • /Visual Studio
    • /Source
    • /Resources
    • /libs
    • README.txt - readme for the assignment

Clone this wiki locally