added more example scene and oren-nayar diffuse shading
This commit is contained in:
parent
074074704a
commit
427ccccc1b
|
@ -0,0 +1,32 @@
|
|||
# Blender 3.4.1 MTL File: 'None'
|
||||
# www.blender.org
|
||||
|
||||
newmtl light
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl light_blue
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl white
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
# Blender 3.4.1 MTL File: 'None'
|
||||
# www.blender.org
|
||||
|
||||
newmtl light
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl light_green
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl light_red
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl white
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
# Blender 3.4.1 MTL File: 'None'
|
||||
# www.blender.org
|
||||
|
||||
newmtl light_blue
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl light_green
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl light_red
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl white
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 638 KiB |
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
Binary file not shown.
After Width: | Height: | Size: 460 KiB |
Binary file not shown.
After Width: | Height: | Size: 285 KiB |
Binary file not shown.
After Width: | Height: | Size: 869 KiB |
|
@ -24,7 +24,7 @@ void main() {
|
|||
|
||||
vec3 color = texture(image, uv).rgb;
|
||||
|
||||
color = smart_de_noise(image, uv, 5.0, 1.0, 0.400).rgb;
|
||||
color = smart_de_noise(image, uv, 5.0, 1.0, 0.200).rgb;
|
||||
|
||||
color = reinhard_jodie(color);
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ impl Camera {
|
|||
front: Vector3::new(0.0, 0.0, -1.0),
|
||||
left: Vector3::new(1.0, 0.0, 0.0),
|
||||
up: Vector3::new(0.0, -1.0, 0.0),
|
||||
pos: Vector3::new(0.0, 1.0, 9.0),
|
||||
fov: 90.0f32
|
||||
pos: Vector3::new(0.0, 0.0, 9.0),
|
||||
fov: 65.0f32
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ lazy_static! {
|
|||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.0,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -51,10 +51,21 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.0,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("glossy"), cs::Material {
|
||||
albedo: Padded::from([1.0, 1.0, 1.0]),
|
||||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 0.0,
|
||||
specular: 0.8,
|
||||
transmission: 0.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("red"), cs::Material {
|
||||
|
@ -62,10 +73,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.0,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("green"), cs::Material {
|
||||
|
@ -73,10 +84,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.0,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("glass"), cs::Material {
|
||||
|
@ -84,10 +95,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.0, 0.0, 0.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.5,
|
||||
specular: 0.0,
|
||||
transmission: 1.0,
|
||||
ior: 1.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("light"), cs::Material {
|
||||
|
@ -95,10 +106,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([1.0, 1.0, 1.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.5,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 0.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("light_blue"), cs::Material {
|
||||
|
@ -106,10 +117,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.3, 0.3, 1.0]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.5,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 0.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("light_red"), cs::Material {
|
||||
|
@ -117,10 +128,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([1.0, 0.3, 0.3]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.5,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 0.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
|
||||
material_collection.insert(String::from("light_green"), cs::Material {
|
||||
|
@ -128,10 +139,10 @@ fn add_default_materials() {
|
|||
emission: Padded::from([0.3, 1.0, 0.3]),
|
||||
specular_color: [0.0, 0.0, 0.0],
|
||||
roughness: 1.5,
|
||||
specular: 0.0,
|
||||
transmission: 0.0,
|
||||
ior: 0.0,
|
||||
metallic: false as u32,
|
||||
__padding: 0
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -291,7 +302,7 @@ fn create_image(memory_allocator: &StandardMemoryAllocator, queue: &Arc<Queue>,
|
|||
}
|
||||
|
||||
fn load_example_scene() -> (Vec<[f32; 4]>, Vec<u32>, Vec<cs::Material>) {
|
||||
let (mut models, materials) = tobj::load_obj("res/example-scene.obj", &tobj::GPU_LOAD_OPTIONS).expect("unable to load scene from obj");
|
||||
let (mut models, materials) = tobj::load_obj("res/head.obj", &tobj::GPU_LOAD_OPTIONS).expect("unable to load scene from obj");
|
||||
|
||||
// allocate some host memory
|
||||
let mut vertices:Vec<[f32; 4]> = vec![];
|
||||
|
@ -336,7 +347,7 @@ fn create_gpu_buffer(vertices: &Vec<[f32; 4]>, indices: &Vec<u32>, materials: &V
|
|||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
usage: MemoryUsage::DeviceOnly,
|
||||
usage: MemoryUsage::Upload,
|
||||
..Default::default()
|
||||
},
|
||||
vertices.clone(),
|
||||
|
@ -349,7 +360,7 @@ fn create_gpu_buffer(vertices: &Vec<[f32; 4]>, indices: &Vec<u32>, materials: &V
|
|||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
usage: MemoryUsage::DeviceOnly,
|
||||
usage: MemoryUsage::Upload,
|
||||
..Default::default()
|
||||
},
|
||||
indices.clone(),
|
||||
|
@ -362,7 +373,7 @@ fn create_gpu_buffer(vertices: &Vec<[f32; 4]>, indices: &Vec<u32>, materials: &V
|
|||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
usage: MemoryUsage::DeviceOnly,
|
||||
usage: MemoryUsage::Upload,
|
||||
..Default::default()
|
||||
},
|
||||
materials.clone(),
|
||||
|
|
|
@ -27,6 +27,22 @@ uint get_pixel_index() {
|
|||
return gl_GlobalInvocationID.y * uint(program_metadata.resolution.x) + gl_GlobalInvocationID.x;
|
||||
}
|
||||
|
||||
// from: https://github.com/glslify/glsl-diffuse-oren-nayar/blob/master/index.glsl
|
||||
vec3 oren_nayar_diffuse(in vec3 lightDirection, in vec3 viewDirection, in vec3 surfaceNormal, in float roughness, in vec3 albedo) {
|
||||
float LdotV = dot(lightDirection, viewDirection);
|
||||
float NdotL = dot(lightDirection, surfaceNormal);
|
||||
float NdotV = dot(surfaceNormal, viewDirection);
|
||||
|
||||
float s = LdotV - NdotL * NdotV;
|
||||
float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
|
||||
|
||||
float sigma2 = roughness * roughness;
|
||||
vec3 A = 1.0 + sigma2 * (albedo / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33));
|
||||
float B = 0.45 * sigma2 / (sigma2 + 0.09);
|
||||
|
||||
return albedo * max(0.0, NdotL) * (A + B * s / t) / PI;
|
||||
}
|
||||
|
||||
vec3 trace_direct(in Ray ray) {
|
||||
vec3 color = vec3(0);
|
||||
vec3 throughput = vec3(1);
|
||||
|
@ -42,12 +58,23 @@ vec3 trace_direct(in Ray ray) {
|
|||
|
||||
Material material = materials[hit.material_index];
|
||||
|
||||
color += material.emission * 64.0 * throughput * pdf;
|
||||
color += material.emission * 256.0 * throughput * pdf;
|
||||
|
||||
throughput *= material.albedo;
|
||||
float fresnel = abs(dot(ray.direction, hit.normal));
|
||||
|
||||
ray.origin = ray.origin + ray.direction * hit.depth;
|
||||
ray.direction = generate_brdf_ray_direction(hit.normal, ray.direction, 1.0);
|
||||
if (random() * material.specular > fresnel) {
|
||||
// reflection ray
|
||||
ray.origin = ray.origin + ray.direction * hit.depth;
|
||||
ray.direction = generate_brdf_ray_direction(hit.normal, ray.direction, material.roughness);
|
||||
} else {
|
||||
vec3 incident = ray.direction;
|
||||
|
||||
// diffuse ray
|
||||
ray.origin = ray.origin + ray.direction * hit.depth;
|
||||
ray.direction = generate_brdf_ray_direction(hit.normal, ray.direction, 1.0);
|
||||
|
||||
throughput *= oren_nayar_diffuse(ray.direction, incident, hit.normal, material.roughness, material.albedo);
|
||||
}
|
||||
}
|
||||
|
||||
return color;
|
||||
|
|
|
@ -30,16 +30,13 @@ struct Material {
|
|||
vec3 specular_color;
|
||||
// roughtness of the microfacets
|
||||
float roughness;
|
||||
float specular;
|
||||
// index of refraction (exclusive to metalic)
|
||||
float ior;
|
||||
// how transmissive the surface is (exclusive to metalic)
|
||||
float transmission;
|
||||
// whether the surface is metalic or not (exclusive to ior and transmission)
|
||||
bool metallic;
|
||||
// extra padding required for vulkano not properly padding the structs in the buffer
|
||||
// the size of the useble data is 60 bytes, GLSL will add 4 additional bytes, to round up to 64.
|
||||
// for compatibility I added the padding manually
|
||||
bool __padding;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 3) buffer VertexBuffer {
|
||||
|
@ -74,7 +71,7 @@ vec3 intersect_triangle(in Ray ray, in vec3 v0, in vec3 v1, in vec3 v2, out vec3
|
|||
|
||||
// test if the intersection lies outside of the triangle by checking the bounds of the barycentric coordinates
|
||||
// also perform backface culling
|
||||
if(u < 0.0 || v < 0.0 || (u + v) > 1.0 || d > 0.0)
|
||||
if(u < 0.0 || v < 0.0 || (u + v) > 1.0)
|
||||
t = -1.0;
|
||||
|
||||
return vec3(t, u, v);
|
||||
|
|
Reference in New Issue