Path: blob/master/servers/rendering/renderer_rd/effects/roughness_limiter.cpp
10279 views
/**************************************************************************/1/* roughness_limiter.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "roughness_limiter.h"31#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"32#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"3334using namespace RendererRD;3536RoughnessLimiter::RoughnessLimiter() {37// Initialize roughness limiter38Vector<String> shader_modes;39shader_modes.push_back("");4041shader.initialize(shader_modes);4243shader_version = shader.version_create();4445pipeline = RD::get_singleton()->compute_pipeline_create(shader.version_get_shader(shader_version, 0));46}4748RoughnessLimiter::~RoughnessLimiter() {49shader.version_free(shader_version);50}5152void RoughnessLimiter::roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve) {53UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();54ERR_FAIL_NULL(uniform_set_cache);55MaterialStorage *material_storage = MaterialStorage::get_singleton();56ERR_FAIL_NULL(material_storage);5758push_constant.screen_size[0] = p_size.x;59push_constant.screen_size[1] = p_size.y;60push_constant.curve = p_curve;6162RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);63RID rl_shader = shader.version_get_shader(shader_version, 0);6465RD::Uniform u_source_normal(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_normal }));66RD::Uniform u_roughness(RD::UNIFORM_TYPE_IMAGE, 0, Vector<RID>({ p_roughness }));6768RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();69RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, pipeline);70RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(rl_shader, 0, u_source_normal), 0);71RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(rl_shader, 1, u_roughness), 1);7273RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(RoughnessLimiterPushConstant)); //not used but set anyway7475RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_size.x, p_size.y, 1);7677RD::get_singleton()->compute_list_end();78}798081