mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-05 14:35:52 +02:00
Merge remote-tracking branch 'overte/master' into master_to_protocol_changes3
This commit is contained in:
commit
8fc734b168
9 changed files with 82 additions and 11 deletions
30
interface/resources/shaders/errorShader.frag
Normal file
30
interface/resources/shaders/errorShader.frag
Normal file
|
@ -0,0 +1,30 @@
|
|||
vec3 getErrorColor() {
|
||||
vec3 positionWS = iWorldOrientation * (_positionMS.xyz * iWorldScale) + iWorldPosition;
|
||||
float checkSize = 0.1;
|
||||
vec3 edges = round(mod(positionWS, vec3(checkSize)) / checkSize);
|
||||
float checkerboard = mod(edges.x + edges.y + edges.z, 2.0);
|
||||
return mix(vec3(1, 0, 1), vec3(0.0), checkerboard);
|
||||
}
|
||||
|
||||
// version 1
|
||||
vec3 getProceduralColor() {
|
||||
return getErrorColor();
|
||||
}
|
||||
|
||||
// version 2
|
||||
float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
|
||||
diffuse = getErrorColor();
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// version 3
|
||||
float getProceduralFragment(inout ProceduralFragment data) {
|
||||
data.emissive = getErrorColor();
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// version 4
|
||||
float getProceduralFragmentWithPosition(inout ProceduralFragmentWithPosition data) {
|
||||
data.emissive = getErrorColor();
|
||||
return 1.0;
|
||||
}
|
7
interface/resources/shaders/errorSkyboxShader.frag
Normal file
7
interface/resources/shaders/errorSkyboxShader.frag
Normal file
|
@ -0,0 +1,7 @@
|
|||
vec3 getSkyboxColor() {
|
||||
vec3 normal = normalize(_normal);
|
||||
float checkSize = 0.1;
|
||||
vec3 edges = round(mod(normal, vec3(checkSize)) / checkSize);
|
||||
float checkerboard = mod(edges.x + edges.y + edges.z, 2.0);
|
||||
return mix(vec3(1, 0, 1), vec3(0.0), checkerboard);
|
||||
}
|
|
@ -64,7 +64,6 @@
|
|||
#include "SpeechRecognizer.h"
|
||||
#endif
|
||||
|
||||
#include "MeshPartPayload.h"
|
||||
#include "scripting/RenderScriptingInterface.h"
|
||||
|
||||
extern bool DEV_DECIMATE_TEXTURES;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <QScreen>
|
||||
#include "ScreenName.h"
|
||||
|
||||
#include <MeshPartPayload.h>
|
||||
#include <procedural/Procedural.h>
|
||||
|
||||
STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
@ -252,7 +252,7 @@ void RenderScriptingInterface::forceProceduralMaterialsEnabled(bool enabled) {
|
|||
_proceduralMaterialsEnabledSetting.set(enabled);
|
||||
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::MaterialProceduralShaders, enabled);
|
||||
ModelMeshPartPayload::enableMaterialProceduralShaders = enabled;
|
||||
Procedural::enableProceduralShaders = enabled;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
Q_LOGGING_CATEGORY(proceduralLog, "hifi.gpu.procedural")
|
||||
|
||||
bool Procedural::enableProceduralShaders = false;
|
||||
|
||||
// User-data parsing constants
|
||||
static const QString PROCEDURAL_USER_DATA_KEY = "ProceduralEntity";
|
||||
static const QString VERTEX_URL_KEY = "vertexShaderURL";
|
||||
|
@ -377,6 +379,27 @@ void Procedural::prepare(gpu::Batch& batch,
|
|||
|
||||
_proceduralPipelines[key] = gpu::Pipeline::create(program, key.isTransparent() ? _transparentState : _opaqueState);
|
||||
|
||||
// Error fallback: pink checkerboard
|
||||
if (_errorFallbackFragmentSource.isEmpty()) {
|
||||
QFile file(_errorFallbackFragmentPath);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
_errorFallbackFragmentSource = QTextStream(&file).readAll();
|
||||
}
|
||||
vertexSource.replacements.erase(PROCEDURAL_BLOCK);
|
||||
fragmentSource.replacements[PROCEDURAL_BLOCK] = _errorFallbackFragmentSource.toStdString();
|
||||
gpu::ShaderPointer errorVertexShader = gpu::Shader::createVertex(vertexSource);
|
||||
gpu::ShaderPointer errorFragmentShader = gpu::Shader::createPixel(fragmentSource);
|
||||
gpu::ShaderPointer errorProgram = gpu::Shader::createProgram(errorVertexShader, errorFragmentShader);
|
||||
_errorPipelines[key] = gpu::Pipeline::create(errorProgram, _opaqueState);
|
||||
|
||||
// Disabled fallback: nothing
|
||||
vertexSource.replacements.erase(PROCEDURAL_BLOCK);
|
||||
fragmentSource.replacements.erase(PROCEDURAL_BLOCK);
|
||||
gpu::ShaderPointer disabledVertexShader = gpu::Shader::createVertex(vertexSource);
|
||||
gpu::ShaderPointer disabledFragmentShader = gpu::Shader::createPixel(fragmentSource);
|
||||
gpu::ShaderPointer disabledProgram = gpu::Shader::createProgram(disabledVertexShader, disabledFragmentShader);
|
||||
_disabledPipelines[key] = gpu::Pipeline::create(disabledProgram, _opaqueState);
|
||||
|
||||
_lastCompile = usecTimestampNow();
|
||||
if (_firstCompile == 0) {
|
||||
_firstCompile = _lastCompile;
|
||||
|
@ -385,8 +408,15 @@ void Procedural::prepare(gpu::Batch& batch,
|
|||
recompiledShader = true;
|
||||
}
|
||||
|
||||
gpu::PipelinePointer finalPipeline = recompiledShader ? _proceduralPipelines[key] : pipeline->second;
|
||||
if (!enableProceduralShaders) {
|
||||
finalPipeline = _disabledPipelines[key];
|
||||
} else if (!finalPipeline || finalPipeline->getProgram()->compilationHasFailed()) {
|
||||
finalPipeline = _errorPipelines[key];
|
||||
}
|
||||
|
||||
// FIXME: need to handle forward rendering
|
||||
batch.setPipeline(recompiledShader ? _proceduralPipelines[key] : pipeline->second);
|
||||
batch.setPipeline(finalPipeline);
|
||||
|
||||
bool recreateUniforms = _shaderDirty || _uniformsDirty || recompiledShader || _prevKey != key;
|
||||
if (recreateUniforms) {
|
||||
|
@ -546,4 +576,6 @@ void graphics::ProceduralMaterial::initializeProcedural() {
|
|||
// FIXME: Setup proper uniform slots and use correct pipelines for forward rendering
|
||||
_procedural._opaqueFragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple_procedural);
|
||||
_procedural._transparentFragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple_procedural_translucent);
|
||||
|
||||
_procedural._errorFallbackFragmentPath = ":" + QUrl("qrc:///shaders/errorShader.frag").path();
|
||||
}
|
|
@ -127,12 +127,16 @@ public:
|
|||
gpu::Shader::Source _opaqueFragmentSource;
|
||||
gpu::Shader::Source _transparentFragmentSource;
|
||||
|
||||
QString _errorFallbackFragmentPath;
|
||||
|
||||
gpu::StatePointer _opaqueState { std::make_shared<gpu::State>() };
|
||||
gpu::StatePointer _transparentState { std::make_shared<gpu::State>() };
|
||||
|
||||
static std::function<void(gpu::StatePointer)> opaqueStencil;
|
||||
static std::function<void(gpu::StatePointer)> transparentStencil;
|
||||
|
||||
static bool enableProceduralShaders;
|
||||
|
||||
protected:
|
||||
// DO NOT TOUCH
|
||||
// We have to pack these in a particular way to match the ProceduralCommon.slh
|
||||
|
@ -179,6 +183,8 @@ protected:
|
|||
bool _shaderDirty { true };
|
||||
bool _uniformsDirty { true };
|
||||
|
||||
QString _errorFallbackFragmentSource;
|
||||
|
||||
// Rendering objects
|
||||
UniformLambdas _uniforms;
|
||||
NetworkTexturePointer _channels[MAX_PROCEDURAL_TEXTURE_CHANNELS];
|
||||
|
@ -186,6 +192,8 @@ protected:
|
|||
std::unordered_map<std::string, std::string> _fragmentReplacements;
|
||||
|
||||
std::unordered_map<ProceduralProgramKey, gpu::PipelinePointer> _proceduralPipelines;
|
||||
std::unordered_map<ProceduralProgramKey, gpu::PipelinePointer> _errorPipelines;
|
||||
std::unordered_map<ProceduralProgramKey, gpu::PipelinePointer> _disabledPipelines;
|
||||
|
||||
StandardInputs _standardInputs;
|
||||
gpu::BufferPointer _standardInputsBuffer;
|
||||
|
|
|
@ -22,6 +22,8 @@ ProceduralSkybox::ProceduralSkybox(uint64_t created) : graphics::Skybox(), _crea
|
|||
_procedural._vertexSource = shader::Source::get(shader::graphics::vertex::skybox);
|
||||
_procedural._opaqueFragmentSource = shader::Source::get(shader::procedural::fragment::proceduralSkybox);
|
||||
|
||||
_procedural._errorFallbackFragmentPath = ":" + QUrl("qrc:///shaders/errorSkyboxShader.frag").path();
|
||||
|
||||
_procedural.setDoesFade(false);
|
||||
|
||||
// Adjust the pipeline state for background using the stencil test
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
using namespace render;
|
||||
|
||||
bool ModelMeshPartPayload::enableMaterialProceduralShaders = false;
|
||||
|
||||
ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex,
|
||||
const Transform& transform, const uint64_t& created) :
|
||||
_meshIndex(meshIndex),
|
||||
|
@ -352,9 +350,6 @@ void ModelMeshPartPayload::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
if (_shapeKey.hasOwnPipeline()) {
|
||||
if (!(enableMaterialProceduralShaders)) {
|
||||
return;
|
||||
}
|
||||
auto procedural = std::static_pointer_cast<graphics::ProceduralMaterial>(_drawMaterials.top().material);
|
||||
auto& schema = _drawMaterials.getSchemaBuffer().get<graphics::MultiMaterial::Schema>();
|
||||
glm::vec4 outColor = glm::vec4(ColorUtils::tosRGBVec3(schema._albedo), schema._opacity);
|
||||
|
|
|
@ -71,8 +71,6 @@ public:
|
|||
|
||||
void setBlendshapeBuffer(const std::unordered_map<int, gpu::BufferPointer>& blendshapeBuffers, const QVector<int>& blendedMeshSizes);
|
||||
|
||||
static bool enableMaterialProceduralShaders;
|
||||
|
||||
private:
|
||||
void initCache(const ModelPointer& model, int shapeID);
|
||||
|
||||
|
|
Loading…
Reference in a new issue