1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Add new StandardMaterial properties to allow users to control FPS-style objects (hands, weapons, tools close to the camera)

Add new shader built in Z_CLIP_SCALE to easily adjust clipping distance to avoid clipping walls etc.

Add fov_override to StandardMaterial3D to easily have a custom FOV for FPS objects

Add IN_SHADOW_PASS built-in to shaders for tweaking materials without impacting shadow maps
This commit is contained in:
clayjohn
2024-06-13 15:16:18 -07:00
parent 25a3c27c41
commit 9a1def8da1
15 changed files with 254 additions and 90 deletions

View File

@@ -400,6 +400,10 @@ void vertex_shader(vec3 vertex_input,
#endif
#endif
#ifdef Z_CLIP_SCALE_USED
float z_clip_scale = 1.0;
#endif
float roughness = 1.0;
mat4 modelview = scene_data.view_matrix * model_matrix;
@@ -644,14 +648,14 @@ void vertex_shader(vec3 vertex_input,
#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
#ifdef MODE_RENDER_DEPTH
if (scene_data.pancake_shadows) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_PANCAKE_SHADOWS)) {
if (gl_Position.z >= 0.9999) {
gl_Position.z = 0.9999;
}
}
#endif
#ifdef MODE_RENDER_MATERIAL
if (scene_data.material_uv2_mode) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_UV2_MATERIAL)) {
vec2 uv_dest_attrib;
if (uv_scale != vec4(0.0)) {
uv_dest_attrib = (uv2_attrib.xy - 0.5) * uv_scale.zw;
@@ -665,6 +669,12 @@ void vertex_shader(vec3 vertex_input,
gl_Position.w = 1.0;
}
#endif
#ifdef Z_CLIP_SCALE_USED
if (!bool(scene_data_block.data.flags & SCENE_DATA_FLAGS_IN_SHADOW_PASS)) {
gl_Position.z = mix(gl_Position.w, gl_Position.z, z_clip_scale);
}
#endif
}
void _unpack_vertex_attributes(vec4 p_vertex_in, vec3 p_compressed_aabb_position, vec3 p_compressed_aabb_size,
@@ -1381,7 +1391,7 @@ void fragment_shader(in SceneData scene_data) {
// to maximize VGPR usage
// Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky.
if (scene_data.fog_enabled) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_FOG)) {
fog = fog_process(vertex);
}
@@ -1391,7 +1401,7 @@ void fragment_shader(in SceneData scene_data) {
#else
vec4 volumetric_fog = volumetric_fog_process(screen_uv, -vertex.z);
#endif
if (scene_data.fog_enabled) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_FOG)) {
//must use the full blending equation here to blend fogs
vec4 res;
float sa = 1.0 - volumetric_fog.a;
@@ -1543,7 +1553,7 @@ void fragment_shader(in SceneData scene_data) {
/////////////////////// LIGHTING //////////////////////////////
#ifdef NORMAL_USED
if (scene_data.roughness_limiter_enabled) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_ROUGHNESS_LIMITER)) {
//https://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf
float roughness2 = roughness * roughness;
vec3 dndu = dFdx(normal), dndv = dFdy(normal);
@@ -1574,7 +1584,7 @@ void fragment_shader(in SceneData scene_data) {
vec3 indirect_normal = normal;
#endif
if (scene_data.use_reflection_cubemap) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_REFLECTION_CUBEMAP)) {
#ifdef LIGHT_ANISOTROPY_USED
// https://google.github.io/filament/Filament.html#lighting/imagebasedlights/anisotropy
vec3 anisotropic_direction = anisotropy >= 0.0 ? binormal : tangent;
@@ -1614,10 +1624,10 @@ void fragment_shader(in SceneData scene_data) {
#ifndef USE_LIGHTMAP
//lightmap overrides everything
if (scene_data.use_ambient_light) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_AMBIENT_LIGHT)) {
ambient_light = scene_data.ambient_light_color_energy.rgb;
if (scene_data.use_ambient_cubemap) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_AMBIENT_CUBEMAP)) {
vec3 ambient_dir = scene_data.radiance_inverse_xform * indirect_normal;
#ifdef USE_RADIANCE_CUBEMAP_ARRAY
vec3 cubemap_ambient = texture(samplerCubeArray(radiance_cubemap, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec4(ambient_dir, MAX_ROUGHNESS_LOD)).rgb;
@@ -1635,7 +1645,7 @@ void fragment_shader(in SceneData scene_data) {
#ifdef LIGHT_CLEARCOAT_USED
if (scene_data.use_reflection_cubemap) {
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_REFLECTION_CUBEMAP)) {
float NoV = max(dot(geo_normal, view), 0.0001); // We want to use geometric normal, not normal_map
vec3 ref_vec = reflect(-view, geo_normal);
ref_vec = mix(ref_vec, geo_normal, clearcoat_roughness * clearcoat_roughness);