Hot answers tagged

14

Sorry folks for posting such a trivial issue! The issue is solved. I was using the wrong function. Here goes the correct one: glm::vec2 testVec(6,-4); float len = glm::length(testVec); The member function of the same name returns the number of components instead (i.e. vec2::length will always yield 2, vec3::length will always yield 3, etc.).


9

Here's the simple answer. In 4D, to be able to multiply them by a 4x4 matrix, vectors are represented as (x,y,z,0) and points are represented as (x,y,z,1). Since the 4th row of a 4x4 matrix represents the translation of the matrix, the above representations make it so points are affected by translation, but vectors are not. Both vectors and points are ...


6

I (believe) I've solved this (even if it has taken 2 days). My problem was essentially I wanted to take the dot product of the face normal, and line-of-sight vector like below And determine the angle to see if the face was looking towards or away from the view point. My erroneous step was that I was doing this AFTER transforming from world-space to view-...


5

Let's say you have your two points that define the line segment: $A$ and $B$, and a point $P$ that you are testing to see if it is on the line segment. Firstly, you get a normalized vector from $A$ to $B$, as well as the distance from $A$ to $B$. direction = normalize(B - A); length = length(B-A); Next, you use dot product to project the point $P$ onto ...


5

I did some research and found the answer I was looking for. The three most common ways to interpolate vectors are: Slerp - short for "spherical interpolation", this is the most correct way, but is also the costliest. In practice you likely do not need the precision. lerp - short for "linear interpolation", you just do a regular linear interpolation ...


5

In a traditional camera, the photons from the scene travel through the lens of the camera, then hit the sensor at the focal length. A consequence of the lens is that the image is upside down and backwards. In ray tracing, we can optimize this by imagining the focal plane is in front of the camera. You can think that the photons from the scene travel towards ...


4

What you are looking for is a way to get access to individual pixels in an image, in a way that you can modify those pixels with CPU code. Once you have that you'll want to find software rendering / software rasterization methods. A great place to start would be reading up in the various bresenham algorithms. There is a lot of info out there on that. Here ...


4

I've done some small changes to how I usually construct my view matrix, here is what I've modified: // put it after N = ... U = cross(N, Vspec); U = U / sqrt(dot(U,U)); % normalize V = cross(U, N); Then I also set N vector as -N to R matrix, like this: R= [U(1),U(2),U(3),0; % U is direction of camera space X axis V(1),V(2),V(3),0; % V is direction of ...


4

Short answer: yes. Longer answer: yes, because the vectors you’re using are meant to represent directions, not directions-and-distances. Think of it in terms of light: it doesn’t matter how far a photon’s traveled, whether it’s from the sun or from a lamp on your desk—once it arrives at a surface, it’s going to get reflected in exactly the same way. From a ...


4

From what I've learnt, since I'm also a student, is that you want to work with $4 \times 4$ matrices in order to treat rotations, scaling and translations in the same way, that is, multiplying by a matrix (i.e., a $4 \times 4$ matrix). Remember that without these $4 \times 4$ matrices, translations would be represented by summing with a vector, whereas ...


4

Well there's no way to know for sure unless you look at the source code but my guess is that they do zooming by lowering the FOV (field of view) of the camera. This is easy to implement and actually sort of represents how a real scope works (in the way that light rays are bent through an optical lens). A zoom effect where you change the actual position of ...


4

I think there might be a misprinting in the book. I am getting this $((A-C) + tB)\cdot((A-C) + tB) = R\cdot R$ Let A-C = Y $(Y + tB)\cdot(Y + tB) = R\cdot R$ $Y\cdot Y + Y\cdot tB + tB\cdot Y + t^2B\cdot B = R\cdot R$ Substituting back $(A-C)\cdot(A-C) + 2t * B\cdot(A-C) + t^2B\cdot B = R\cdot R$


3

It looks like the way you're using smoothstep isn't quite right. With lerp, the first two parameters are the endpoints of the output range, and the third is a 0–1 value specifying how far to interpolate. It looks like you're trying to use smoothstep the same way, but it doesn't work like that: the first two parameters to smoothstep are endpoints of the ...


3

