Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

RenderingServer

继承: Object

任何可见的东西的服务器。

描述

渲染服务器是所有可见内容的 API 后端。整个场景系统都挂载在它上面来显示。渲染服务器是完全不透明的:内部实现完全取决于具体的实现,无法进行访问。

使用渲染服务器可以完全绕过场景和 Node 系统。如果场景系统是瓶颈所在,那么这样做就可以提升性能,否则无法提升性能(例如已经完全利用 GPU 的情况)。

资源是使用 *_create 函数创建的。这些函数返回的 RID 并不是对对象本身的引用,而是指向这些对象的不透明指针

所有对象都会被绘制到视口中。你可以使用附加到 SceneTreeViewport,或者也可以使用 viewport_create 自行创建。使用自定义场景或画布时,需要使用 viewport_set_scenarioviewport_attach_canvas 将场景或画布附加到视口。

场景:在 3D 中,所有可视对象都必须与一个场景(Scenario)相关联。场景是世界的可视化表示。如果要从正在运行的游戏中访问渲染服务器,那么就可以使用 Node3D.get_world_3d 从任何 Node3D 节点的场景树访问该场景。此外,也可以使用 scenario_create 创建场景。

在 2D 中也是类似的,需要一个画布(Canvas)来绘制所有的画布项。

3D:在 3D 中,所有可视对象都由资源(Resource)和实例(Instance)组成。资源可以是网格、粒子系统、灯光或任何其他 3D 对象。为了使资源可见,必须使用 instance_set_base 将其附加到一个实例。该实例还必须使用 instance_set_scenario 附加到场景中才可见。不带前缀的 RenderingServer 方法通常都是针对 3D 的(但也有例外)。

2D:在 2D 中,所有可见对象都是某种形式的画布项(Canvas Item)。为了使画布项可见,就需要让它成为附加到视口的画布的子项,或者需要让它成为其他画布项的子项,但这些画布项最终也需要是画布的子项。针对 2D 的 RenderingServer 方法一般都以 canvas_* 开头。

无头模式:使用 --headless 命令行参数启动引擎将禁用所有渲染和窗口管理功能。在这种情况下,RenderingServer 中的大多数函数将返回虚值。

教程

属性

bool

render_loop_enabled

方法

Image[]

bake_render_uv2 ( RID base, RID[] material_overrides, Vector2i image_size )

void

call_on_render_thread ( Callable callable )

RID

camera_attributes_create ( )

void

camera_attributes_set_auto_exposure ( RID camera_attributes, bool enable, float min_sensitivity, float max_sensitivity, float speed, float scale )

void

camera_attributes_set_dof_blur ( RID camera_attributes, bool far_enable, float far_distance, float far_transition, bool near_enable, float near_distance, float near_transition, float amount )

void

camera_attributes_set_dof_blur_bokeh_shape ( DOFBokehShape shape )

void

camera_attributes_set_dof_blur_quality ( DOFBlurQuality quality, bool use_jitter )

void

camera_attributes_set_exposure ( RID camera_attributes, float multiplier, float normalization )

RID

camera_create ( )

void

camera_set_camera_attributes ( RID camera, RID effects )

void

camera_set_cull_mask ( RID camera, int layers )

void

camera_set_environment ( RID camera, RID env )

void

camera_set_frustum ( RID camera, float size, Vector2 offset, float z_near, float z_far )

void

camera_set_orthogonal ( RID camera, float size, float z_near, float z_far )

void

camera_set_perspective ( RID camera, float fovy_degrees, float z_near, float z_far )

void

camera_set_transform ( RID camera, Transform3D transform )

void

camera_set_use_vertical_aspect ( RID camera, bool enable )

RID

canvas_create ( )

void

canvas_item_add_animation_slice ( RID item, float animation_length, float slice_begin, float slice_end, float offset=0.0 )

void

canvas_item_add_circle ( RID item, Vector2 pos, float radius, Color color )

void

canvas_item_add_clip_ignore ( RID item, bool ignore )

void

canvas_item_add_lcd_texture_rect_region ( RID item, Rect2 rect, RID texture, Rect2 src_rect, Color modulate )

void

canvas_item_add_line ( RID item, Vector2 from, Vector2 to, Color color, float width=-1.0, bool antialiased=false )

void

canvas_item_add_mesh ( RID item, RID mesh, Transform2D transform=Transform2D(1, 0, 0, 1, 0, 0), Color modulate=Color(1, 1, 1, 1), RID texture=RID() )

void

canvas_item_add_msdf_texture_rect_region ( RID item, Rect2 rect, RID texture, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), int outline_size=0, float px_range=1.0, float scale=1.0 )

void

canvas_item_add_multiline ( RID item, PackedVector2Array points, PackedColorArray colors, float width=-1.0 )

void

canvas_item_add_multimesh ( RID item, RID mesh, RID texture=RID() )

void

canvas_item_add_nine_patch ( RID item, Rect2 rect, Rect2 source, RID texture, Vector2 topleft, Vector2 bottomright, NinePatchAxisMode x_axis_mode=0, NinePatchAxisMode y_axis_mode=0, bool draw_center=true, Color modulate=Color(1, 1, 1, 1) )

void

canvas_item_add_particles ( RID item, RID particles, RID texture )

void

canvas_item_add_polygon ( RID item, PackedVector2Array points, PackedColorArray colors, PackedVector2Array uvs=PackedVector2Array(), RID texture=RID() )

void

canvas_item_add_polyline ( RID item, PackedVector2Array points, PackedColorArray colors, float width=-1.0, bool antialiased=false )

void

canvas_item_add_primitive ( RID item, PackedVector2Array points, PackedColorArray colors, PackedVector2Array uvs, RID texture )

void

canvas_item_add_rect ( RID item, Rect2 rect, Color color )

void

canvas_item_add_set_transform ( RID item, Transform2D transform )

void

canvas_item_add_texture_rect ( RID item, Rect2 rect, RID texture, bool tile=false, Color modulate=Color(1, 1, 1, 1), bool transpose=false )

void

canvas_item_add_texture_rect_region ( RID item, Rect2 rect, RID texture, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), bool transpose=false, bool clip_uv=true )

void

canvas_item_add_triangle_array ( RID item, PackedInt32Array indices, PackedVector2Array points, PackedColorArray colors, PackedVector2Array uvs=PackedVector2Array(), PackedInt32Array bones=PackedInt32Array(), PackedFloat32Array weights=PackedFloat32Array(), RID texture=RID(), int count=-1 )

void

canvas_item_clear ( RID item )

RID

canvas_item_create ( )

void

canvas_item_set_canvas_group_mode ( RID item, CanvasGroupMode mode, float clear_margin=5.0, bool fit_empty=false, float fit_margin=0.0, bool blur_mipmaps=false )

void

canvas_item_set_clip ( RID item, bool clip )

void

canvas_item_set_copy_to_backbuffer ( RID item, bool enabled, Rect2 rect )

void

canvas_item_set_custom_rect ( RID item, bool use_custom_rect, Rect2 rect=Rect2(0, 0, 0, 0) )

void

canvas_item_set_default_texture_filter ( RID item, CanvasItemTextureFilter filter )

void

canvas_item_set_default_texture_repeat ( RID item, CanvasItemTextureRepeat repeat )

void

canvas_item_set_distance_field_mode ( RID item, bool enabled )

void

canvas_item_set_draw_behind_parent ( RID item, bool enabled )

void

canvas_item_set_draw_index ( RID item, int index )

void

canvas_item_set_light_mask ( RID item, int mask )

void

canvas_item_set_material ( RID item, RID material )

void

canvas_item_set_modulate ( RID item, Color color )

void

canvas_item_set_parent ( RID item, RID parent )

void

canvas_item_set_self_modulate ( RID item, Color color )

void

canvas_item_set_sort_children_by_y ( RID item, bool enabled )

void

canvas_item_set_transform ( RID item, Transform2D transform )

void

canvas_item_set_use_parent_material ( RID item, bool enabled )

void

canvas_item_set_visibility_layer ( RID item, int visibility_layer )

void

canvas_item_set_visibility_notifier ( RID item, bool enable, Rect2 area, Callable enter_callable, Callable exit_callable )

void

canvas_item_set_visible ( RID item, bool visible )

void

canvas_item_set_z_as_relative_to_parent ( RID item, bool enabled )

void

canvas_item_set_z_index ( RID item, int z_index )

void

canvas_light_attach_to_canvas ( RID light, RID canvas )

RID

canvas_light_create ( )

void

canvas_light_occluder_attach_to_canvas ( RID occluder, RID canvas )

RID

canvas_light_occluder_create ( )

void

canvas_light_occluder_set_as_sdf_collision ( RID occluder, bool enable )

void

canvas_light_occluder_set_enabled ( RID occluder, bool enabled )

void

canvas_light_occluder_set_light_mask ( RID occluder, int mask )

void

canvas_light_occluder_set_polygon ( RID occluder, RID polygon )

void

canvas_light_occluder_set_transform ( RID occluder, Transform2D transform )

void

canvas_light_set_blend_mode ( RID light, CanvasLightBlendMode mode )

void

canvas_light_set_color ( RID light, Color color )

void

canvas_light_set_enabled ( RID light, bool enabled )

void

canvas_light_set_energy ( RID light, float energy )

void

canvas_light_set_height ( RID light, float height )

void

canvas_light_set_item_cull_mask ( RID light, int mask )

void

canvas_light_set_item_shadow_cull_mask ( RID light, int mask )

void

canvas_light_set_layer_range ( RID light, int min_layer, int max_layer )

void

canvas_light_set_mode ( RID light, CanvasLightMode mode )

void

canvas_light_set_shadow_color ( RID light, Color color )

void

canvas_light_set_shadow_enabled ( RID light, bool enabled )

void

canvas_light_set_shadow_filter ( RID light, CanvasLightShadowFilter filter )

void

canvas_light_set_shadow_smooth ( RID light, float smooth )

void

canvas_light_set_texture ( RID light, RID texture )

void

canvas_light_set_texture_offset ( RID light, Vector2 offset )

void

canvas_light_set_texture_scale ( RID light, float scale )

void

canvas_light_set_transform ( RID light, Transform2D transform )

void

canvas_light_set_z_range ( RID light, int min_z, int max_z )

RID

canvas_occluder_polygon_create ( )

void

canvas_occluder_polygon_set_cull_mode ( RID occluder_polygon, CanvasOccluderPolygonCullMode mode )

void

canvas_occluder_polygon_set_shape ( RID occluder_polygon, PackedVector2Array shape, bool closed )

void

canvas_set_disable_scale ( bool disable )

void

canvas_set_item_mirroring ( RID canvas, RID item, Vector2 mirroring )

void

canvas_set_modulate ( RID canvas, Color color )

void

canvas_set_shadow_texture_size ( int size )

RID

canvas_texture_create ( )

void

canvas_texture_set_channel ( RID canvas_texture, CanvasTextureChannel channel, RID texture )

void

canvas_texture_set_shading_parameters ( RID canvas_texture, Color base_color, float shininess )

void

canvas_texture_set_texture_filter ( RID canvas_texture, CanvasItemTextureFilter filter )

void

canvas_texture_set_texture_repeat ( RID canvas_texture, CanvasItemTextureRepeat repeat )

RenderingDevice

create_local_rendering_device ( ) const

Rect2

debug_canvas_item_get_rect ( RID item )

RID

decal_create ( )

void

decal_set_albedo_mix ( RID decal, float albedo_mix )

void

decal_set_cull_mask ( RID decal, int mask )

void

decal_set_distance_fade ( RID decal, bool enabled, float begin, float length )

void

decal_set_emission_energy ( RID decal, float energy )

void

decal_set_fade ( RID decal, float above, float below )

void

decal_set_modulate ( RID decal, Color color )

void

decal_set_normal_fade ( RID decal, float fade )

void

decal_set_size ( RID decal, Vector3 size )

void

decal_set_texture ( RID decal, DecalTexture type, RID texture )

void

decals_set_filter ( DecalFilter filter )

RID

directional_light_create ( )

void

directional_shadow_atlas_set_size ( int size, bool is_16bits )

void

directional_soft_shadow_filter_set_quality ( ShadowQuality quality )

Image

environment_bake_panorama ( RID environment, bool bake_irradiance, Vector2i size )

RID

environment_create ( )

void

environment_glow_set_use_bicubic_upscale ( bool enable )

void

environment_set_adjustment ( RID env, bool enable, float brightness, float contrast, float saturation, bool use_1d_color_correction, RID color_correction )

void

environment_set_ambient_light ( RID env, Color color, EnvironmentAmbientSource ambient=0, float energy=1.0, float sky_contibution=0.0, EnvironmentReflectionSource reflection_source=0 )

void

environment_set_background ( RID env, EnvironmentBG bg )

void

environment_set_bg_color ( RID env, Color color )

void

environment_set_bg_energy ( RID env, float multiplier, float exposure_value )

void

environment_set_canvas_max_layer ( RID env, int max_layer )

void

environment_set_fog ( RID env, bool enable, Color light_color, float light_energy, float sun_scatter, float density, float height, float height_density, float aerial_perspective, float sky_affect )

void

environment_set_glow ( RID env, bool enable, PackedFloat32Array levels, float intensity, float strength, float mix, float bloom_threshold, EnvironmentGlowBlendMode blend_mode, float hdr_bleed_threshold, float hdr_bleed_scale, float hdr_luminance_cap, float glow_map_strength, RID glow_map )

void

environment_set_sdfgi ( RID env, bool enable, int cascades, float min_cell_size, EnvironmentSDFGIYScale y_scale, bool use_occlusion, float bounce_feedback, bool read_sky, float energy, float normal_bias, float probe_bias )

void

environment_set_sdfgi_frames_to_converge ( EnvironmentSDFGIFramesToConverge frames )

void

environment_set_sdfgi_frames_to_update_light ( EnvironmentSDFGIFramesToUpdateLight frames )

void

environment_set_sdfgi_ray_count ( EnvironmentSDFGIRayCount ray_count )

void

environment_set_sky ( RID env, RID sky )

void

environment_set_sky_custom_fov ( RID env, float scale )

void

environment_set_sky_orientation ( RID env, Basis orientation )

void

environment_set_ssao ( RID env, bool enable, float radius, float intensity, float power, float detail, float horizon, float sharpness, float light_affect, float ao_channel_affect )

void

environment_set_ssao_quality ( EnvironmentSSAOQuality quality, bool half_size, float adaptive_target, int blur_passes, float fadeout_from, float fadeout_to )

void

environment_set_ssil_quality ( EnvironmentSSILQuality quality, bool half_size, float adaptive_target, int blur_passes, float fadeout_from, float fadeout_to )

void

environment_set_ssr ( RID env, bool enable, int max_steps, float fade_in, float fade_out, float depth_tolerance )

void

environment_set_ssr_roughness_quality ( EnvironmentSSRRoughnessQuality quality )

void

environment_set_tonemap ( RID env, EnvironmentToneMapper tone_mapper, float exposure, float white )

void

environment_set_volumetric_fog ( RID env, bool enable, float density, Color albedo, Color emission, float emission_energy, float anisotropy, float length, float p_detail_spread, float gi_inject, bool temporal_reprojection, float temporal_reprojection_amount, float ambient_inject, float sky_affect )

void

environment_set_volumetric_fog_filter_active ( bool active )

void

environment_set_volumetric_fog_volume_size ( int size, int depth )

RID

fog_volume_create ( )

void

fog_volume_set_material ( RID fog_volume, RID material )

void

fog_volume_set_shape ( RID fog_volume, FogVolumeShape shape )

void

fog_volume_set_size ( RID fog_volume, Vector3 size )

void

force_draw ( bool swap_buffers=true, float frame_step=0.0 )

void

force_sync ( )

void

free_rid ( RID rid )

Color

get_default_clear_color ( )

float

get_frame_setup_time_cpu ( ) const

RenderingDevice

get_rendering_device ( ) const

int

get_rendering_info ( RenderingInfo info )

Dictionary[]

get_shader_parameter_list ( RID shader ) const

RID

get_test_cube ( )

RID

get_test_texture ( )

String

get_video_adapter_api_version ( ) const

String

get_video_adapter_name ( ) const