Commit 910b7375 authored by Brian's avatar Brian

compute funtions update

-try to use formulas from other papers
parent 07d51783
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Shader\compute.glsl" /> <None Include="Shader\compute.c" />
<None Include="Shader\fragment.glsl" /> <None Include="Shader\fragment.glsl" />
<None Include="Shader\vertex.glsl" /> <None Include="Shader\vertex.glsl" />
</ItemGroup> </ItemGroup>
......
...@@ -30,15 +30,15 @@ ...@@ -30,15 +30,15 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Shader\compute.glsl">
<Filter>Shader</Filter>
</None>
<None Include="Shader\fragment.glsl"> <None Include="Shader\fragment.glsl">
<Filter>Shader</Filter> <Filter>Shader</Filter>
</None> </None>
<None Include="Shader\vertex.glsl"> <None Include="Shader\vertex.glsl">
<Filter>Shader</Filter> <Filter>Shader</Filter>
</None> </None>
<None Include="Shader\compute.c">
<Filter>Shader</Filter>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="glad.h"> <ClInclude Include="glad.h">
......
...@@ -9,24 +9,47 @@ vec3 sphere_c = vec3(0.0, 0.0, -10.0); ...@@ -9,24 +9,47 @@ vec3 sphere_c = vec3(0.0, 0.0, -10.0);
float sphere_r = 1.0; float sphere_r = 1.0;
vec4 normals(float t, ivec2 pixel_coords) vec3 point_at_parameter(vec3 A, float t)
{ { return A + t * ray_d; }
if (t > 0.0)
bool hit_sphere(float max_x, float max_y)
vec3 ray_o = vec3(max_x, max_y, 0.0);
vec3 omc = ray_o - sphere_c;
float a = dot(ray_d, ray_d);
float b = 2 * dot(ray_d, omc);
float c = dot(omc, omc) - sphere_r * sphere_r;
float discriminant = b * b - 4*a*c;
// hit one or both sides
if (discriminant < 0.0)
{ {
vec3 normal = normalize(pixel_coords - vec3(0, 0, -1)); return -1.0;
vec4 pixel = 0.5 * vec4(normal.x + 1, normal.y + 1, normal.z + 1, 2*1.0) }
else {
return (-b - sqrt(discriminant)) / (2 * a);
}
}
vec4 color(float max_x, float max_y)
{
float t = hit_sphere(max_x, max_y
if (t > 0)) {
vec3 N = normalize(point_at_parameter(vec3(max_x, max_y, 0.0), t));
return 0.5*vec4(N.x + 1, N.y +1, N.z + 1, 2);
}
else
{ // base pixel colour for image
vec4 unit_direction = normalize(ray_d);
float t = 0.5 * (unit_directioon.y + 1.0);
vec4 pixel = (1.0 - t) * vec4(1.0, 1.0, 1.0, 1.0) + t * vec4(0.5, 0.7, 1.0, 1.0);
return pixel; return pixel;
} }
vec4 unit_direction = normalize(ray_d) + (0.0, 0.0, 0.0, 1.0);
t = 0.5*(unit_direction.y + 1.0);
pixel = ((1.0 - t) * vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0)) + vec4(0.0, 0.0, 0.0, 1.0;
return pixel;
} }
void main() { void main() {
// base pixel colour for image //vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);
vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);
// get index in global work group i.e x,y position // get index in global work group i.e x,y position
ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
...@@ -39,24 +62,8 @@ void main() { ...@@ -39,24 +62,8 @@ void main() {
ivec2 dims = imageSize(img_output); // fetch image dimensions ivec2 dims = imageSize(img_output); // fetch image dimensions
float x = (float(pixel_coords.x * 2 - dims.x) / dims.x); float x = (float(pixel_coords.x * 2 - dims.x) / dims.x);
float y = (float(pixel_coords.y * 2 - dims.y) / dims.y); float y = (float(pixel_coords.y * 2 - dims.y) / dims.y);
vec3 ray_o = vec3(x * max_x, y * max_y, 0.0);
vec3 omc = ray_o - sphere_c;
float b = dot(ray_d, omc);
float c = dot(omc, omc) - sphere_r * sphere_r;
float bsqmc = b * b - c;
float t = 10000.0; //maximum bounds
// hit one or both sides pixel = color(x* max_x, y* max_y, pixel);
if (bsqmc >= 0.0) {
if(bsqmc > 0.0){
float t = 2
}
else
{
float t = 1
pixel = normals(t, pixel_coords);
}
}
// output to a specific pixel in the image // output to a specific pixel in the image
imageStore(img_output, pixel_coords, pixel); imageStore(img_output, pixel_coords, pixel);
......
...@@ -300,7 +300,7 @@ void rt::rt_window::queryWorkGroups() ...@@ -300,7 +300,7 @@ void rt::rt_window::queryWorkGroups()
void rt::rt_window::initComputeShader() void rt::rt_window::initComputeShader()
{ {
char* computeShaderSource = readShaderFromFile("Shader/compute.glsl"); char* computeShaderSource = readShaderFromFile("Shader/compute.c");
GLuint ray_shader = glCreateShader(GL_COMPUTE_SHADER); GLuint ray_shader = glCreateShader(GL_COMPUTE_SHADER);
glShaderSource(ray_shader, 1, &computeShaderSource, NULL); glShaderSource(ray_shader, 1, &computeShaderSource, NULL);
......
B^C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLAD.OBJ|C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLCALLS.OBJ|C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\OPENGL_RAYTRACER.OBJ B^C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLAD.OBJ|C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLCALLS.OBJ|C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\OPENGL_RAYTRACER.OBJ
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment