A4: Solar System

ewillwin·2022년 11월 11일
0

Computer Graphics

목록 보기
2/2
post-thumbnail

1. Objective

In the last assignment, you learned how to place and transform 3D objects. This assignment is to complete your solar system with shading/textures and advanced features. The rendering results will be similar as shown in Figure 1. Refer to them for your implementation.

2. Requirements

  • (20pt) Make and animate dwarf planets of each planet. 위성은 두 개 이상.
  • (20pt) Apply a point light (the Sun) based per-pixel shading using Blinn-Phong model. (Blinn-Phong model은 sample에서 들고오면 됨.) The Sun would not need to be shaded. (otherwise, -5pt)
  • (20pt) Apply texturing using freely-available resources; e.g., http://planetpixelemporium.com/planets.html. Please do not distribute the maps which violates copyrights. (이미 넣어둠)
  • (20pt) Make a textured ring system of the Saturn. The ring geometry needs to use an additional vertex array. -> 구가 아닌 geometry -> vertex buffer가 두 개가 됨. 마찬가지로 삼각형으로 근사화.
  • (10pt) Apply the alpha blending to the ring system. For the alpha blending, you need to configure OpenGL as:Then, apply alpha from the alpha textures to fragColor. a.

3. Bump Mapping (Optional)

When you implement additional features listed below, you can get additional credits.

  • (20pt) Apply bump mapping on planet surfaces.

We know what the bump mapping implies, but its implementation is
non-trivial. In particular for a correct implementation, we need to define tangent and binormal vectors (as additional vertex attributes) as well as normal vector in your vertices or meshes. For the moment, suppose the tangent and binormal vectors are already available. Then, we can find a bumped normal in the world space and the eye space in your fragment shader (see Fig. 2). When shading is performed in the eye space, make sure to use the eye-space normal instead of the world-space normal.


[Algorithms and data structures]
1. Make and animate dwarf planets of each planet.
지구의 위성 1개, 목성의 위성 4개, 토성의 위성 6개, 천왕성의 위성 2개, 해왕성의 위성 2개를 생성하였다.
우선 위성은 행성 주위를 공전하기 때문에 회전 축이 움직인다는 점을 고려하여 기존의 circle_t 구조체에 bool isDwarf, int whatplanet 변수를 추가하였다. 또한 circle_t 구조체 안의 void update 함수의 인자로 vector<circle_t> &circles을 추가하였다. (isDwarf는 해당 sphere instance가 위성인 지 아닌지를 나타내는 변수이고, whatplanet은 isDwarf가 true일 경우 어떤 행성의 위성인지를 나 타내는 변수이다. Void update 함수에 구조체 벡터 참조자를 추가한 이유는 위성의 경우, 공전하 고자 하는 행성의 위치를 불러오기 위함이다.)
circle.h 파일의 create_circles()함수에서 태양과 행성 8개를 생성하고, 위성 또한 총 15개를 생성 하였다.
위성의 공전을 구현하기 위해 circle.h 파일의 update() 함수에서 isDwarf가 true인 경우 model_matrix를 재정의해주어야 했다.
행성의 경우 공전을 구현하기 위해: 태양 위치로 translate -> rotate -> 원래 위치로 translate
위성의 경우 공전을 구현하기 위해: 행성 위치로 translate -> rotate -> 위성 위치로 translate
해야한다고 생각하여, tmp_translate_matrix와 tmp_rotation_matrix를 행성의 데이터를 불러와서 구 현하였고, tmp_rotation_matrix tmp_translate_matrix rotation_matrix translate_matrix scale_matrix 순서로 곱하여 model_matrix 정의하여 위성의 공전을 구현하였다.

2. Apply a point light (the Sun) based per-pixel shading using Blinn-Phong model. The Sun should not need to be shaded.
Blinn-Phong model을 구현하기 위해, 우선 light_t 구조체와 material_t 구조체를 정의해주었다. 또한, directional light가 아닌, point light을 구현해야 했기에 light_t 구조체의 vec4 position를 vec4(0.0f, 0.0f, 0.0f, 1.0f)로 정의하였다. 앞 세 개의 원소는 point의 위치인데, 태양은 원점에 위치 하기 때문에 0.0f로 값을 할당하였다.
Main.cpp 파일의 update() 함수에서 light properties와 material properties를 setup해주어 fragment shader에서 사용할 uniform variable들을 정의해주었다.
Fragment shader에서 교안에 나온 대로 blinn-phong function을 정의하였고 태양은 shaded 되면 안되기 때문에 fragColor = texture(TEX0, tc); 로 texture만 입혀주고, 나머지 행성들에 대해 blinn- phong 함수를 적용시켜 주었다.

3. Apply texturing using freely-available resource.
Texture mapping을 위해 우선 std_image.h 파일을 link 시켜 주었다. 또한 main.cpp 파일에서 static const 변수로 각 행성의 texture path를 찾아 선언해주었다.
각 행성의 이름으로 GLuint 변수를 선언해주고, User_init() 함수에서 각 행성마다 cg_create_texture() 함수를 실행하여 texture를 생성시켜 주었다.
Render() 함수에서 circles vector의 size만큼 for문을 돌며 각 행성들의 texture를 bind 해주었다.
Circle.h 파일의 circle_t 구조체에 int index 변수를 추가하여 각 행성에 해당하는 texture가 올바 르게 mapping 될 수 있도록 구현하였다. 이 index 변수는 fragment shader의 uniform variable인 데, 이를 통해 if문을 구현하여 각 행성들에 texture를 mapping 해주었다.

[Discussions]
blinn-phong shading은 교안과 sample에 나와있는 대로 코드를 수정하여 다소 쉽게 구현할 수 있었다.
Texture mapping은 각 sphere instance마다 다른 texture를 mapping 해주어야 했기 때문에, 이 부분에서 살짝 막혔지만, 각 sphere instance에 index를 지정하여 구현할 수 있었다. Fragment shader에서 해당 index로 행성을 구분하여 texture를 입혀야 하기 때문에, index 변수를 uniform variable로 선언해주어야 했다.
위성의 공전을 구현하는데 다소 어려움을 느꼈다. 행성이 공전을 하기 때문에, 회전축이 움직인 다는 점에서 어떻게 구현해야 할 지 고민하던 중, 행성의 데이터를 불러와야 한다는 사실을 깨닫 고, 구조체 안의 update 함수에 circle_t vector를 인자로 입력 받아 해당 행성의 데이터를 가져오 는 것을 구현하였다. 이를 통해 tmp_translate_matrix와 tmp_rotation_matrix를 생성하여 공전하는 회전축을 구현할 수 있었다.

profile
Software Engineer @ LG Electronics

1개의 댓글

comment-user-thumbnail
2023년 11월 17일

The Solar System, a marvel of cosmic wonder, comprises the sun, planets, moons, and celestial objects. Among its innovative advancements, harnessing solar energy stands out. High wattage solar panels a technological feat, captivate with their ability to convert sunlight into renewable power efficiently. These panels, pivotal in the green energy revolution, adorn rooftops and vast solar farms, offering sustainable electricity solutions worldwide. In our Solar System's vastness, Earth embraces these panels as a beacon of hope for a cleaner future, illustrating humanity's quest to embrace the sun's boundless energy for a brighter and more sustainable tomorrow.

답글 달기