Browse Source

渲染测式 案例

master
yuanjiajia 1 year ago
parent
commit
8507f038c1
  1. 264
      examples/renderTest.php
  2. 61
      src/scene/materials/MaterialsBase.php
  3. 36
      src/utils/MatHelper.php

264
examples/renderTest.php

@ -3,6 +3,8 @@
namespace Blobt\Luxcore\scene; namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\utils\MatHelper;
use GuzzleHttp\Client; use GuzzleHttp\Client;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php"; include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
@ -15,8 +17,31 @@ const CLOSE = false;
$client = new Client(); $client = new Client();
$response = $client->get("deep3d.backend-api.dev.com/test/render-task"); $response = $client->get("deep3d.backend-api.dev.com/test/render-task");
$resContents = $response->getBody()->getContents(); $resContents = $response->getBody()->getContents();
$resData = json_decode($resContents);
$result = json_decode($resContents,false);
$taskData = $result->data;
$taskScene = $taskData->scene;
$taskModel = $taskScene->model;
// print_r($taskModel);
/**
* 创建个 Luxcore 材质
*/
function createLuxcoreMat($matParams){
switch($matParams->renderType){
case 1:
return MatHelper::createMatOfDisney($matParams);
case 2:
return;
case 3:
return;
case 4:
return;
}
}
@ -27,101 +52,101 @@ $scene = new Scene();
// 一、创建光场: // 一、创建光场:
// 1、创建 面片光001 // 1、创建 面片光001
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('1 1 1');
$scene->registerMaterial($materials);
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1');
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight001.ply'; $obj->ply = './ply/FaceLight001.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 2、创建 面片光002 // 2、创建 面片光002
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('0 0 0');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('0 0 0');
$material->emissionCfg = new lights\Emission([
'gain' => "30 30 30", 'gain' => "30 30 30",
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight002.ply'; $obj->ply = './ply/FaceLight002.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 3、创建 面片光003 // 3、创建 面片光003
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('1 1 1');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
'gain' => "50 50 50", 'gain' => "50 50 50",
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight003.ply'; $obj->ply = './ply/FaceLight003.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 4、创建 面片光004 // 4、创建 面片光004
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('0 0 0');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('0 0 0');
$material->emissionCfg = new lights\Emission([
'gain' => "4 4 4", 'gain' => "4 4 4",
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight004.ply'; $obj->ply = './ply/FaceLight004.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 5、创建 面片光005 // 5、创建 面片光005
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('1 1 1');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
'gain' => "10 10 10", 'gain' => "10 10 10",
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight005.ply'; $obj->ply = './ply/FaceLight005.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 6、创建 面片光006 // 6、创建 面片光006
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('1 1 1');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
'gain' => "8 8 8", 'gain' => "8 8 8",
'mapfile' => "./map/SD-037.exr", 'mapfile' => "./map/SD-037.exr",
'gamma' => 1, 'gamma' => 1,
'storage' => "float" 'storage' => "float"
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight006.ply'; $obj->ply = './ply/FaceLight006.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 7、创建 面片光000 // 7、创建 面片光000
$materials = new materials\Matte();
$materials->setBaseColor('0 0 0');
$materials->setTransparencyShadow('1 1 1');
$materials->setEmission('1 1 1');
$materials->emissionCfg = new lights\Emission([
$material = new materials\Matte();
$material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
'gain' => "3.3 3.3 3.3", 'gain' => "3.3 3.3 3.3",
]); ]);
$scene->registerMaterial($materials);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/FaceLight000.ply'; $obj->ply = './ply/FaceLight000.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 8、创建环境光 // 8、创建环境光
@ -145,31 +170,142 @@ $texture = new texture\procedural\ImageMap([
]); ]);
$texture->mapping = $mapping; $texture->mapping = $mapping;
$scene->registerTexture($texture); $scene->registerTexture($texture);
$materials = new materials\Disney([
$material = new materials\Disney([
'shadowcatcherEnable' => OPEN, 'shadowcatcherEnable' => OPEN,
'photongiEnable' => CLOSE 'photongiEnable' => CLOSE
]); ]);
$materials->setBaseColor('1 1 1');
$materials->setTransparencyFront($texture);
$materials->setTransparencyBack($texture);
$scene->registerMaterial($materials);
$material->setBaseColor('1 1 1');
$material->setTransparencyFront($texture);
$material->setTransparencyBack($texture);
$scene->registerMaterial($material);
$obj = new objects\Objects(); $obj = new objects\Objects();
$obj->ply = './ply/ground.ply'; $obj->ply = './ply/ground.ply';
$obj->setMaterial($materials);
$obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 二、添加要渲染的模型 // 二、添加要渲染的模型
$loadModel = $resData->data->scene->model;
$loadCamera = $resData->data->scene->camera;
foreach($loadModel->childsParams as $childParams){
print_r($childParams);
foreach($taskModel->childsParams as $childParams){
$material = null;
$matParams = (function ($childParams){
if(is_object($childParams->customMat)){
return $childParams->customMat;
}else if(is_object($childParams->fixedMat)){
return $childParams->fixedMat;
}else if(is_object($childParams->defaultMat)){
return $childParams->defaultMat;
}
})($childParams);
if(is_object($matParams)){
$material = createLuxcoreMat($matParams,$scene);
}else{
$material = new materials\Disney();
$material->setBaseColor('1 1 1');
}
$scene->registerMaterial($material);
$obj = new objects\Objects();
$obj->ply = $childParams->childPlyFile;
$obj->setMaterial($material);
$scene->registerObjects($obj);
} }
// 三、创建相机
$camera = new camera\Perspective( // 创建一个相机
[
'autovolumeEnable' => 0, // 关闭自动体积效果
'lookatOrig' => "-3.197486 -4.560584 0.8914337", // 视点坐标位置
'lookatTarget' => "-2.632151 -3.747173 0.7544713", // 目标点坐标位置
'up' => "0.0781663 0.1124666 0.9905763", // 旋转参数
'screenwindow' => "-1 1 -1 1", // 视野比例
'autofocusEnable' => 0, // 关闭自动对焦
'fieldofview' => 3.40608, // 视野角度大小
'cliphither' => 0.1 // 剪切成像起始位置,单位跟随系统
]
);
$camera->bokeh->blades = 0; // 模拟镜头模糊效果的光圈数
$scene->registerCamera($camera); // 将相机注册到 scene 中
// 四、设置渲染参数
$render = '';
$renderEngine = new render\RenderEngine(); // 设置 渲染引擎 的配置参数,默认使用了 PATHOCL,意义着将使用 GPU 设备渲染
$render .= $renderEngine;
$openCL = new render\OpenCL(); // 设置 GPU 渲染参数,这里使用一个默认的参数
$render .= $openCL;
$path = new render\Path(); // 设置 光线跟踪 参数,这里使用一个默认的参数
$render .= $path;
$sampler = new render\Sampler(); // 设置 采样器 配置参数,默认使用 Sobol 类型的自适应采样器
$render .= $sampler;
$lightStrategy = new render\LightStrategy(); // 设置 灯光策略 类型,默认使用 LOG_POWER 类型
$render .= $lightStrategy;
$filesaver = new render\FileSaver(); // 设置 文件储存格式 配置参数
$render .= $filesaver;
$batch = new render\Batch(); // 设置 渲染终止 参数,
$batch->haltspp = 1000; // 设置 每像素 采样达 800 则终止渲染
// $batch->halttime = 2000; // 设置 渲染 超时参数,
$render .= $batch;
$sceneCfg = new render\Scene(); // 设置 场景属性 参数
$render .= $sceneCfg;
$film = new render\Film(); // 添加一个渲染胶片
$film->width = 3000; // 设置渲染胶片宽度,单位像素
$film->heigth = 3000; // 设置渲染胶片宽度,单位像素
$img = new render\Image(); // 添加一个图像输出
$img->effect = [new render\effect\Pretreatment(),new render\effect\ToneMapLinear(),new render\effect\CammaCorrection()];
// 为该图像添加效果管线
$film->addImage($img); // 将该图像输出添加到渲染胶片
$film->addImage(new render\Image(['type' => render\Image::TYPE_OBJECT_ID])); // 为渲染胶片添加一个 通道图类型 的图像输出
$film->addImage(new render\Image(['type' => render\Image::TYPE_RGBA])); // 添加一个 透明底 的图像输出
$img = new render\Image(); // 添加一个图像输出,使用默认参数
$img->effect[] = new render\effect\NoiseReducerOIDN(); // 添加降噪效果管线,使用默认参数
$img->effect[] = new render\effect\Pretreatment(); //
$img->effect[] = new render\effect\ToneMapLinear(); // 添加一亮度效果管线,使用默认参数
$img->effect[] = new render\effect\Synthesis(); // 添加一个合成效果管线,使用默认参数
$img->effect[] = new render\effect\BackgroundImg( // 添加一个背景图像,使用默认参数
[
'file' => "./map/纯白242.png"
]
);
$img->effect[] = new render\effect\CammaCorrection(); // 添加一个 gamma 校正,,使用默认参数
$film->addImage($img); // 将该图像输出添加到渲染胶片
$render .= $film;
// 五、输出场景文件 scene.scn,及渲染文件 render.cfg
echo $scene;
$handle = fopen( "./DemoScene/scene.scn",'w+');
fwrite($handle,$scene);
fclose($handle);
echo $render ;
$handle = fopen( "./DemoScene/render.cfg",'w+');
fwrite($handle,$render);
fclose($handle);
// // 六、启动渲染器
// $cmd = "luxcoreconsole -o ./DemoScene/render.cfg -f ./DemoScene/scene.scn 1>./DemoScene/render.log 2>&1";
// $output;
// $returnVar;
// exec($cmd,$output,$returnVar);
// if( $returnVar == 127 ){
// throw new \Exception("Please install the luxcorerender bin file in the system directory correctly,Or add to the system environment variable");
// }
?> ?>

