Browse Source

渲染测式 案例 开发

master
yuanjiajia 1 year ago
parent
commit
79f6e9d058
  1. 88
      examples/renderTest.php

88
examples/renderTest.php

@ -4,8 +4,28 @@
namespace Blobt\Luxcore\scene; namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\scene\lights\Emission;
use Blobt\Luxcore\scene\lights\env\HdrImage;
use Blobt\Luxcore\scene\materials\Disney; use Blobt\Luxcore\scene\materials\Disney;
use Blobt\Luxcore\scene\materials\Matte;
use Blobt\Luxcore\scene\objects\Objects; use Blobt\Luxcore\scene\objects\Objects;
use Blobt\Luxcore\scene\render\Batch;
use Blobt\Luxcore\scene\render\effect\BackgroundImg;
use Blobt\Luxcore\scene\render\effect\CammaCorrection;
use Blobt\Luxcore\scene\render\effect\NoiseReducerOIDN;
use Blobt\Luxcore\scene\render\effect\Pretreatment;
use Blobt\Luxcore\scene\render\effect\Synthesis;
use Blobt\Luxcore\scene\render\effect\ToneMapLinear;
use Blobt\Luxcore\scene\render\FileSaver;
use Blobt\Luxcore\scene\render\Film;
use Blobt\Luxcore\scene\render\Image;
use Blobt\Luxcore\scene\render\LightStrategy;
use Blobt\Luxcore\scene\render\OpenCL;
use Blobt\Luxcore\scene\render\Path;
use Blobt\Luxcore\scene\render\RenderEngine;
use Blobt\Luxcore\scene\render\Sampler;
use Blobt\Luxcore\scene\texture\mapping\Mapping;
use Blobt\Luxcore\scene\texture\procedural\ImageMap;
use Blobt\Luxcore\utils\MatHelper; use Blobt\Luxcore\utils\MatHelper;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
@ -58,7 +78,7 @@ $sceneTemplatePath = dirname(dirname(__FILE__)) . "/sceneTemplate";
// 一、创建光场: // 一、创建光场:
// 1、创建 面片光001 // 1、创建 面片光001
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1'); $material->setEmission('1 1 1');
@ -69,11 +89,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 2、创建 面片光002 // 2、创建 面片光002
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('0 0 0'); $material->setEmission('0 0 0');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "30 30 30", 'gain' => "30 30 30",
]); ]);
$scene->registerMaterial($material); $scene->registerMaterial($material);
@ -83,11 +103,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 3、创建 面片光003 // 3、创建 面片光003
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1'); $material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "50 50 50", 'gain' => "50 50 50",
]); ]);
$scene->registerMaterial($material); $scene->registerMaterial($material);
@ -97,11 +117,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 4、创建 面片光004 // 4、创建 面片光004
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('0 0 0'); $material->setEmission('0 0 0');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "4 4 4", 'gain' => "4 4 4",
]); ]);
$scene->registerMaterial($material); $scene->registerMaterial($material);
@ -111,11 +131,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 5、创建 面片光005 // 5、创建 面片光005
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1'); $material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "10 10 10", 'gain' => "10 10 10",
]); ]);
$scene->registerMaterial($material); $scene->registerMaterial($material);
@ -125,11 +145,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 6、创建 面片光006 // 6、创建 面片光006
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1'); $material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "8 8 8", 'gain' => "8 8 8",
'mapfile' => "./map/SD-037.exr", 'mapfile' => "./map/SD-037.exr",
'gamma' => 1, 'gamma' => 1,
@ -142,11 +162,11 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 7、创建 面片光000 // 7、创建 面片光000
$material = new materials\Matte();
$material = new Matte();
$material->setBaseColor('0 0 0'); $material->setBaseColor('0 0 0');
$material->setTransparencyShadow('1 1 1'); $material->setTransparencyShadow('1 1 1');
$material->setEmission('1 1 1'); $material->setEmission('1 1 1');
$material->emissionCfg = new lights\Emission([
$material->emissionCfg = new Emission([
'gain' => "3.3 3.3 3.3", 'gain' => "3.3 3.3 3.3",
]); ]);
$scene->registerMaterial($material); $scene->registerMaterial($material);
@ -156,7 +176,7 @@ $obj->setMaterial($material);
$scene->registerObjects($obj); $scene->registerObjects($obj);
// 8、创建环境光 // 8、创建环境光
$light = new lights\env\HdrImage([
$light = new HdrImage([
'gain' => "1.25 1.25 1.25", 'gain' => "1.25 1.25 1.25",
'transformation' => "0.1736481 -0.9848078 0 0 -0.9848078 -0.1736481 0 0 0 0 1 0 0 0 0 1", 'transformation' => "0.1736481 -0.9848078 0 0 -0.9848078 -0.1736481 0 0 0 0 1 0 0 0 0 1",
'file' => "./map/env.png", 'file' => "./map/env.png",
@ -167,9 +187,9 @@ $light->id = 0;
$scene->registerLight($light); $scene->registerLight($light);
// 9、创建地面模型 // 9、创建地面模型
$mapping = new texture\mapping\Mapping();
$mapping = new Mapping();
$mapping->useUVMapping2d(0, "0", "0.4 -0.966", "0.3 0.983"); $mapping->useUVMapping2d(0, "0", "0.4 -0.966", "0.3 0.983");
$texture = new texture\procedural\ImageMap([
$texture = new ImageMap([
'file' => "./map/方形阴影遮照.png", 'file' => "./map/方形阴影遮照.png",
'gain' => 0.6, 'gain' => 0.6,
'gamma' => 1, 'gamma' => 1,
@ -243,25 +263,25 @@ $scene->registerCamera($camera); // 将相机注册
// 四、设置渲染参数 // 四、设置渲染参数
$render = ''; $render = '';
$renderEngine = new render\RenderEngine(); // 设置 渲染引擎 的配置参数,默认使用了 PATHOCL,意义着将使用 GPU 设备渲染
$renderEngine = new RenderEngine(); // 设置 渲染引擎 的配置参数,默认使用了 PATHOCL,意义着将使用 GPU 设备渲染
$render .= $renderEngine; $render .= $renderEngine;
$openCL = new render\OpenCL(); // 设置 GPU 渲染参数,这里使用一个默认的参数
$openCL = new OpenCL(); // 设置 GPU 渲染参数,这里使用一个默认的参数
$render .= $openCL; $render .= $openCL;
$path = new render\Path(); // 设置 光线跟踪 参数,这里使用一个默认的参数
$path = new Path(); // 设置 光线跟踪 参数,这里使用一个默认的参数
$render .= $path; $render .= $path;
$sampler = new render\Sampler(); // 设置 采样器 配置参数,默认使用 Sobol 类型的自适应采样器
$sampler = new Sampler(); // 设置 采样器 配置参数,默认使用 Sobol 类型的自适应采样器
$render .= $sampler; $render .= $sampler;
$lightStrategy = new render\LightStrategy(); // 设置 灯光策略 类型,默认使用 LOG_POWER 类型
$lightStrategy = new LightStrategy(); // 设置 灯光策略 类型,默认使用 LOG_POWER 类型
$render .= $lightStrategy; $render .= $lightStrategy;
$filesaver = new render\FileSaver(); // 设置 文件储存格式 配置参数
$filesaver = new FileSaver(); // 设置 文件储存格式 配置参数
$render .= $filesaver; $render .= $filesaver;
$batch = new render\Batch(); // 设置 渲染终止 参数,
$batch = new Batch(); // 设置 渲染终止 参数,
$batch->haltspp = 1000; // 设置 每像素 采样达 800 则终止渲染 $batch->haltspp = 1000; // 设置 每像素 采样达 800 则终止渲染
// $batch->halttime = 2000; // 设置 渲染 超时参数, // $batch->halttime = 2000; // 设置 渲染 超时参数,
$render .= $batch; $render .= $batch;
@ -270,23 +290,23 @@ $sceneCfg = new render\Scene(); // 设置 场景属
$render .= $sceneCfg; $render .= $sceneCfg;
$film = new render\Film(); // 添加一个渲染胶片
$film = new Film(); // 添加一个渲染胶片
$film->width = 3000; // 设置渲染胶片宽度,单位像素 $film->width = 3000; // 设置渲染胶片宽度,单位像素
$film->heigth = 3000; // 设置渲染胶片宽度,单位像素 $film->heigth = 3000; // 设置渲染胶片宽度,单位像素
$img = new render\Image(); // 添加一个图像输出
$img->effect = [new render\effect\Pretreatment(),new render\effect\ToneMapLinear(),new render\effect\CammaCorrection()];
$img = new Image(); // 添加一个图像输出
$img->effect = [new Pretreatment(),new ToneMapLinear(),new CammaCorrection()];
// 为该图像添加效果管线 // 为该图像添加效果管线
$film->addImage($img); // 将该图像输出添加到渲染胶片 $film->addImage($img); // 将该图像输出添加到渲染胶片
$film->addImage(new render\Image(['type' => render\Image::TYPE_OBJECT_ID])); // 为渲染胶片添加一个 通道图类型 的图像输出
$film->addImage(new render\Image(['type' => render\Image::TYPE_RGBA])); // 添加一个 透明底 的图像输出
$film->addImage(new Image(['type' => Image::TYPE_OBJECT_ID])); // 为渲染胶片添加一个 通道图类型 的图像输出
$film->addImage(new Image(['type' => 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( // 添加一个背景图像,使用默认参数
$img = new Image(); // 添加一个图像输出,使用默认参数
$img->effect[] = new NoiseReducerOIDN(); // 添加降噪效果管线,使用默认参数
$img->effect[] = new Pretreatment(); //
$img->effect[] = new ToneMapLinear(); // 添加一亮度效果管线,使用默认参数
$img->effect[] = new Synthesis(); // 添加一个合成效果管线,使用默认参数
$img->effect[] = new BackgroundImg( // 添加一个背景图像,使用默认参数
[ [
'file' => "./map/纯白242.png" 'file' => "./map/纯白242.png"
] ]

Loading…
Cancel
Save