Skip to content

Commit

Permalink
rayrender v0.33.1: Fix ambient light default and add image filename e…
Browse files Browse the repository at this point in the history
…xtension checks
  • Loading branch information
tylermorganwall committed Apr 11, 2024
1 parent 83c0ebd commit 3109c50
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 67 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: rayrender
Type: Package
Title: Build and Raytrace 3D Scenes
Version: 0.33.0
Date: 2024-04-06
Version: 0.33.1
Date: 2024-04-10
Authors@R: c(person("Tyler", "Morgan-Wall", email = "tylermw@gmail.com",
role = c("aut", "cph", "cre"), comment = c(ORCID = "0000-0002-3131-3814")),
person("Syoyo", "Fujita", role=c("ctb", "cph")),
Expand Down
100 changes: 36 additions & 64 deletions R/materials.R
Expand Up @@ -122,18 +122,11 @@ diffuse = function(color = "#ffffff",

info = convert_color(color)
noisecolor = convert_color(noisecolor)
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(alpha_texture) && !is.na(alpha_texture) && !is.character(alpha_texture)) {
alpha_texture = NA
warning("Alpha texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(bump_texture) && !is.na(bump_texture) && !is.character(bump_texture)) {
bump_texture = NA
warning("Bump texture not in recognized format (array, matrix, or filename), ignoring.")
}
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)


type = "diffuse"
if(!is.null(sigma) && is.numeric(sigma)) {
if(sigma < 0) {
Expand Down Expand Up @@ -285,18 +278,10 @@ metal = function(color = "#ffffff",
gradient_point_info = NA
}
noisecolor = convert_color(noisecolor)
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(alpha_texture) && !is.na(alpha_texture) && !is.character(alpha_texture)) {
alpha_texture = NA
warning("Alpha texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(bump_texture) && !is.na(bump_texture) && !is.character(bump_texture)) {
bump_texture = NA
warning("Bump texture not in recognized format (array, matrix, or filename), ignoring.")
}
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)

if(length(eta) == 1) {
eta = c(eta,eta,eta)
}
Expand Down Expand Up @@ -443,10 +428,7 @@ dielectric = function(color="white", refraction = 1.5,
}
attenuation = attenuation * attenuation_intensity

if(!is.array(bump_texture) && !is.na(bump_texture) && !is.character(bump_texture)) {
bump_texture = NA
warning("Bump texture not in recognized format (array, matrix, or filename), ignoring.")
}
bump_texture = check_image_texture(bump_texture)
ray_material(list(type = "dielectric",
properties = list(c(color, refraction, attenuation, priority)),
checkercolor=list(NA),
Expand Down Expand Up @@ -647,22 +629,11 @@ microfacet = function(color="white", roughness = 0.0001, transmission = FALSE,
gradient_point_info = NA
}
noisecolor = convert_color(noisecolor)
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(alpha_texture) && !is.na(alpha_texture) && !is.character(alpha_texture)) {
alpha_texture = NA
warning("Alpha texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(bump_texture) && !is.na(bump_texture) && !is.character(bump_texture)) {
bump_texture = NA
warning("Bump texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(roughness_texture) && !is.na(roughness_texture) && !is.character(roughness_texture)) {
roughness_texture = NA
warning("Roughness texture not in recognized format (array, matrix, or filename), ignoring.")
}
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)
roughness_texture = check_image_texture(roughness_texture)

if(length(image_repeat) == 1) {
image_repeat = c(image_repeat,image_repeat)
}
Expand Down Expand Up @@ -784,10 +755,7 @@ light = function(color = "#ffffff", intensity = 10, importance_sample = TRUE,
gradient_color = NA, gradient_transpose = FALSE,
gradient_point_start = NA, gradient_point_end = NA, gradient_type = "hsv") {
info = convert_color(color)
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
image_texture = check_image_texture(image_texture)
if(length(image_repeat) == 1) {
image_repeat = c(image_repeat,image_repeat)
}
Expand Down Expand Up @@ -993,22 +961,11 @@ glossy = function(color="white", gloss = 1, reflectance = 0.05, microfacet = "tb
gradient_point_info = NA_real_
}
noisecolor = convert_color(noisecolor)
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(alpha_texture) && !is.na(alpha_texture) && !is.character(alpha_texture)) {
alpha_texture = NA_character_
warning("Alpha texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(bump_texture) && !is.na(bump_texture) && !is.character(bump_texture)) {
bump_texture = NA_character_
warning("Bump texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(roughness_texture) && !is.na(roughness_texture) && !is.character(roughness_texture)) {
roughness_texture = NA_character_
warning("Roughness texture not in recognized format (array, matrix, or filename), ignoring.")
}
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)
roughness_texture = check_image_texture(roughness_texture)

if(length(image_repeat) == 1) {
image_repeat = c(image_repeat,image_repeat)
}
Expand Down Expand Up @@ -1162,3 +1119,18 @@ lambertian = function(...) {
diffuse(...)
}

#' Check Image Texture
#' @keywords internal
check_image_texture = function(image_texture) {
if(!is.array(image_texture) && !is.na(image_texture) && !is.character(image_texture)) {
image_texture = NA_character_
warning("Texture not in recognized format (array, matrix, or filename), ignoring.")
}
if(!is.array(image_texture) && !is.na(image_texture) &&
!tools::file_ext(tolower(image_texture)) %in% c("jpg", "jpeg", "png", "hdr")) {
image_texture = NA_character_
warning("Texture not in recognized format (JPEG, PNG, or HDR), ignoring.")
}
return(image_texture)
}

2 changes: 1 addition & 1 deletion R/prepare_scene_list.R
Expand Up @@ -59,7 +59,7 @@ prepare_scene_list = function(scene, width = 400, height = 400, fov = 20,
}


if(scene_info$any_light &&
if(!scene_info$any_light &&
is.null(ambient_light) &&
is.null(environment_light)) {
ambient_light = TRUE
Expand Down

0 comments on commit 3109c50

Please sign in to comment.