FPS view shader with color/texture and metallic
Riordan’s FPS view shader, but modified to include color/texture and metallic features
also fixed a rotation issue
color will add a hint to the texture
if there is no texture then it will all just be the color
Riordan’s shader -> https://godotshaders.com/shader/first-person-view-model-shader/
Shader code
// Riordan's (Kastor) FPS view shader (MIT)
//NICI VERSION
shader_type spatial;
render_mode depth_draw_opaque, cull_back, specular_schlick_ggx;
// FOV and Color
uniform float FOV: hint_range(20, 120) = 40;
uniform vec4 Color: source_color = vec4(1, 1, 1, 1);
uniform sampler2D Texture;
//metalic uniforms
uniform float HowShiny = 0.75;
uniform float Roughness = 0.2;
void vertex() {
// recreate the camera projection matrix with our custom fov value
float scale = 1.0 / tan(FOV * 0.5 * PI / -180.0);
PROJECTION_MATRIX[0][0] = scale / (-VIEWPORT_SIZE.x / VIEWPORT_SIZE.y);
PROJECTION_MATRIX[1][1] = scale;
}
void fragment() {
ivec2 TextureSize = textureSize(Texture, 1);
bool CheckTexture = TextureSize.x > ivec2(1, 1).x && TextureSize.y > ivec2(1, 1).y;
vec4 CurrentColor = CheckTexture ? texture(Texture, UV) : Color;
//Set Color
ALBEDO = CurrentColor.rgb;
EMISSION = Color.rgb;
// Set Metallic and Roughness
METALLIC = HowShiny;
ROUGHNESS = Roughness;
// Scale the depth value 70%, this prevents most clipping.
DEPTH = FRAGCOORD.z;
DEPTH = FRAGCOORD.z * 0.7;
}
Great stuff, although I have no idea how to use my Normal, Metallic, Roughness and AO textures. Please help.