Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makeup Assignment #1 #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

shahinmv
Copy link

Could not finalize the last task and get the correct renders for the Environmental camera.

Copy link
Collaborator

@ereator ereator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • CPrimPlane::intersect returns -1 instead of false - yellow line on horizon (-2)
  • CPrimTriangle::intersect gives incorrect results (-2)
  • CCameraPerspective - good idea, but the results are not correct, extra 30 mins of work would made your implementation fine. I have debugged your code and gave the feedback in GittHub.

float den = m_normal.dot(ray.dir);
if (den == 0)
{
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a Boolean function, it should be false. This error gives the yellow line on horizon in your renders.

return false;
}
ray.t = t;
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triangles are rendered only in the right part of the screen. I think somewhere inside this algorithm an error. Perhaps in the line float t = p[0] / ray.dir[0];I recommend to check the sign and take into consideration also other dimensions.

// --- PUT YOUR CODE HERE ---

class CPrimDisc : public IPrim {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to derive the disc from plane primitive here, however the implementation is fine

{
public:
CCameraEnvironmental(Size resolution, const Vec3f& pos, float angle)
: ICamera(resolution)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env camera has no angle

auto height = getResolution().height;
auto width = getResolution().width;

double theta = 2 * M_PI * dx / height;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here dx should be decided by width and not height.
The same error for dy.

double x1 = sin(phi) * cos(theta);
double y1 = sin(phi) * sin(theta);
double z = cos(phi);
Vec3f spherePoint = Vec3f(x1, y1, z);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this point is on the unit sphere, which is located in the origin. So you can use it as direction vector. Next, you forgot the coordinate system transformation, in the WCS y axis looks up, in the sphere you generate, z axis looks up

auto width = getResolution().width;

double theta = 2 * M_PI * dx / height;
double phi = acos(1 - 2 * dy / width);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here would be enough to have phi changing from 0 to Pi. arccosine is not needed.

}
virtual ~CCameraEnvironmental(void) = default;

virtual void InitRay(Ray& ray, int x, int y) override
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your implementation, it general it looks correct. After a closer look, there are some error. You need to spend a bit more time for debugging.

// input values
Vec3f m_pos; ///< Camera origin (center of projection)
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following implementation based on yours:

		float dx = static_cast<float>(x) / getResolution().width;
		float dy = static_cast<float>(y) / getResolution().height;

		float theta = 2 * Pif * dx;
		float phi	 = Pif * dy;
		
		float x1 = sinf(phi) * cosf(theta);
		float z1 = sinf(phi) * sinf(theta);
		float y1 = cosf(phi);

		ray.org = m_pos;
		ray.dir = Vec3f(x1, y1, z1);
		ray.t = std::numeric_limits<float>::infinity();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants