Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions doc/classes/BaseMaterial3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
<member name="depth_draw_mode" type="int" setter="set_depth_draw_mode" getter="get_depth_draw_mode" enum="BaseMaterial3D.DepthDrawMode" default="0">
Determines when depth rendering takes place. See [enum DepthDrawMode]. See also [member transparency].
</member>
<member name="depth_function" type="int" setter="set_depth_function" getter="get_depth_function" enum="BaseMaterial3D.DepthFunction" default="0">
Determines which comparison operator is used when testing depth. See [enum DepthFunction].
</member>
<member name="detail_albedo" type="Texture2D" setter="set_texture" getter="get_texture">
Texture that specifies the color of the detail overlay. [member detail_albedo]'s alpha channel is used as a mask, even when the material is opaque. To use a dedicated texture as a mask, see [member detail_mask].
[b]Note:[/b] [member detail_albedo] is [i]not[/i] modulated by [member albedo_color].
Expand Down Expand Up @@ -355,6 +358,20 @@
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_bit" type="int" setter="set_stencil_bit" getter="get_stencil_bit" default="0">
</member>
<member name="stencil_compare" type="int" setter="set_stencil_compare" getter="get_stencil_compare" enum="BaseMaterial3D.StencilCompareOperator" default="0">
</member>
<member name="stencil_depth_fail" type="int" setter="set_stencil_depth_fail" getter="get_stencil_depth_fail" enum="BaseMaterial3D.StencilOperation" default="0">
</member>
<member name="stencil_enabled" type="bool" setter="set_stencil_enabled" getter="is_stencil_enabled" default="false">
</member>
<member name="stencil_fail" type="int" setter="set_stencil_fail" getter="get_stencil_fail" enum="BaseMaterial3D.StencilOperation" default="0">
</member>
<member name="stencil_pass" type="int" setter="set_stencil_pass" getter="get_stencil_pass" enum="BaseMaterial3D.StencilOperation" default="0">
</member>
<member name="stencil_reference" type="int" setter="set_stencil_reference" getter="get_stencil_reference" default="1">
</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 @@ -440,6 +457,10 @@
</member>
</members>
<constants>
<constant name="STENCIL_BIT_MAX" value="7">
</constant>
<constant name="STENCIL_BIT_MIN" value="0">
</constant>
<constant name="TEXTURE_ALBEDO" value="0" enum="TextureParam">
Texture specifying per-pixel color.
</constant>
Expand Down Expand Up @@ -624,6 +645,30 @@
<constant name="DEPTH_DRAW_DISABLED" value="2" enum="DepthDrawMode">
Objects will not write their depth to the depth buffer, even during the depth prepass (if enabled).
</constant>
<constant name="DEPTH_FUNCTION_LESS_OR_EQUAL" value="0" enum="DepthFunction">
Default depth function. Depth check succeeds if less than or equal to existing depth.
</constant>
<constant name="DEPTH_FUNCTION_LESS" value="1" enum="DepthFunction">
Depth check succeeds if less than existing depth.
</constant>
<constant name="DEPTH_FUNCTION_GREATER_OR_EQUAL" value="2" enum="DepthFunction">
Depth check succeeds if greater than or equal to existing depth.
</constant>
<constant name="DEPTH_FUNCTION_GREATER" value="3" enum="DepthFunction">
Depth check succeeds if greater than existing depth.
</constant>
<constant name="DEPTH_FUNCTION_EQUAL" value="4" enum="DepthFunction">
Depth check succeeds if equal to existing depth.
</constant>
<constant name="DEPTH_FUNCTION_NOT_EQUAL" value="5" enum="DepthFunction">
Depth check succeeds if not equal to existing depth.
</constant>
<constant name="DEPTH_FUNCTION_ALWAYS" value="6" enum="DepthFunction">
Depth check always succeeds.
</constant>
<constant name="DEPTH_FUNCTION_NEVER" value="7" enum="DepthFunction">
Depth check never succeeds.
</constant>
<constant name="CULL_BACK" value="0" enum="CullMode">
Default cull mode. The back of the object is culled when not visible. Back face triangles will be culled when facing the camera. This results in only the front side of triangles being drawn. For closed-surface meshes, this means that only the exterior of the mesh will be visible.
</constant>
Expand Down Expand Up @@ -767,5 +812,37 @@
<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_OP_KEEP" value="0" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_ZERO" value="1" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_REPLACE" value="2" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_INCREMENT_AND_CLAMP" value="3" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_DECREMENT_AND_CLAMP" value="4" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_INVERT" value="5" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_INCREMENT_AND_WRAP" value="6" enum="StencilOperation">
</constant>
<constant name="STENCIL_OP_DECREMENT_AND_WRAP" value="7" enum="StencilOperation">
</constant>
<constant name="STENCIL_COMPARE_OP_NEVER" value="0" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_LESS" value="1" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_EQUAL" value="2" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_LESS_OR_EQUAL" value="3" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_GREATER" value="4" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_NOT_EQUAL" value="5" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_GREATER_OR_EQUAL" value="6" enum="StencilCompareOperator">
</constant>
<constant name="STENCIL_COMPARE_OP_ALWAYS" value="7" enum="StencilCompareOperator">
</constant>
</constants>
</class>
18 changes: 18 additions & 0 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,8 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
RENDER_TIMESTAMP("Render Sky");

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
Expand Down Expand Up @@ -2163,6 +2165,22 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
}
}

if (scene_state.current_depth_function != shader->depth_function) {
GLenum depth_function_table[GLES3::SceneShaderData::DEPTH_FUNCTION_MAX] = {
GL_LEQUAL,
GL_LESS,
GL_GEQUAL,
GL_GREATER,
GL_EQUAL,
GL_NOTEQUAL,
GL_ALWAYS,
GL_NEVER,
};

glDepthFunc(depth_function_table[shader->depth_function]);
scene_state.current_depth_function = shader->depth_function;
}

if (scene_state.current_depth_draw != shader->depth_draw) {
switch (shader->depth_draw) {
case GLES3::SceneShaderData::DEPTH_DRAW_OPAQUE: {
Expand Down
1 change: 1 addition & 0 deletions drivers/gles3/rasterizer_scene_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
GLES3::SceneShaderData::BlendMode current_blend_mode = GLES3::SceneShaderData::BLEND_MODE_MIX;
GLES3::SceneShaderData::DepthDraw current_depth_draw = GLES3::SceneShaderData::DEPTH_DRAW_OPAQUE;
GLES3::SceneShaderData::DepthTest current_depth_test = GLES3::SceneShaderData::DEPTH_TEST_DISABLED;
GLES3::SceneShaderData::DepthFunction current_depth_function = GLES3::SceneShaderData::DEPTH_FUNCTION_LESS_OR_EQUAL;
GLES3::SceneShaderData::Cull cull_mode = GLES3::SceneShaderData::CULL_BACK;

bool texscreen_copied = false;
Expand Down
11 changes: 11 additions & 0 deletions drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,7 @@ void SceneShaderData::set_code(const String &p_code) {

int blend_modei = BLEND_MODE_MIX;
int depth_testi = DEPTH_TEST_ENABLED;
int depth_functioni = DEPTH_FUNCTION_LESS_OR_EQUAL;
int alpha_antialiasing_modei = ALPHA_ANTIALIASING_OFF;
int cull_modei = CULL_BACK;
int depth_drawi = DEPTH_DRAW_OPAQUE;
Expand Down Expand Up @@ -2879,6 +2880,15 @@ void SceneShaderData::set_code(const String &p_code) {

actions.render_mode_values["depth_test_disabled"] = Pair<int *, int>(&depth_testi, DEPTH_TEST_DISABLED);

actions.render_mode_values["depth_function_lequal"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_LESS_OR_EQUAL);
actions.render_mode_values["depth_function_less"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_LESS);
actions.render_mode_values["depth_function_gequal"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_GREATER_OR_EQUAL);
actions.render_mode_values["depth_function_greater"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_GREATER);
actions.render_mode_values["depth_function_equal"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_EQUAL);
actions.render_mode_values["depth_function_notequal"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_NOT_EQUAL);
actions.render_mode_values["depth_function_always"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_ALWAYS);
actions.render_mode_values["depth_function_never"] = Pair<int *, int>(&depth_functioni, DEPTH_FUNCTION_NEVER);

actions.render_mode_values["cull_disabled"] = Pair<int *, int>(&cull_modei, CULL_DISABLED);
actions.render_mode_values["cull_front"] = Pair<int *, int>(&cull_modei, CULL_FRONT);
actions.render_mode_values["cull_back"] = Pair<int *, int>(&cull_modei, CULL_BACK);
Expand Down Expand Up @@ -2934,6 +2944,7 @@ void SceneShaderData::set_code(const String &p_code) {

depth_draw = DepthDraw(depth_drawi);
depth_test = DepthTest(depth_testi);
depth_function = DepthFunction(depth_functioni);
cull_mode = Cull(cull_modei);
blend_mode = BlendMode(blend_modei);
alpha_antialiasing_mode = AlphaAntiAliasing(alpha_antialiasing_modei);
Expand Down
13 changes: 13 additions & 0 deletions drivers/gles3/storage/material_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ struct SceneShaderData : public ShaderData {
DEPTH_TEST_ENABLED
};

enum DepthFunction {
DEPTH_FUNCTION_LESS_OR_EQUAL,
DEPTH_FUNCTION_LESS,
DEPTH_FUNCTION_GREATER_OR_EQUAL,
DEPTH_FUNCTION_GREATER,
DEPTH_FUNCTION_EQUAL,
DEPTH_FUNCTION_NOT_EQUAL,
DEPTH_FUNCTION_ALWAYS,
DEPTH_FUNCTION_NEVER,
DEPTH_FUNCTION_MAX
};

enum Cull {
CULL_DISABLED,
CULL_FRONT,
Expand All @@ -278,6 +290,7 @@ struct SceneShaderData : public ShaderData {
AlphaAntiAliasing alpha_antialiasing_mode;
DepthDraw depth_draw;
DepthTest depth_test;
DepthFunction depth_function;
Cull cull_mode;

bool uses_point_size;
Expand Down
Loading