Skip to content

Commit

Permalink
Added stencil function
Browse files Browse the repository at this point in the history
Updated stencil features to match new design

Fixed stencil opaque pass

Added STENCIL_RW_WRITE_ALWAYS

Added docs for BaseMaterial3D stencil operations

Added mobile renderer support

Renamed stencil rw modes

Implemented property hiding for stencil fields

Updated docs

Apply suggestions from code review

Co-authored-by: A Thousand Ships <[email protected]>

Update scene/resources/material.cpp

Co-authored-by: RedMser <[email protected]>

Update servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp

Co-authored-by: A Thousand Ships <[email protected]>

Added missing cases

Fixed stencil_mode autocompletion

Fixed syntax highlighting of stencil_mode

Added stencil support to VisualShader

Added stencil support for GLES3

Changed stencil property default values in BaseMaterial3D

Revert "Added stencil support for GLES3"

This reverts commit c6f581b.

Removed mask_uses_ref project setting

Changed depth functions to better match PR #73527

Apply suggestions from code review

Co-authored-by: A Thousand Ships <[email protected]>

Changed set_stencil_effect_color to pass by const ref

Fixed errors
  • Loading branch information
apples committed Jul 20, 2024
1 parent 47ff5a9 commit 1c1b7a8
Show file tree
Hide file tree
Showing 19 changed files with 1,056 additions and 87 deletions.
60 changes: 60 additions & 0 deletions doc/classes/BaseMaterial3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@
The method for rendering the specular blob. See [enum SpecularMode].
[b]Note:[/b] [member specular_mode] only applies to the specular blob. It does not affect specular reflections from the sky, screen-space reflections, [VoxelGI], SDFGI or [ReflectionProbe]s. To disable reflections from these sources as well, set [member metallic_specular] to [code]0.0[/code] instead.
</member>
<member name="stencil_color" type="Color" setter="set_stencil_effect_color" getter="get_stencil_effect_color">
The primary color of the stencil effect.
</member>
<member name="stencil_compare" type="int" setter="set_stencil_compare" getter="get_stencil_compare" enum="BaseMaterial3D.StencilCompare">
The comparison operator to use for stencil masking operations. See [enum StencilCompare].
</member>
<member name="stencil_flags" type="int" setter="set_stencil_flags" getter="get_stencil_flags">
The flags dictating how the stencil operation behaves. See [enum StencilFlags].
</member>
<member name="stencil_mode" type="int" setter="set_stencil_mode" getter="get_stencil_mode" enum="BaseMaterial3D.StencilMode" default="0">
The stencil effect mode. See [enum StencilMode].
</member>
<member name="stencil_outline_thickness" type="float" setter="set_stencil_effect_outline_thickness" getter="get_stencil_effect_outline_thickness">
The outline thickness for STENCIL_MODE_OUTLINE.
</member>
<member name="stencil_reference" type="int" setter="set_stencil_reference" getter="get_stencil_reference">
The stencil reference value (0-255). Typically a power of 2.
</member>
<member name="subsurf_scatter_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
If [code]true[/code], subsurface scattering is enabled. Emulates light that penetrates an object's surface, is scattered, and then emerges. Subsurface scattering quality is controlled by [member ProjectSettings.rendering/environment/subsurface_scattering/subsurface_scattering_quality].
</member>
Expand Down Expand Up @@ -805,5 +823,47 @@
<constant name="DISTANCE_FADE_OBJECT_DITHER" value="3" enum="DistanceFadeMode">
Smoothly fades the object out based on the object's distance from the camera using a dithering approach. Dithering discards pixels based on a set pattern to smoothly fade without enabling transparency. On certain hardware, this can be faster than [constant DISTANCE_FADE_PIXEL_ALPHA] and [constant DISTANCE_FADE_PIXEL_DITHER].
</constant>
<constant name="STENCIL_MODE_DISABLED" value="0" enum="StencilMode">
Disables stencil operations.
</constant>
<constant name="STENCIL_MODE_OUTLINE" value="1" enum="StencilMode">
Stencil preset which applies an outline to the object. Requires a next_pass.
</constant>
<constant name="STENCIL_MODE_XRAY" value="2" enum="StencilMode">
Stencil preset which shows a silhouette of the object behind walls. Requires a next_pass.
</constant>
<constant name="STENCIL_MODE_CUSTOM" value="3" enum="StencilMode">
Enables stencil operations without a preset.
</constant>
<constant name="STENCIL_FLAG_READ" value="1" enum="StencilFlags">
The material will only be rendered where it passes a stencil comparison with existing stencil buffer values. See [enum StencilCompare].
</constant>
<constant name="STENCIL_FLAG_WRITE" value="2" enum="StencilFlags">
The material will write the reference value to the stencil buffer where it passes the depth test.
</constant>
<constant name="STENCIL_FLAG_WRITE_DEPTH_FAIL" value="4" enum="StencilFlags">
The material will write the reference value to the stencil buffer where it fails the depth test.
</constant>
<constant name="STENCIL_COMPARE_LESS" value="0" enum="StencilCompare">
Passes the stencil test when the reference value is less than the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_EQUAL" value="1" enum="StencilCompare">
Passes the stencil test when the reference value is equal to the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_LESS_OR_EQUAL" value="2" enum="StencilCompare">
Passes the stencil test when the reference value is less than or equal to the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_GREATER" value="3" enum="StencilCompare">
Passes the stencil test when the reference value is greater than the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_NOT_EQUAL" value="4" enum="StencilCompare">
Passes the stencil test when the reference value is not equal to the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_GREATER_OR_EQUAL" value="5" enum="StencilCompare">
Passes the stencil test when the reference value is greater than or equal to the existing stencil value.
</constant>
<constant name="STENCIL_COMPARE_ALWAYS" value="6" enum="StencilCompare">
Always passes the stencil test.
</constant>
</constants>
</class>
70 changes: 54 additions & 16 deletions editor/plugins/text_shader_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,35 @@ void ShaderTextEditor::_load_theme_settings() {
}
}

