Skip to content

Commit

Permalink
custom shader fix
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jul 5, 2024
1 parent 1c938b5 commit 1a2bac9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
60 changes: 33 additions & 27 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ PipelineState PSO_object_wire_tessellation;
wi::vector<CustomShader> customShaders;
int RegisterCustomShader(const CustomShader& customShader)
{
static std::mutex locker;
std::scoped_lock lck(locker);
int result = (int)customShaders.size();
customShaders.push_back(customShader);
return result;
Expand Down Expand Up @@ -1209,33 +1211,6 @@ void LoadShaders()

wi::jobsystem::Wait(ctx);

// Clear custom shaders (Custom shaders coming from user will need to be handled by the user in case of shader reload):
customShaders.clear();

// Hologram sample shader will be registered as custom shader:
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) {
SHADERTYPE realVS = GetVSTYPE(RENDERPASS_MAIN, false, false, true);

PipelineStateDesc desc;
desc.vs = &shaders[realVS];
desc.ps = &shaders[PSTYPE_OBJECT_HOLOGRAM];

desc.bs = &blendStates[BSTYPE_ADDITIVE];
desc.rs = &rasterizers[RSTYPE_FRONT];
desc.dss = &depthStencils[DSSTYPE_HOLOGRAM];
desc.pt = PrimitiveTopology::TRIANGLELIST;

PipelineState pso;
device->CreatePipelineState(&desc, &pso);

CustomShader customShader;
customShader.name = "Hologram";
customShader.filterMask = FILTER_TRANSPARENT;
customShader.pso[RENDERPASS_MAIN] = pso;
RegisterCustomShader(customShader);
});


wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) {
PipelineStateDesc desc;
desc.vs = &shaders[VSTYPE_OBJECT_SIMPLE];
Expand Down Expand Up @@ -1722,6 +1697,37 @@ void LoadShaders()
};
#endif // RTREFLECTION_WITH_RAYTRACING_PIPELINE

// Clear custom shaders (Custom shaders coming from user will need to be handled by the user in case of shader reload):
customShaders.clear();

// Hologram sample shader will be registered as custom shader:
// It's best to register all custom shaders from the same thread, so under here
// or after engine has been completely initialized
// This is because RegisterCustomShader() will give out IDs in increasing order
// and you can keep the order stable by ensuring they are registered in order.
{
SHADERTYPE realVS = GetVSTYPE(RENDERPASS_MAIN, false, false, true);

PipelineStateDesc desc;
desc.vs = &shaders[realVS];
desc.ps = &shaders[PSTYPE_OBJECT_HOLOGRAM];

desc.bs = &blendStates[BSTYPE_ADDITIVE];
desc.rs = &rasterizers[RSTYPE_FRONT];
desc.dss = &depthStencils[DSSTYPE_HOLOGRAM];
desc.pt = PrimitiveTopology::TRIANGLELIST;

PipelineState pso;
device->CreatePipelineState(&desc, &pso);

CustomShader customShader;
customShader.name = "Hologram";
customShader.filterMask = FILTER_TRANSPARENT;
customShader.pso[RENDERPASS_MAIN] = pso;
RegisterCustomShader(customShader);
}


wi::jobsystem::Wait(ctx);


Expand Down
4 changes: 2 additions & 2 deletions WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 500;
const int revision = 501;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down Expand Up @@ -50,7 +50,7 @@ All contributors: https://github.com/turanszkij/WickedEngine/graphs/contributors
Patreon supporters
---------------------------
Nemerle, James Webb, Quifeng Jin, TheGameCreators, Joseph Goldin, Yuri, Sergey K, Yukawa Kanta, Dragon Josh, John, LurkingNinja, Bernardo Del Castillo, Invictus, Scott Hunt, Yazan Altaki, Tuan NV, Robert MacGregor, cybernescence, Alexander Dahlin, blueapples, Delhills, NI NI, Sherief, ktopoet, Justin Macklin, Cédric Fabre, TogetherTeam, Bartosz Boczula, Arne Koenig, Ivan Trajchev, nathants, Fahd Ahmed, Gabriel Jadderson, SAS_Controller, Dominik Madarász, Segfault, Mike amanfo, Dennis Brakhane, rookie, Peter Moore, therealjtgill, Nicolas Embleton, Desuuc, radino1977, Anthony Curtis, manni heck, Matthias Hölzl, Phyffer, Lucas Pinheiro, Tapkaara, gpman, Anthony Python, Gnowos, Klaus, slaughternaut, Paul Brain, Connor Greaves, Alexandr, Lee Bamber, MCAlarm MC2, Titoutan, Willow, Aldo, lokimx, K. Osterman, Nomad, ykl, Alex Krokos, Timmy, Avaflow, mat, Hexegonel Samael Michael, Joe Spataro, soru, GeniokV, Mammoth, Ignacio, datae, Jason Rice, MarsBEKET
Nemerle, James Webb, Quifeng Jin, TheGameCreators, Joseph Goldin, Yuri, Sergey K, Yukawa Kanta, Dragon Josh, John, LurkingNinja, Bernardo Del Castillo, Invictus, Scott Hunt, Yazan Altaki, Tuan NV, Robert MacGregor, cybernescence, Alexander Dahlin, blueapples, Delhills, NI NI, Sherief, ktopoet, Justin Macklin, Cédric Fabre, TogetherTeam, Bartosz Boczula, Arne Koenig, Ivan Trajchev, nathants, Fahd Ahmed, Gabriel Jadderson, SAS_Controller, Dominik Madarász, Segfault, Mike amanfo, Dennis Brakhane, rookie, Peter Moore, therealjtgill, Nicolas Embleton, Desuuc, radino1977, Anthony Curtis, manni heck, Matthias Hölzl, Phyffer, Lucas Pinheiro, Tapkaara, gpman, Anthony Python, Gnowos, Klaus, slaughternaut, Paul Brain, Connor Greaves, Alexandr, Lee Bamber, MCAlarm MC2, Titoutan, Willow, Aldo, lokimx, K. Osterman, Nomad, ykl, Alex Krokos, Timmy, Avaflow, mat, Hexegonel Samael Michael, Joe Spataro, soru, GeniokV, Mammoth, Ignacio, datae, Jason Rice, MarsBEKET, Tim
)";

return credits;
Expand Down

0 comments on commit 1a2bac9

Please sign in to comment.