// // ShapeRender.cpp // render-utils/src // // Created by Zach Pomerantz on 1/4/2015. // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "ShapeRender.h" #include #include #include "DeferredLightingEffect.h" #include "model_vert.h" #include "model_shadow_vert.h" #include "model_normal_map_vert.h" #include "model_lightmap_vert.h" #include "model_lightmap_normal_map_vert.h" #include "skin_model_vert.h" #include "skin_model_shadow_vert.h" #include "skin_model_normal_map_vert.h" #include "model_frag.h" #include "model_shadow_frag.h" #include "model_normal_map_frag.h" #include "model_normal_specular_map_frag.h" #include "model_specular_map_frag.h" #include "model_lightmap_frag.h" #include "model_lightmap_normal_map_frag.h" #include "model_lightmap_normal_specular_map_frag.h" #include "model_lightmap_specular_map_frag.h" #include "model_translucent_frag.h" void ShapeRender::ShapeRender() { // TODO: There is probably a cleaner way to init the pipeline that in a derived class if (_pipelineLib.empty()) { initPipeline(); } } void ShapeRender::initPipeline() { assert(_pipelineLib.empty()); // Vertex shaders auto modelVertex = gpu::Shader::createVertex(std::string(model_vert)); auto modelNormalMapVertex = gpu::Shader::createVertex(std::string(model_normal_map_vert)); auto modelLightmapVertex = gpu::Shader::createVertex(std::string(model_lightmap_vert)); auto modelLightmapNormalMapVertex = gpu::Shader::createVertex(std::string(model_lightmap_normal_map_vert)); auto modelShadowVertex = gpu::Shader::createVertex(std::string(model_shadow_vert)); auto skinModelVertex = gpu::Shader::createVertex(std::string(skin_model_vert)); auto skinModelNormalMapVertex = gpu::Shader::createVertex(std::string(skin_model_normal_map_vert)); auto skinModelShadowVertex = gpu::Shader::createVertex(std::string(skin_model_shadow_vert)); // Pixel shaders auto modelPixel = gpu::Shader::createPixel(std::string(model_frag)); auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag)); auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag)); auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag)); auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag)); auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag)); auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag)); auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag)); auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)); auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)); // Fill the pipelineLib _pipelineLib.addPipeline( RenderKey(0), modelVertex, modelPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_TANGENTS), modelNormalMapVertex, modelNormalMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_SPECULAR), modelVertex, modelSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR), modelNormalMapVertex, modelNormalSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_TRANSLUCENT), modelVertex, modelTranslucentPixel); // FIXME Ignore lightmap for translucents meshpart _pipelineLib.addPipeline( RenderKey(RenderKey::IS_TRANSLUCENT | RenderKey::HAS_LIGHTMAP), modelVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT), modelNormalMapVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT), modelVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT), modelNormalMapVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_LIGHTMAP), modelLightmapVertex, modelLightmapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS), modelLightmapNormalMapVertex, modelLightmapNormalMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_SPECULAR), modelLightmapVertex, modelLightmapSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR), modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED), skinModelVertex, modelPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS), skinModelNormalMapVertex, modelNormalMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR), skinModelVertex, modelSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR), skinModelNormalMapVertex, modelNormalSpecularMapPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_TRANSLUCENT), skinModelVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT), skinModelNormalMapVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT), skinModelVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT), skinModelNormalMapVertex, modelTranslucentPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW), modelShadowVertex, modelShadowPixel); _pipelineLib.addPipeline( RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW), skinModelShadowVertex, modelShadowPixel); } const render::PipelinePointer ShapeRender::pickPipeline(RenderArgs* args, Key& key) { PerformanceTimer perfTimer("ShapeRender::pickPipeline"); auto pipeline = _pickPipeline(args, key); if (!pipeline) { return pipeline; } if ((pipeline->locations->normalFittingMapUnit > -1)) { batch.setResourceTexture(pipeline->locations->normalFittingMapUnit, DependencyManager::get()->getNormalFittingTexture()); } } model::MaterialPointer ShapeRender::_collisionHullMaterial; model::MaterialPointer ShapeRender::getCollisionHullMaterial() { if (!_collisionHullMaterial) { _collisionHullMaterial = std::make_shared(); _collisionHullMaterial->setDiffuse(glm::vec3(1.0f, 0.5f, 0.0f)); _collisionHullMaterial->setMetallic(0.02f); _collisionHullMaterial->setGloss(1.0f); } return _collisionHullMaterial; }