All of these pictures were made through a combination of Layer masks and some adjustments. The second one also used lasso tools to select the aera where I added the setting sun effects.
This project Demo Link consists of basic ray-tracing functions and many extra features.
Following features have been implemented:
Render polygons
Render spheres
Use simple Phong Shading (in color)
Compute shadows
Compute reflections
Use point lights
Write its output to a standard image format(.ppm).
Depth of field
Anti-aliasing
Transparency with refraction
Use AABB tree to accelerate the computations
Use iterative flows to trace the bounce rays, instead of recursion.
Toon shading
Inputs
The inputs include two parts: command lane arguments and an input file(writen in .nnf format)
Command Lane Arguments
All the command line arguments are optional. The default values for each object on the screen is its ambient color. Other pixels will be filled with background color. Detailed specifications are written in the input file.
-c
This command tells the programm to shade the objects(i.e. running phone shading or toon shading)
-d %g
This command provides an integer value limiting the number of bounces in reflection and refraction.
-phone
Switch to phone shading(default)
-toon
Switch to toon shading(the last command on switching shading methods will be applied)
-samples %g
Set the number of samples(%g * %g) to be collected to determine each pixel(if greater than one, then automatically run anti-aliasing)
-aabb
Set to use aabb-tree data structure
-iter
Set to shift from recursion to iteration bounce ray tracing.
In addition, I added three extra parameters–rr rg rb following the fill color and shading parameters to provide the reflective attenuation, which makes the rendering of image easier.
Gallery
The tracing results generated from my program. All the input datasets were from the Internet.
Environment: Windows10, i7-8750H 2.20GHz CPU, VS Code
This project Demo Link implements the following features:
open a window contains an OpenGL rendering area in which a circular shape should be shaded using the Phong Illumination Model for point and directional lights.
The circular shape should always occupy most of the window. If the window is resized it should update the display so that the shape still occupies most of the window and is still round. (In this context “most” would mean that the diameter of the circle should be 90% of the smaller of the window’s height or width.)
Press arrow keys to move the circular shape, and either ESC key or Q to terminate the program and close the window.
Command Lane Arguments
All the command line arguments are optional. The default values should be a black sphere with no lights. That is the program display a black circular shape on a black(default) background. If material parameters are multiply specified, the last value should be used.
-ka r g b
This is the ambient color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-kd r g b
This is the diffuse color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-ks r g b
This is the specular color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-spu pu
This is the power coefficient on the specular term in the u direction for an anisotropic material. It is a number between 0 and max_float.
-spv pv
This is the power coefficient on the specular term in the v direction for an anisotropic material. It is a number between 0 and max_float.
-sp p
This is the power coefficient on the specular term for an isotropic material. It is a number between 0 and max_float. (i.e. the same as setting pu and pv the the same value.)
-pl x y z r g b
This adds a point light to the scene. The x y z values are the location of the light. The r g b values are it’s color. Note that the x y z values are relative to the sphere. That is, the center of the sphere is at the origin and the radius of the sphere defines one unit of length. The Y direction is UP, the X direction is to the right on the screen, and the Z direction is “in your face.” The r g b value are between 0 and max_float, NOT between 0 and 1 (that is, the r g b values encode the brightness of the light).
-dl x y z r g b
This adds a directional light to the scene. The x y z values are the direction that the light points in. The r g b values are it’s color. See -pl for coordinate system notes.
-bgbmp fp
This tells which .BMP file would be used as the custom background image.
-bgppm fp
This tells which .ppm file would be used as the custom background image.
-toon
switch to the toon shading
-pixellation
apply the pixellation effect on the final image
Specifications:
There may be up to 5 point lights and 5 directional lights (10 total) in a scene. Image r g b values of 1.0 should be mapped to a display values of 255.
The coordinate system you use in your program should have a unit sphere at the origin and the viewer looking down the Z-axis. The X-axis points to the right of the screen, the Y-axis points up, and the viewer is located infinitely far away in the positive Z direction. You should assume that the vector from eye to the surface will always be -Z.
All the background image would automatically fill the screen when the screen has been resized.
This algorithm serves to finding the major element in a pile of data, and the occurrence of the major element is no less than 50% of the whole.
Question Description:
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. (Leetcode 169)
Brute force
HashMap
Double loop
Application
This algorithm logically partitions the elements to two sections. One is the section contains only major elements and the other one contains any other elements.
class Solution { public int majorityElement(int[] nums) { int count = 0; Integer candidate = null;
for (int num : nums) { if (count == 0) { candidate = num; } count += (num == candidate) ? 1 : -1; }
return candidate; } }
Extension
分布式Boyer-Moore Boyer-Moore还有一个优点,那就是可以使用并行算法实现。相关算法可见Finding the Majority Element in Parallel 其基本思想为对原数组采用分治的方法,把数组划分成很多段(每段大小可以不相同),在每段中计算出candidate-count二元组,然后得到最终结果。