61
src/scene/materials/MaterialsBase.php

@ -13,52 +13,39 @@ class MaterialsBase extends BaseCfg
/** /**
* 材质类型 * 材质类型
*/ */
const TYPE_DISNEY = 'disney'; //Disney材质,这是一种金属度流程的材质,并加入次表面、透明车漆、镀膜的物殊效果控制,
//是满足大多数材质调节的一种通用材质。
const TYPE_DISNEY = 'disney'; //1, Disney材质,这是一种金属度流程的材质,并加入次表面、透明车漆、镀膜的物殊效果控制,
// 是满足大多数材质调节的一种通用材质。
const TYPE_METAL = 'metal2'; //2, 金属度流程的金属材质
const TYPE_MIRROR = 'mirror'; //3, 镜面材质,金属度流程
const TYPE_METAL = 'metal2'; //金属度流程的金属材质
const TYPE_MIRROR = 'mirror'; //镜面材质,金属度流程
const TYPE_GLOSSY = 'glossy2'; //4, Glossy材质,这是一个高光光泽度流程的材质,是满足大多数以 高光光泽度流程 调节材质的
// 一种通用材质。
const TYPE_GLOSSYCOATING = 'glossycoating'; //5, GlossyCoating材质,这是一个高光光泽度流程的材质,是满足大多数以 高光光泽度流程 调
// 节材质的一种通用材质。使用此类材质不能设置不透明度
const TYPE_GLOSSYTRANSLUCENT = 'glossytranslucent'; //6, GlossyTranslucent材质,这是一个高光光泽度流程的半透明材质,是满足大多数以
// 高光光泽度流程 调节材质的一种通用材质。使用此类材质不能设置不透明度
const TYPE_GLOSSY = 'glossy2'; //Glossy材质,这是一个高光光泽度流程的材质,是满足大多数以 高光光泽度流程 调节材质的
//一种通用材质。
const TYPE_GLASS = 'glass'; //7, 普通的透明材质类型
const TYPE_ARCHGLASS = 'archglass'; //8, 一种没色散属性的薄的透明材质类型,使用这种类型的材质,色散参必须要被禁用。用于薄薄的玻璃,折射不重要的地方(在传输过程中跳
// 过折射,传播alpha和阴影光线。如果不使用此选项,还可以将输出节点中的阴影颜色设置为白色,从而实现相同的效果,同时保持相机光线的折射,如果玻
// 璃板的边缘可见,效果会更好。)
const TYPE_ROUGHGLASS = 'roughglass'; //9, 粗糙玻离材质类型
const TYPE_GLOSSYCOATING = 'glossycoating'; //GlossyCoating材质,这是一个高光光泽度流程的材质,是满足大多数以 高光光泽度流程 调
//节材质的一种通用材质。使用此类材质不能设置不透明度
const TYPE_GLOSSYTRANSLUCENT = 'glossytranslucent'; //GlossyTranslucent材质,这是一个高光光泽度流程的半透明材质,是满足大多数以
//高光光泽度流程 调节材质的一种通用材质。使用此类材质不能设置不透明度
const TYPE_MATTE = 'matte'; //10, 磨砂材质
const TYPE_ROUGHMATTE = 'roughmatte'; //11, 粗糙的磨砂材质
const TYPE_MATTETRANSLUCENT = 'mattetranslucent'; //12, 半透明的磨砂材质
const TYPE_GLASS = 'glass'; //普通的透明材质类型
const TYPE_ARCHGLASS = 'archglass'; //一种没色散属性的薄的透明材质类型,使用这种类型的材质,色散参必须要被禁用。用于薄薄的玻璃,折射不重要的地方(在传输过程中跳
//过折射,传播alpha和阴影光线。如果不使用此选项,还可以将输出节点中的阴影颜色设置为白色,从而实现相同的效果,同时保持相机光线的折射,如果玻
//璃板的边缘可见,效果会更好。)
const TYPE_ROUGHGLASS = 'roughglass'; //粗糙玻离材质类型
const TYPE_MATTE = 'matte'; //磨砂材质
const TYPE_ROUGHMATTE = 'roughmatte'; //粗糙的磨砂材质
const TYPE_MATTETRANSLUCENT = 'mattetranslucent'; //半透明的磨砂材质
const TYPE_CARPAINT = 'carpaint'; //车漆材质,使用此类材质不能设置不透明度
const TYPE_CLOTH = 'cloth'; //布料材质
const TYPE_VELVET = 'velvet'; //丝绒材质
const TYPE_NULL = 'null'; //空的材质
const TYPE_MIX = 'mix'; //材质混合
const TYPE_TWOSIDED = 'twosided'; //双面材质
const TYPE_CARPAINT = 'carpaint'; //13, 车漆材质,使用此类材质不能设置不透明度
const TYPE_CLOTH = 'cloth'; //14, 布料材质
const TYPE_VELVET = 'velvet'; //15, 丝绒材质
const TYPE_NULL = 'null'; //16, 空的材质
const TYPE_MIX = 'mix'; //17, 材质混合
const TYPE_TWOSIDED = 'twosided'; //18, 双面材质
/** /**
* @var string 材质类型 * @var string 材质类型

36
src/utils/MatHelper.php

@ -0,0 +1,36 @@
<?php
namespace Blobt\Luxcore\utils;
class MatHelper
{
/**
* 创建一个 Disney 的材质
*/
static function createMatOfDisney($matParams){
}
/**
* 创建一个 Glass 材质(折射材质)
*/
static function createMatOfGlass(){
}
/**
* 创建一个半透明材质
*/
static function createMatOfTranslucent(){
}
/**
* 创建一个自发光材质
*/
static function createMatOfEmission(){
}
}
?>
Loading…
Cancel
Save