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

@ -46,6 +46,12 @@ LIGHTMAP_BICUBIC_FILTER = false
#define SHADER_IS_SRGB true
#define SHADER_SPACE_FAR -1.0
#if defined(RENDER_SHADOWS) || defined(RENDER_SHADOWS_LINEAR)
#define IN_SHADOW_PASS true
#else
#define IN_SHADOW_PASS false
#endif
#include "stdlib_inc.glsl"
#if !defined(MODE_RENDER_DEPTH) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED) ||defined(LIGHT_CLEARCOAT_USED)
@ -607,6 +613,10 @@ void main() {
#endif
#endif
#ifdef Z_CLIP_SCALE_USED
float z_clip_scale = 1.0;
#endif
float roughness = 1.0;
highp mat4 modelview = scene_data.view_matrix * model_matrix;
@ -712,6 +722,12 @@ void main() {
gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
#endif
#if !defined(RENDER_SHADOWS) && !defined(RENDER_SHADOWS_LINEAR)
#ifdef Z_CLIP_SCALE_USED
gl_Position.z = mix(gl_Position.w, gl_Position.z, z_clip_scale);
#endif
#endif
#ifdef RENDER_MATERIAL
vec2 uv_dest_attrib;
if (uv_scale != vec4(0.0)) {
@ -833,6 +849,12 @@ void main() {
#define SHADER_IS_SRGB true
#define SHADER_SPACE_FAR -1.0
#if defined(RENDER_SHADOWS) || defined(RENDER_SHADOWS_LINEAR)
#define IN_SHADOW_PASS true
#else
#define IN_SHADOW_PASS false
#endif
#define FLAGS_NON_UNIFORM_SCALE (1 << 4)
/* Varyings */

View File

@ -1232,6 +1232,7 @@ MaterialStorage::MaterialStorage() {
actions.renames["POINT_SIZE"] = "point_size";
actions.renames["INSTANCE_ID"] = "gl_InstanceID";
actions.renames["VERTEX_ID"] = "gl_VertexID";
actions.renames["Z_CLIP_SCALE"] = "z_clip_scale";
actions.renames["ALPHA_SCISSOR_THRESHOLD"] = "alpha_scissor_threshold";
actions.renames["ALPHA_HASH_SCALE"] = "alpha_hash_scale";
@ -1247,6 +1248,7 @@ MaterialStorage::MaterialStorage() {
actions.renames["E"] = String::num(Math::E);
actions.renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
actions.renames["CLIP_SPACE_FAR"] = "SHADER_SPACE_FAR";
actions.renames["IN_SHADOW_PASS"] = "IN_SHADOW_PASS";
actions.renames["VIEWPORT_SIZE"] = "scene_data.viewport_size";
actions.renames["FRAGCOORD"] = "gl_FragCoord";
@ -1336,6 +1338,7 @@ MaterialStorage::MaterialStorage() {
actions.usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n";
actions.usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n";
actions.usage_defines["LIGHT_VERTEX"] = "#define LIGHT_VERTEX_USED\n";
actions.usage_defines["Z_CLIP_SCALE"] = "#define Z_CLIP_SCALE_USED\n";
actions.usage_defines["ALPHA_SCISSOR_THRESHOLD"] = "#define ALPHA_SCISSOR_USED\n";
actions.usage_defines["ALPHA_HASH_SCALE"] = "#define ALPHA_HASH_USED\n";