Instead of a screen plane in front of the eye, it describes a film plane, where the image is projected, to explicitly model camera optics. You don't need to compute the focal point in doing ray tracing - it's just a way to find the plane of focus for depth of field effects. For depth of field effects I use a standard perspective projection but jitter the ...


2

Your transform looks correct. To transform from world to eye coordinates, I I always use a "lookat" transform, defined by 3 vectors: $\bf{e}$, $\bf{a}$ and $\bf{u}$; in english, the eye position, the point it's looking at, and an up vector, which must not be in the same direction as $\bf{a} - \bf{e}$ (more specifically, not a multiple of it). The space is ...


2

Good answer above. (I like that the book adds in p then subtracts it.) This is a hard-coded grey world as a "hello world" kind of ray tracer. The 0.5 is the hard-coded reflectance. Keep working through book and the object reflectance and max-recursion will be addressed. Ray branching I avoid like the plague. In cost benefit I am always a skeptic ...


2

vec3 target = rec.p + rec.normal + random_in_unit_sphere(); return 0.5*color(ray(rec.p, target-rec.p), world); this is the exact same as vec3 targetDir = rec.normal + random_in_unit_sphere(); return 0.5*color(ray(rec.p, targetDir), world); In other words the sphere is a way to pick a random direction which is biased towards the normal direction without ...


2

If you would look up the definition of a vector and a point, then a vector is: A quantity, such as velocity, completely specified by a magnitude and a direction. http://www.thefreedictionary.com/vector And a point is: A dimensionless geometric object having no properties except location. http://www.thefreedictionary.com/point So you could say ...


2

See equation (16) in Microfacet Models for Refraction through Rough Surfaces : $-(\eta_i w_i + \eta_o w_o)$ which you'll probably want to normalize. $\eta$ are the two indices of refraction and $w$ the two vectors (they use $i$ and $o$ in the paper). Also look at the left part of figure 7 on the same page to see where all the vectors are pointing.


2

Since the question was somewhat clarified I will formalize both the question and the answer for future readers. Having a differentiable scalar field $f : \mathbb{R}^4 \rightarrow \mathbb{R}$ we want to find the gradient of the field with respect to $\theta, \phi$ on the 2-manifold defined parametrically by: $$(x(\theta,\phi), y(\theta,\phi) z(\theta,\phi), ...


1

I'm not going to dive into much details about affine transformations and such, you are better off reading up on these concepts from good graphics books. I think The matrix you need is this. $\begin{bmatrix} 0.5 & 0 & 0 & 4\\ 0 & 0.5 & 0 & 6\\ 0 & 0 & 0.5 & 2\\ 0 & 0 & 0 & 1\\ \end{bmatrix}$ The reason why ...


1

Rotation matrix | wikipedia.org in section that says "in three dimensions". It's the first search result when searching about rotating a vector about an axis. Let me know if you have any questions. For your specific problem: bring the point P to the origin, then rotate the vector about the Z axis, then bring the point P back to its original location.


1

It would seem that, in the second example, the morphNormals are targets while in in the first they are deltas. This explains the difference in math used between the two pieces of code.


1

Trying to explain a problem seems to help the thought process. This is what eventually worked for me: I realized that I can easily find the point (in 3D space) where a line between two of the corners brakes through one of the walls in my pyramid field of view, given the coordinates of the out-of-view corner and one of the visible ones. It is only a matter ...


1

The simplest solution is to use a lookat matrix. This is a matrix calculated from a "eye" point, a "target" point and an up vector. The resulting matrix will then make the Z axis point from the eye to the target and the y axis in the general direction of up.


1

the arbitrary line can be represented as $P = (x,y) = P_0 + \lambda. \vec{dir}$ (works in n dimensions, no special case). If your other line is $x=x_1$ simply inject this in to solve for $\lambda$ and get $y$: $y=y_0+(x_1-x_0).\frac{{dir}_y}{{dir}_x}$.


1

The arbitrary line can be expressed as y = a*x+b (assuming it's not parallel to the y axis). If the other line is parallel to the y axis then you can simply fill in the x coordinate of any point on the line into the formula of the first line. Then you can check whether they intersect by ensuring the result lies between the endpoints of the second line. ...


Only top voted, non community-wiki answers of a minimum length are eligible