Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ork.data/platform_lev2/shaders/fxv2/fwdtools.i2
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ libblock lib_fwd //

vec3 forward_lighting_ntex(vec3 modcolor) {
vec2 uvinvy = abs(frg_uv0.xy);
vec3 albedo = vec3(1,1,1);
vec3 albedo = modcolor;
vec3 TN = vec3(0.5,0.5,1);
vec3 ambrufmtl = vec3(1,1,1);
vec3 ambrufmtl = vec3(1, RoughnessFactor, MetallicFactor);
vec3 emission = vec3(0,0,0);
vec3 N = TN * 2.0 - vec3(1, 1, 1);
bool emissive = false;
vec3 normal = normalize(frg_tbn * N);
return _forward_lightingZ(modcolor, albedo, ambrufmtl, emission, EyePostion, normal, emissive) * modcolor;
return _forward_lightingZ(vec3(1), albedo, ambrufmtl, emission, EyePostion, normal, emissive);
}
}
23 changes: 22 additions & 1 deletion ork.data/platform_lev2/shaders/fxv2/pbr.fxv2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ state_block sb_cullcw : sb_default {
CullTest = PASS_BACK;
}
///////////////////////////////////////////////////////////////
state_block sb_cullcw_alpha : sb_default {
CullTest = PASS_BACK;
BlendMode = ALPHA;
DepthMask = false;
}
///////////////////////////////////////////////////////////////
technique PIK_RI_NI {
fxconfig=fxcfg_default;
vf_pass={vs_pick_rigid_simple_mono,ps_pick,sb_default}
Expand Down Expand Up @@ -55,16 +61,31 @@ technique FWD_CT_NM_RI_NI_MO {
vf_pass={vs_forward_test,ps_forward_test,sb_default}
}
///////////////////////////////////////////////////////////////
technique FWD_CV_NM_RI_NI_MO {
technique FWD_CV_NM_RI_NI_MO {
fxconfig=fxcfg_default;
vf_pass={vs_forward_test_vtxcol,ps_forward_test_vtxcol,sb_cullcw}
}
///////////////////////////////////////////////////////////////
technique FWD_CV_NM_RI_NI_MO_ALPHA {
fxconfig=fxcfg_default;
vf_pass={vs_forward_test_vtxcol,ps_forward_test_vtxcol_alpha,sb_cullcw_alpha}
}
///////////////////////////////////////////////////////////////
technique FWD_CT_NM_RI_IN_MO {
fxconfig=fxcfg_default;
vf_pass={vs_forward_instanced,ps_forward_test,sb_default}
}
///////////////////////////////////////////////////////////////
technique FWD_CV_NM_RI_IN_MO {
fxconfig=fxcfg_default;
vf_pass={vs_forward_instanced_vc,ps_forward_test_vtxcol,sb_cullcw}
}
///////////////////////////////////////////////////////////////
technique FWD_CV_NM_RI_IN_MO_ALPHA {
fxconfig=fxcfg_default;
vf_pass={vs_forward_instanced_vc,ps_forward_instanced_vtxcol_alpha,sb_cullcw_alpha}
}
///////////////////////////////////////////////////////////////
technique FWD_CT_NM_SK_NI_MO {
fxconfig=fxcfg_default;
vf_pass={vs_forward_skinned_mono,ps_forward_test,sb_default}
Expand Down
43 changes: 37 additions & 6 deletions ork.data/platform_lev2/shaders/fxv2/pbrtools.i2
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,33 @@ fragment_shader ps_forward_test_vtxcol //
: lib_brdf //
: lib_def //
: lib_fwd
: std_forward_all {
out_color = vec4(forward_lighting_ntex(frg_clr.xyz), 1);
: std_forward_all {
out_color = vec4(forward_lighting_ntex(frg_clr.xyz) * ModColor.rgb, frg_clr.a * ModColor.a);
}
//////////////////////////////////////
fragment_shader ps_forward_test_vtxcol_alpha //
: fif_FWDTESTVC //
: lib_math //
: lib_brdf //
: lib_def //
: lib_fwd
: std_forward_all {
vec3 lit = forward_lighting_ntex(frg_clr.xyz) * ModColor.rgb;
float vtx_alpha = frg_clr.a;
float lum = dot(lit, vec3(0.2126, 0.7152, 0.0722));
float boosted = clamp(vtx_alpha + lum * (1.0 - vtx_alpha), vtx_alpha, 1.0);
out_color = vec4(lit, boosted * ModColor.a);
}
//////////////////////////////////////
fragment_shader ps_forward_instanced_vtxcol_alpha //
: fif_FWDTESTVC //
: lib_math //
: lib_brdf //
: lib_def //
: lib_fwd
: std_forward_all {
vec3 lit = forward_lighting_ntex(frg_clr.xyz);
out_color = vec4(lit, frg_clr.a);
}
//////////////////////////////////////
fragment_shader ps_forward_test //
Expand All @@ -444,13 +469,19 @@ vertex_shader vs_forward_instanced
: vif_FWDTEST
: storage_instancing
: lib_pbr_vtx_instanced {
////////////////////////////////
// fetch instance matrix from SSBO
////////////////////////////////
mat4 instancemtx = _instance_matrices[gl_InstanceIndex];
vec4 instanced_pos = instancemtx * position;
vs_instanced(position, normal, binormal);
////////////////////////////////
gl_Position = mvp * instanced_pos;
}
///////////////////////////////////////////////////////////////
vertex_shader vs_forward_instanced_vc
: vif_FWDTESTVC
: storage_instancing
: lib_pbr_vtx_instanced_vc {
mat4 instancemtx = _instance_matrices[gl_InstanceIndex];
vec4 instanced_pos = instancemtx * position;
vs_instanced_vc(position, normal, binormal, vtxcolor);
gl_Position = mvp * instanced_pos;
}
///////////////////////////////////////////////////////////////
Expand Down
18 changes: 18 additions & 0 deletions ork.data/platform_lev2/shaders/fxv2/stdtools.i2
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,21 @@ libblock lib_pbr_vtx_instanced : ublk_std_matrices : storage_instancing {
}
} // lib_pbr_vtx_instanced
///////////////////////////////////////////////////////////////
libblock lib_pbr_vtx_instanced_vc : ublk_std_matrices : storage_instancing {
void vs_instanced_vc(vec4 pos, vec3 nrm, vec3 bin, vec4 vclr) {
mat4 instance_matrix = _instance_matrices[gl_InstanceIndex];
vec4 instance_color = _instance_colors[gl_InstanceIndex];
mat3 instance_rot = mat3(instance_matrix);
vec4 cpos = mv * (instance_matrix * pos);
vec3 wnormal = normalize(instance_rot * nrm);
vec3 wbitangent = normalize(instance_rot * bin);
vec3 wtangent = cross(wbitangent, wnormal);
frg_wpos = m * (instance_matrix * pos);
frg_uv0 = vec2(0, 0);
frg_tbn = mat3(wtangent, wbitangent, wnormal);
frg_camz = wnormal.xyz;
frg_camdist = -cpos.z;
frg_clr = vclr * instance_color;
}
} // lib_pbr_vtx_instanced_vc
///////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions ork.lev2/inc/ork/lev2/gfx/fx_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct FxPipelinePermutation {
bool _skinned = false;
bool _is_picking = false;
bool _has_vtxcolors = false;
bool _is_alpha = false;
bool _vr_mono = false;

fxtechnique_constptr_t _forced_technique = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions ork.lev2/inc/ork/lev2/gfx/material_pbr.inl
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ public:
// texcolor

fxtechnique_constptr_t _tek_FWD_CT_NM_RI_IN_MO = nullptr;
fxtechnique_constptr_t _tek_FWD_CV_NM_RI_IN_MO = nullptr;
fxtechnique_constptr_t _tek_FWD_CV_NM_RI_IN_MO_ALPHA = nullptr;
fxtechnique_constptr_t _tek_FWD_CT_NM_RI_NI_MO = nullptr;
fxtechnique_constptr_t _tek_FWD_CV_NM_RI_NI_MO = nullptr;
fxtechnique_constptr_t _tek_FWD_CV_NM_RI_NI_MO_ALPHA = nullptr;
fxtechnique_constptr_t _tek_FWD_CT_NM_RI_IN_ST = nullptr;
fxtechnique_constptr_t _tek_FWD_CT_NM_RI_NI_ST = nullptr;

Expand Down Expand Up @@ -376,6 +379,7 @@ public:

bool _stereoVtex = false;
bool _doubleSided = false;
bool _alphaBlend = false;
float _alphaCutoff = 0.0f;
int _alphaMode = 0; // 0=OPAQUE, 1=MASK, 2=BLEND

Expand Down
95 changes: 94 additions & 1 deletion ork.lev2/inc/ork/lev2/gfx/meshutil/rigid_primitive.inl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ork/lev2/gfx/gfxenv_enum.h>
#include <ork/lev2/gfx/gfxvtxbuf.h>
#include <ork/lev2/gfx/gfxmaterial.h>
#include <ork/lev2/gfx/material_pbr.inl>
#include <ork/lev2/gfx/gfxmodel.h>
#include <ork/lev2/gfx/targetinterfaces.h>
#include <unordered_map>
Expand Down Expand Up @@ -128,6 +129,7 @@ template <typename vtx_t> struct RigidPrimitive : public RigidPrimitiveBase {

void fromClusterizer(const XgmClusterizerStd& cluz, lev2::Context* context);
void renderEML(lev2::Context* context) const; /// draw with context
void renderInstancedEML(lev2::Context* context, size_t instance_count) const; /// draw instanced

void renderUnitOrthoWithMaterial(lev2::Context* context, const SRect& vprect, lev2::GfxMaterial* pmat) const;

Expand Down Expand Up @@ -179,7 +181,11 @@ template <typename vtx_t> struct RigidPrimitive : public RigidPrimitiveBase {
//////////////////////////////////////////////////////////////////////////////
void installInCallbackDrawable(lev2::callback_drawable_wkptr_t drw, lev2::material_ptr_t material){
OrkAssert(material != nullptr);
drw.lock()->SetRenderCallback([this,material](lev2::RenderContextInstData& RCID) { //
bool is_alpha = false;
if (auto as_pbr = std::dynamic_pointer_cast<lev2::PBRMaterial>(material)) {
is_alpha = as_pbr->_alphaBlend;
}
drw.lock()->SetRenderCallback([this,material,is_alpha](lev2::RenderContextInstData& RCID) { //
auto context = RCID.context();
auto RCFD = RCID.rcfd();
lev2::FxPipelinePermutation permu;
Expand All @@ -188,6 +194,7 @@ template <typename vtx_t> struct RigidPrimitive : public RigidPrimitiveBase {
permu._skinned = false;
permu._is_picking = false;
permu._has_vtxcolors = true;
permu._is_alpha = is_alpha;
permu._rendering_model = RCFD->_renderingmodel._modelID;
auto fxcache = material->pipelineCache();
auto pipeline = fxcache->findPipeline(permu);
Expand Down Expand Up @@ -616,6 +623,19 @@ template <typename vtx_t> void RigidPrimitive<vtx_t>::renderEML(lev2::Context* c
}
}
////////////////////////////////////////////////////////////////////////////////
template <typename vtx_t> void RigidPrimitive<vtx_t>::renderInstancedEML(lev2::Context* context, size_t instance_count) const {
auto gbi = context->GBI();
for (auto& cluster : _gpuClusters) {
for (auto& primgroup : cluster->_primgroups) {
gbi->DrawInstancedIndexedPrimitiveEML(
*cluster->_vtxbuffer.get(),
*primgroup->_idxbuffer.get(),
primgroup->_primtype,
instance_count);
}
}
}
////////////////////////////////////////////////////////////////////////////////
template <typename vtx_t>
void RigidPrimitive<vtx_t>::renderUnitOrthoWithMaterial(lev2::Context* context, const SRect& vprect, lev2::GfxMaterial* pmat)
const {
Expand Down Expand Up @@ -660,5 +680,78 @@ using rigidprim_V12C4T16_ptr_t = std::shared_ptr<rigidprim_V12C4T16_t>;
using rigidprim_V12N12T16_ptr_t = std::shared_ptr<rigidprim_V12N12T16_t>;
using rigidprim_V12N12B12T8C4_t = meshutil::RigidPrimitive<lev2::SVtxV12N12B12T8C4>;
using rigidprim_V12N12B12T8C4_ptr_t = std::shared_ptr<rigidprim_V12N12B12T8C4_t>;
///////////////////////////////////////////////////////////////////////////////

template <typename vtx_t>
struct InstancedRigidPrimitiveDrawable final : public lev2::InstancedDrawable {

InstancedRigidPrimitiveDrawable() = default;

void bindPrimitive(std::shared_ptr<RigidPrimitive<vtx_t>> prim, lev2::material_ptr_t material) {
_primitive = prim;
_material = material;
_fxcache = material->pipelineCache();
}

void gpuInit(lev2::Context* ctx) const {
auto FXI = ctx->FXI();
_instanceSSBO = FXI->createStorageBuffer(k_ssbo_total_size);
}

void enqueueToRenderQueue(lev2::drawqueueitem_constptr_t item, lev2::IRenderer* renderer) const override {
auto context = renderer->GetTarget();
if (!_instanceSSBO) {
gpuInit(context);
}
lev2::CallbackRenderable& renderable = renderer->enqueueCallback();
renderable._drawable = nullptr;
renderable._pickID = _pickID;
renderable._sortkey = _sortkey;
renderable._instanced = true;
renderable.SetModColor(fcolor4::White());
renderable.SetDrawableDataA(GetUserDataA());
renderable.SetDrawableDataB(GetUserDataB());
bool is_alpha = false;
if (auto as_pbr = std::dynamic_pointer_cast<lev2::PBRMaterial>(_material)) {
is_alpha = as_pbr->_alphaBlend;
}
renderable.SetRenderCallback([this, is_alpha](lev2::RenderContextInstData& RCID) {
auto context = RCID.context();
auto RCFD = RCID.rcfd();
auto FXI = context->FXI();
OrkAssert(_count <= k_max_instances);
auto instances_copy = _idbuf_pool.begin_pull();
auto ssbo_mapped = FXI->mapStorageBuffer(_instanceSSBO, 0, k_ssbo_total_size, lev2::BufferMapAccess::WRITE_ONLY);
char* base_ptr = (char*)ssbo_mapped->_mappedaddr;
memcpy(base_ptr + k_ssbo_offset_matrices, instances_copy->_worldmatrices.data(), _count * 64);
memcpy(base_ptr + k_ssbo_offset_colors, instances_copy->_modcolors.data(), _count * 16);
memcpy(base_ptr + k_ssbo_offset_pickids, instances_copy->_pickids.data(), _count * 8);
ssbo_mapped->unmap();
_idbuf_pool.end_pull(instances_copy);
lev2::FxPipelinePermutation permu;
permu._stereo = false;
permu._instanced = true;
permu._skinned = false;
permu._is_picking = false;
permu._has_vtxcolors = true;
permu._is_alpha = is_alpha;
permu._rendering_model = RCFD->_renderingmodel._modelID;
auto pipeline = _fxcache->findPipeline(permu);
OrkAssert(pipeline);
pipeline->wrappedDrawCall(RCID, [&]() {
if (pipeline->_parInstanceBlock) {
FXI->bindStorageBuffer(pipeline->_parInstanceBlock, _instanceSSBO);
}
_primitive->renderInstancedEML(context, _count);
});
RCID._isInstanced = false;
});
}

std::shared_ptr<RigidPrimitive<vtx_t>> _primitive;
lev2::material_ptr_t _material;
lev2::fxpipelinecache_constptr_t _fxcache;
};

///////////////////////////////////////////////////////////////////////////////
} // namespace ork::meshutil
51 changes: 49 additions & 2 deletions ork.lev2/pyext/src/pyext_gfx_lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ void pyinit_gfx_lighting(py::module& module_lev2) {
[](lightdata_ptr_t lightdata, fvec3 color) { //
lightdata->mColor = color;
})
.def_property(
"intensity", //
[](lightdata_ptr_t lightdata) -> float { //
return lightdata->_intensity;
},
[](lightdata_ptr_t lightdata, float v) { //
lightdata->_intensity = v;
})
.def_property(
"shadowCaster", //
[](lightdata_ptr_t lightdata) -> bool { //
return lightdata->mbShadowCaster;
},
[](lightdata_ptr_t lightdata, bool v) { //
lightdata->mbShadowCaster = v;
})
.def_property(
"shadowBias", //
[](lightdata_ptr_t lightdata) -> float { //
Expand All @@ -78,6 +94,22 @@ void pyinit_gfx_lighting(py::module& module_lev2) {
});
py::class_<PointLightData, LightData, pointlightdata_ptr_t>(module_lev2, "PointLightData")
.def(py::init<>())
.def_property(
"radius", //
[](pointlightdata_ptr_t lightdata) -> float { //
return lightdata->_radius;
},
[](pointlightdata_ptr_t lightdata, float v) { //
lightdata->_radius = v;
})
.def_property(
"falloff", //
[](pointlightdata_ptr_t lightdata) -> float { //
return lightdata->_falloff;
},
[](pointlightdata_ptr_t lightdata, float v) { //
lightdata->_falloff = v;
})
.def(
"createNode", //
[](pointlightdata_ptr_t lightdata, //
Expand Down Expand Up @@ -108,7 +140,16 @@ void pyinit_gfx_lighting(py::module& module_lev2) {
.def_property(
"cookiePath", //
[](spotlightdata_ptr_t d) -> std::string { return d->_cookiePath.c_str(); },
[](spotlightdata_ptr_t d, std::string p) { d->_cookiePath = file::Path(p.c_str()); });
[](spotlightdata_ptr_t d, std::string p) { d->_cookiePath = file::Path(p.c_str()); })
.def(
"createNode", //
[](spotlightdata_ptr_t lightdata, //
std::string named,
scenegraph::layer_ptr_t layer) -> scenegraph::lightnode_ptr_t { //
auto xfgen = [] -> fmtx4 { return fmtx4(); };
auto light = std::make_shared<SpotLight>(xfgen, lightdata.get());
return layer->createLightNode(named, light);
});
/////////////////////////////////////////////////////////////////////////////////
py::class_<Light, light_ptr_t>(module_lev2, "Light")
.def_property_readonly(
Expand Down Expand Up @@ -173,7 +214,13 @@ void pyinit_gfx_lighting(py::module& module_lev2) {
return light->mViewMatrix;
});
/////////////////////////////////////////////////////////////////////////////////
py::class_<DynamicPointLight, PointLight, dynamicpointlight_ptr_t>(module_lev2, "DynamicPointLight");
py::class_<DynamicPointLight, PointLight, dynamicpointlight_ptr_t>(module_lev2, "DynamicPointLight")
.def(py::init<>())
.def_property_readonly(
"data",
[](dynamicpointlight_ptr_t light) -> pointlightdata_ptr_t {
return light->_inlineData;
});
/////////////////////////////////////////////////////////////////////////////////
py::class_<DynamicDirectionalLight, DirectionalLight, dynamicdirectionallight_ptr_t>(module_lev2, "DynamicDirectionalLight");
/////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions ork.lev2/pyext/src/pyext_gfx_pbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ void pyinit_gfx_pbr(py::module& module_lev2) {
[](pbrmaterial_ptr_t m, bool p) { //
m->_doubleSided = p;
})
.def_property(
"alphaBlend",
[](pbrmaterial_ptr_t m) -> bool { return m->_alphaBlend; },
[](pbrmaterial_ptr_t m, bool v) { m->_alphaBlend = v; })
.def_property(
"pbrcommon",
[](pbrmaterial_ptr_t mtl) -> pbr::commonstuff_ptr_t { //
Expand Down
Loading