Full BSDF
This commit is contained in:
@ -72,6 +72,8 @@ class Scene {
|
||||
public var embedded: Map<String, kha.Image>;
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
public static inline var MAX_MATERIALS = 16;
|
||||
public static inline var FLOATS_PER_MATERIAL_PARAM = 32; // 8 vec4s per material
|
||||
public var materialParamsBuffer: kha.arrays.Float32Array;
|
||||
public var materialParamsDirty: Bool = true;
|
||||
#end
|
||||
@ -113,7 +115,7 @@ class Scene {
|
||||
#end
|
||||
embedded = new Map();
|
||||
#if (rp_renderer == "Deferred")
|
||||
materialParamsBuffer = new kha.arrays.Float32Array(512);
|
||||
materialParamsBuffer = new kha.arrays.Float32Array(MAX_MATERIALS * FLOATS_PER_MATERIAL_PARAM);
|
||||
#end
|
||||
root = new Object();
|
||||
root.name = "Root";
|
||||
@ -213,11 +215,14 @@ class Scene {
|
||||
}
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
public function markMaterialParamsDirty() {
|
||||
materialParamsDirty = true;
|
||||
}
|
||||
|
||||
public function updateMaterialParams() {
|
||||
if (!materialParamsDirty) return;
|
||||
materialParamsDirty = false;
|
||||
var buf = materialParamsBuffer;
|
||||
for (i in 0...buf.length) buf[i] = 0.0;
|
||||
for (m in meshes) {
|
||||
if (m.materials == null) continue;
|
||||
for (mat in m.materials) {
|
||||
@ -237,12 +242,16 @@ class Scene {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (slot <= 0 || slot >= 16) continue;
|
||||
var base = slot * 32;
|
||||
if (base + 31 >= buf.length) continue;
|
||||
if (slot < 0 || slot >= MAX_MATERIALS) continue;
|
||||
var base = slot * FLOATS_PER_MATERIAL_PARAM;
|
||||
if (base + FLOATS_PER_MATERIAL_PARAM - 1 >= buf.length) continue;
|
||||
if (bc == null) continue;
|
||||
for (i in 0...FLOATS_PER_MATERIAL_PARAM) buf[base + i] = 0.0;
|
||||
buf[base + 6] = 1.5; // coatIOR
|
||||
buf[base + 12] = 1.45; // ior
|
||||
buf[base + 13] = 1.0; // thinWall
|
||||
for (c in bc) {
|
||||
if (c == null || c.name == null) continue;
|
||||
if (c == null || c.name == null || c.floatValue == null) continue;
|
||||
switch (c.name) {
|
||||
// matp0: vec4(anisotropy, anisoRot, sheen, sheenRough)
|
||||
case "anisotropy": buf[base + 0] = c.floatValue;
|
||||
@ -274,8 +283,13 @@ class Scene {
|
||||
case "subsurfaceColorB": buf[base + 21] = c.floatValue;
|
||||
case "sheenTintR": buf[base + 22] = c.floatValue;
|
||||
case "sheenTintG": buf[base + 23] = c.floatValue;
|
||||
// matp6: vec4(sheenTintB, 0, 0, 0)
|
||||
// matp6: vec4(sheenTintB, specularTintR, specularTintG, specularTintB)
|
||||
case "sheenTintB": buf[base + 24] = c.floatValue;
|
||||
case "specularTintR": buf[base + 25] = c.floatValue;
|
||||
case "specularTintG": buf[base + 26] = c.floatValue;
|
||||
case "specularTintB": buf[base + 27] = c.floatValue;
|
||||
// matp7: vec4(subsurfaceScale, 0, 0, 0)
|
||||
case "subsurfaceScale": buf[base + 28] = c.floatValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,7 +445,7 @@ class Scene {
|
||||
var object = new MeshObject(data, materials);
|
||||
parent != null ? object.setParent(parent) : object.setParent(root);
|
||||
#if (rp_renderer == "Deferred")
|
||||
materialParamsDirty = true;
|
||||
markMaterialParamsDirty();
|
||||
#end
|
||||
return object;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user