const Vector<ShaderLanguage::ModeInfo> &modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(i));
{
const Vector<ShaderLanguage::ModeInfo> &render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(i));

for (int j = 0; j < render_modes.size(); j++) {
const ShaderLanguage::ModeInfo &mode_info = render_modes[j];

if (!mode_info.options.is_empty()) {
for (int k = 0; k < mode_info.options.size(); k++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[k]));
}
} else {
built_ins.push_back(String(mode_info.name));
}
}
}

for (int j = 0; j < modes.size(); j++) {
const ShaderLanguage::ModeInfo &mode_info = modes[j];
{
const Vector<ShaderLanguage::ModeInfo> &stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(i));

if (!mode_info.options.is_empty()) {
for (int k = 0; k < mode_info.options.size(); k++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[k]));
for (int j = 0; j < stencil_modes.size(); j++) {
const ShaderLanguage::ModeInfo &mode_info = stencil_modes[j];

if (!mode_info.options.is_empty()) {
for (int k = 0; k < mode_info.options.size(); k++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[k]));
}
} else {
built_ins.push_back(String(mode_info.name));
}
} else {
built_ins.push_back(String(mode_info.name));
}
}
}
Expand All @@ -289,17 +307,35 @@ void ShaderTextEditor::_load_theme_settings() {
}
}

const Vector<ShaderLanguage::ModeInfo> &modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode()));
{
const Vector<ShaderLanguage::ModeInfo> &shader_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode()));

for (int i = 0; i < shader_modes.size(); i++) {
const ShaderLanguage::ModeInfo &mode_info = shader_modes[i];

if (!mode_info.options.is_empty()) {
for (int j = 0; j < mode_info.options.size(); j++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[j]));
}
} else {
built_ins.push_back(String(mode_info.name));
}
}
}

{
const Vector<ShaderLanguage::ModeInfo> &stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(shader->get_mode()));

for (int i = 0; i < modes.size(); i++) {
const ShaderLanguage::ModeInfo &mode_info = modes[i];
for (int i = 0; i < stencil_modes.size(); i++) {
const ShaderLanguage::ModeInfo &mode_info = stencil_modes[i];

if (!mode_info.options.is_empty()) {
for (int j = 0; j < mode_info.options.size(); j++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[j]));
if (!mode_info.options.is_empty()) {
for (int j = 0; j < mode_info.options.size(); j++) {
built_ins.push_back(String(mode_info.name) + "_" + String(mode_info.options[j]));
}
} else {
built_ins.push_back(String(mode_info.name));
}
} else {
built_ins.push_back(String(mode_info.name));
}
}
}
Expand Down Expand Up @@ -436,6 +472,7 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLa
_check_shader_mode();
comp_info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode()));
comp_info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode()));
comp_info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(shader->get_mode()));
comp_info.shader_types = ShaderTypes::get_singleton()->get_types();

sl.complete(code, comp_info, r_options, calltip);
Expand Down Expand Up @@ -540,6 +577,7 @@ void ShaderTextEditor::_validate_script() {
Shader::Mode mode = shader->get_mode();
comp_info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(mode));
comp_info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(mode));
comp_info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(mode));
comp_info.shader_types = ShaderTypes::get_singleton()->get_types();
}

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5942,6 +5942,7 @@ void VisualShaderEditor::_update_preview() {
ShaderLanguage::ShaderCompileInfo info;
info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode()));
info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
info.shader_types = ShaderTypes::get_singleton()->get_types();
info.global_shader_uniform_type_func = _visual_shader_editor_get_global_shader_uniform_type;

Expand Down
Loading

0 comments on commit 1c1b7a8

Please sign in to comment.