add targeting probability density function
parent
6b47f44ad2
commit
c4ee560dc9
@ -0,0 +1,28 @@
|
|||||||
|
package eu.jonahbauer.raytracing.render.renderer.pdf;
|
||||||
|
|
||||||
|
import eu.jonahbauer.raytracing.math.Vec3;
|
||||||
|
import eu.jonahbauer.raytracing.scene.Target;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.random.RandomGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A probability density function targeting a target.
|
||||||
|
*/
|
||||||
|
public record TargetingProbabilityDensityFunction(@NotNull Vec3 origin, @NotNull Target target) implements ProbabilityDensityFunction {
|
||||||
|
public TargetingProbabilityDensityFunction {
|
||||||
|
Objects.requireNonNull(origin, "origin");
|
||||||
|
Objects.requireNonNull(target, "target");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double value(@NotNull Vec3 direction) {
|
||||||
|
return target.getProbabilityDensity(origin, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Vec3 generate(@NotNull RandomGenerator random) {
|
||||||
|
return target.getTargetingDirection(origin, random);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package eu.jonahbauer.raytracing.scene;
|
||||||
|
|
||||||
|
import eu.jonahbauer.raytracing.math.Vec3;
|
||||||
|
import eu.jonahbauer.raytracing.render.renderer.pdf.TargetingProbabilityDensityFunction;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.random.RandomGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for objects that can be targeted. A target can construct randomly distributed directions in which
|
||||||
|
* it will be hit from a given origin.
|
||||||
|
* @see TargetingProbabilityDensityFunction
|
||||||
|
*/
|
||||||
|
public interface Target extends Hittable {
|
||||||
|
/**
|
||||||
|
* Returns the probability density for a direction as sampled by {@link #getTargetingDirection(Vec3, RandomGenerator)}.
|
||||||
|
* @param origin the origin
|
||||||
|
* @param direction the direction
|
||||||
|
* @return the probability density for a direction as sampled by {@link #getTargetingDirection(Vec3, RandomGenerator)}
|
||||||
|
*/
|
||||||
|
double getProbabilityDensity(@NotNull Vec3 origin, @NotNull Vec3 direction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@return a vector targeting this hittable from the <code>origin</code>} The vector is chosen randomly.
|
||||||
|
* @param origin the origin
|
||||||
|
* @param random a random number generator
|
||||||
|
*/
|
||||||
|
@NotNull Vec3 getTargetingDirection(@NotNull Vec3 origin, @NotNull RandomGenerator random);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default @NotNull Target translate(@NotNull Vec3 offset) {
|
||||||
|
return (Target) Hittable.super.translate(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default @NotNull Target rotateY(double angle) {
|
||||||
|
return (Target) Hittable.super.rotateY(angle);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.jonahbauer.raytracing.scene.util;
|
||||||
|
|
||||||
|
import eu.jonahbauer.raytracing.math.Vec3;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public final class PdfUtil {
|
||||||
|
private PdfUtil() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getSolidAngle(@NotNull Vec3 o, @NotNull Vec3 a, @NotNull Vec3 b, @NotNull Vec3 c) {
|
||||||
|
var i = a.minus(o).unit();
|
||||||
|
var j = b.minus(o).unit();
|
||||||
|
var k = c.minus(o).unit();
|
||||||
|
|
||||||
|
return 2 * Math.atan(Math.abs(i.times(j.cross(k))) / (1 + i.times(j) + j.times(k) + k.times(i)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue