setPBRshaders {rgl2gltf} | R Documentation |
Set shaders for physically based rendering.
Description
The glTF format is designed to hold objects which are intended for "physically based rendering", where the parameters of the object map to physical properties such as metallicity, roughness, etc. This function replaces the default rgl shaders with PBR shaders based on the reference implementation in https://github.com/KhronosGroup/glTF-Sample-Viewer/tree/88eda8c5358efe03128b72b6c5f5f6e5b6d023e1/shaders.
Usage
setPBRshaders(gltf, gltfMat, id,
scene = scene3d(minimal = TRUE),
useIBL = TRUE,
brdfLUT = system.file("textures/brdfLUT.png", package = "rgl2gltf"),
IBLspecular = system.file("textures/refmap.png", package = "rgl"),
IBLdiffuse = system.file("textures/refmapblur.jpeg", package = "rgl2gltf"),
debugBaseColor = 0,
debugMetallic = 0,
debugRoughness = 0,
debugSpecularReflection = 0,
debugGeometricOcclusion = 0,
debugMicrofacetDistribution = 0,
debugSpecContrib = 0,
debugDiffuseContrib = 0,
debugIBLDiffuse = 1,
debugIBLSpecular = 1,
defines = list(),
uniforms = list(),
attributes = list(),
textures = list())
Arguments
gltf , gltfMat |
A |
id , scene |
The rgl id of the corresponding object and the scene holding it. |
useIBL |
Whether to use image based lighting. |
brdfLUT |
The texture to use for the "bidirectional reflectance distribution function" lookup table. |
IBLspecular |
The texture to use for the "image based specular lighting". |
IBLdiffuse |
The texture to use for the "image based diffuse lighting". |
debugBaseColor , debugMetallic , debugRoughness , debugSpecularReflection , debugGeometricOcclusion , debugMicrofacetDistribution , debugSpecContrib , debugDiffuseContrib |
These are flags used for debugging. Setting one of these to 1 will display just that contribution to the rendering. |
debugIBLDiffuse , debugIBLSpecular |
Two more debugging settings. These should be set to non-negative values to control the contribution from each of those components to the image based lighting. |
defines , uniforms , attributes , textures |
Values to use in |
Details
rgl is designed to work with WebGL version 1, which doesn't support all of the features used in the reference shaders. In particular, no extensions are assumed, and the IBL textures are single 2D textures rather than cube maps.
Value
This function modifies the id
object in scene
,
and returns the modified scene.
Author(s)
Duncan Murdoch for the adaptation to rgl, various others for the original shaders.
References
https://github.com/KhronosGroup/glTF-Sample-Viewer
See Also
Examples
# This web page has lots of sample files
samples <- "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0"
# Get one of them: a 2 cylinder engine
gltf <- readGLB(paste0(samples, "/NormalTangentTest/glTF-Binary/NormalTangentTest.glb?raw=true"))
gltfMat <- gltf$getMaterial(0)
scene <- as.rglscene(gltf)
id <- scene$objects[[1]]$id
scene <- setPBRshaders(gltf, gltfMat, id, scene)
cat(scene$objects[[1]]$userFragmentShader)