working generating camera rays from view and proj matrices
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -3,8 +3,8 @@
|
||||
vec2 map(in vec3 pos)
|
||||
{
|
||||
vec2 d1 = vec2(sdPlane(pos), 1);
|
||||
vec2 d2 = vec2(sdSphere(pos - vec3(0.0, 2.0, 0.0)), 2);
|
||||
vec2 d3 = vec2(sdSphere(pos - vec3(2.0, 1.2, 2.0)), 3);
|
||||
vec2 d2 = vec2(sdSphere(pos - vec3(0.0, 2.0, 5.0)), 2);
|
||||
vec2 d3 = vec2(sdSphere(pos - vec3(0.0, 3.0, 3.0)), 3);
|
||||
return sdUnion(sdUnion(d1, d2), d3);
|
||||
}
|
||||
|
||||
|
||||
+12
-5
@@ -7,6 +7,13 @@ layout(location=0) out vec4 out_color;
|
||||
layout(set=0, binding=0) uniform texture2D tex;
|
||||
layout(set=0, binding=1) uniform sampler tex_smp;
|
||||
|
||||
layout(set=1, binding=0) uniform Uniforms
|
||||
{
|
||||
mat4 view_matrix;
|
||||
mat4 proj_matrix_inv;
|
||||
vec3 cam_pos;
|
||||
};
|
||||
|
||||
// Defines
|
||||
#define PI 3.141592
|
||||
#define EPSILON 0.01
|
||||
@@ -19,10 +26,10 @@ layout(set=0, binding=1) uniform sampler tex_smp;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate ray
|
||||
vec3 ro = vec3(0.0, 2, -6.0); // Ray origin
|
||||
vec3 rd = normalize(vec3(vert_uv - vec2(0.5, 0.5), 1.001)); // Ray direction
|
||||
|
||||
vec3 view_dir = (proj_matrix_inv * vec4(vert_uv, 0, 1)).xyz;
|
||||
vec3 ray_dir = normalize(view_matrix * vec4(view_dir,0)).xyz;
|
||||
|
||||
|
||||
// Render
|
||||
out_color = vec4(raymarch(ro, rd), 1);
|
||||
out_color = vec4(raymarch(cam_pos, ray_dir), 1);
|
||||
}
|
||||
@@ -4,14 +4,6 @@ layout(location=0) in vec3 in_position;
|
||||
layout(location=1) in vec2 in_uv;
|
||||
layout(location=0) out vec2 vert_uv;
|
||||
|
||||
layout(set=1, binding=0) uniform Uniforms
|
||||
{
|
||||
mat4 view; // world to camera
|
||||
mat4 proj; // camera to screen
|
||||
mat4 proj_inv; // screen to camera
|
||||
vec3 cam_pos; // camera position
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vert_uv = in_uv;
|
||||
|
||||
Reference in New Issue
Block a user