COMP3170 Assignment 3 Moonlit forest Objectives This assignment covers the following topics: • 3D modelling with triangular meshes • 3D Transformations • Perspective cameras • Fragment shaders • Illumination and shading • Texturing Your task is to build a simple 3D scene of a snowy forest in the moonlight, like this: Framework A basic framework for the assignment is available via GitHub classroom: https://classroom.github.com/a/uA7_vbt7 Scene features Your mark will be based on the features you implement, from the list below. Each feature has a mark value attached. Completing more than 100% worth of features will not earn additional marks. Details below. The more challenging elements are marked with an asterisk*. Feature Marks Forest meshes • Ground plane • Tree trunk • Tree canopy • 40 random trees 5% 5% 5% 5% Textures • Snow on the ground plane • Tree trunks • Tree canopy • Colour • Cone UVs calculated in shader* 4% 4% 4% 4% 4% Camera • Perspective camera with appropriate view volume • Aspect matches window • Movement with keyboard controls 4% 4% 4% Moon • Mesh • Constant offset from camera position • Rising & falling • Always at back of scene (implemented in shader)* 4% 4% 4% 4% Illumination • Low level ambient light • Directional light based on moon position • Moon light fades to zero as it drops below the horizon 4% 4% 4% Shading • Ambient and diffuse lighting on ground • Specular lighting on ground • Ambient and diffuse light on trunk and canopy • Canopy fragment normals calculated in shader* • Rim lighting on trunk and canopy** 4% 4% 4% 4% 4% Total 100% General requirements Your scene should be implemented using: 1) Anti-aliasing using 2x2 supersampling. 2) Backface culling 3) Mipmaps for all textures (with trilinear filtering) 4) Gamma correction (with a default gamma of 2.2) Correctness marks will be deducted if these not implemented correctly. Forest meshes • The forest should consist of a 40x40m ground plane, as a flat square. • 40 trees should be randomly distributed on the ground plane • Each tree is made of two parts: o A cylindrical trunk o A conical canopy of leaves • Each tree should be between 5m and 10m tall, with random variations in both trunk and canopy heights and radii. Textures The ground plane should be textured using the snow.png texture provided. • The texture should repeat 20 times across the square in each direction. The tree trunk and canopy should be textured using the tree.png texture provided. • The texture should repeat two times horizontally and vertically around the trunk. • The texture should repeat four times horizontally and three times vertically around the canopy. • This texture provided is greyscale. Colouring should be implemented in the shader, so the canopy is green and the trunk is brown. • Note: Calculating texture coordinates for a cone is more difficult than usual. The standard technique of setting vertex UVs and interpolating them doesn’t give good results. So, you will need to write a purpose shader to calculate UVs for the canopy. The method involved will be discussed in tutorials. Camera • The camera should have a perspective projection with an appropriate vertical field of view. • The view volume of the camera should be set so the player can see the full extent of the landscape from any position, without any obvious culling. However, the view volume should also not be excessively large. • The aspect ratio of the camera should match the aspect ratio of the window, so the view does not distort when the window is resized. • The camera should sit 1.5m above the terrain. • The camera should move with the keys: o W/S moves forwards and backwards o Q/E strafes left and right o A/D turns left and right • There is no need to handle colliding with trees or walking beyond the extent of the world. The Moon • The moon is a white sphere. • The moon’s position should be at a constant offset from the camera position (in world coordinates), to give the appearance that the moon is a very large distance away. • The moon should rise and fall, rotates around the world once every 2 minutes. • The moon should always render behind other objects in the scene. This should be implemented in the fragment shader by adjusting the depth values for fragments. Illumination • There should be a very low level of ambient lighting. • The Moon should be a source of directional lighting, based on its position in the sky. • When the moon is below the horizon, its intensity should fade to zero. Shading • All lighting should be implemented as fragment lighting (i.e. based on fragment normals). • The ground should implement ambient, diffuse and specular lighting (with a low specularity) so the snow appears brighter when facing toward the moon. • The tree canopy and trunk should implement ambient and diffuse lighting, with appropriate normals. • Note: computing normals for a cone by interpolating vertex normals will not yield accurate results. To shade the tree canopy, you will need to calculate normals directly in the fragment shader, based on the model coordinates of the fragment. • The tree canopy and trunk should exhibit rim lighting, as shown below. Rim lighting occurs when an object sits between the light source and the camera. The edges of the object catch the light and the object appears to have a bright outline. Figure 1: The bright lines on the outer edge of the trunk and canopy are rim lighting. This can be achieved in a fragment shader by: 1. Compute the dot product of the normal vector and the view vector. For fragments on the rim, this value will be close to zero (i.e. the normal vector is perpendicular to the view vector). 2. Compute the dot product of the view vector and the source vector. When the light is behind the object, the view vector and source vector will point in opposite directions, so the dot product will be close to -1. 3. Combine these two values (with appropriate thresholds) to calculate the amount of rim light on the fragment (taking the light source intensity into account). 4. Add the rim light intensity to the lighting equation for the fragment. Report The assignment framework includes a report template. Complete the table at the front of the report indicating which of the components above you are attempting. For each component, give an indication of where in the project it is implemented. Failure to submit a complete report carries a 20% penalty. Submission Assignment code and reports will be submitted through GitHub Classroom. We will mark your last commit before the assignment deadline. Marking Rubric Total mark = SQRT((components completed) * (50% * code correctness + 50% * clarity of code)) So, for example, if you completed components worth 80%, with a correctness mark of 70% and clarity mark of 100%, your final mark would be: Total mark = SQRT(80 * (50% * 70 + 50% * 100)) = SQRT(80 * 85) = 82.5 Alternatively, if you only completed components worth 40%, with the same correctness and completeness your final mark would be: Total mark = SQRT(40 * (50% * 70 + 50% * 100)) = SQRT(40 * 85) = 58.3 Each component that you implement will be marked for completeness of the implementation against the specification. The overall program will be marked for correctness and clarity according to the following rubric. Grade Correctness Clarity A+ (100%) Excellent work. Code is free from any apparent errors. Problems are solved in a suitable fashion. Contains no irrelevant code. Good consistent style. Well structured & commented code. Appropriate division into classes and methods, to make implementation clear. B (80%) Very good work. Code has minor errors which do not significantly affect performance. Contains no irrelevant code. Code is readable with no significant code-smell. Code architecture is adequate but could be improved. C (70%) Good work. Code has one or two minor errors that affect performance. Problems may be solved in ways that are convoluted or otherwise show lack of understanding. Contains some copied code that is not relevant to the problem. Code is readable but has some code- smell that needs to be addressed. Code architecture is adequate but could be improved. D (60%) Poor. Code is functional but contains major flaws. Contains large passages of copied code that are not relevant to the problem. Significant issues with code quality. Inconsistent application of style. Poor readability with code-smell issues. Code architecture could be improved. F (40%) Code compiles and runs, but major elements are not functional. Significant issues with code quality. Inconsistent application of style. Poor readability with code-smell issues. Messy code architecture with significant encapsulation violations. 0% Code does not compile. Major issues with code quality. Major readability problems and code smell throughout. Messy code architecture with significant encapsulation violations.
欢迎咨询51作业君