-
-
Save Victoralm/d586583a176041239d7d038d6275b51e to your computer and use it in GitHub Desktop.
My attempt to make a splatmap with Albedo, Metallic, Roughness, Normal and AO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx; | |
uniform sampler2D splatmap; | |
uniform sampler2D groundBaseColor: hint_albedo; | |
uniform float groundSpecular = 0.5; | |
uniform float groundMetallic; | |
uniform float groundRoughness : hint_range(0,1); | |
uniform float groundPoint_size : hint_range(0,128) = 1; | |
uniform sampler2D groundMetallicTexture : hint_white; | |
uniform vec4 groundMetallicTexture_channel = vec4(1, 0, 0, 0); | |
uniform sampler2D groundRoughnessTexture : hint_white; | |
uniform vec4 groundRoughnessTexture_channel = vec4(0, 1, 0, 0); | |
uniform sampler2D groundNormalTexture : hint_normal; | |
uniform float groundNormalTexture_scale : hint_range(-16,16) = 1; | |
uniform float groundTexturesRes = 1; | |
uniform sampler2D groundAmbientOcclusionTexture : hint_white; | |
uniform vec4 groundAmbientOcclusionTexture_channel = vec4(0, 0, 1, 0); | |
uniform float groundA_O_Texture_light_affect = 1; | |
uniform sampler2D dirtBaseColor: hint_albedo; | |
uniform float dirtSpecular = 0.5; | |
uniform float dirtMetallic; | |
uniform float dirtRoughness : hint_range(0,1); | |
uniform float dirtPoint_size : hint_range(0,128) = 1; | |
uniform sampler2D dirtMetallicTexture : hint_white; | |
uniform vec4 dirtMetallicTexture_channel = vec4(1, 0, 0, 0); | |
uniform sampler2D dirtRoughnessTexture : hint_white; | |
uniform vec4 dirtRoughnessTexture_channel = vec4(0, 1, 0, 0); | |
uniform sampler2D dirtNormalTexture : hint_normal; | |
uniform float dirtNormalTexture_scale : hint_range(-16,16) = 1; | |
uniform float dirtTexturesRes = 1; | |
uniform sampler2D dirtAmbientOcclusionTexture : hint_white; | |
uniform vec4 dirtAmbientOcclusionTexture_channel = vec4(0, 0, 1, 0); | |
uniform float dirtA_O_Texture_light_affect = 1; | |
uniform sampler2D cliffBaseColor: hint_albedo; | |
uniform float cliffSpecular = 0.5; | |
uniform float cliffMetallic; | |
uniform float cliffRoughness : hint_range(0,1); | |
uniform float cliffPoint_size : hint_range(0,128) = 1; | |
uniform sampler2D cliffMetallicTexture : hint_white; | |
uniform vec4 cliffMetallicTexture_channel = vec4(1, 0, 0, 0); | |
uniform sampler2D cliffRoughnessTexture : hint_white; | |
uniform vec4 cliffRoughnessTexture_channel = vec4(0, 1, 0, 0); | |
uniform sampler2D cliffNormalTexture : hint_normal; | |
uniform float cliffNormalTexture_scale : hint_range(-16,16) = 1; | |
uniform float cliffTexturesRes = 1; | |
uniform sampler2D cliffAmbientOcclusionTexture : hint_white; | |
uniform vec4 cliffAmbientOcclusionTexture_channel = vec4(0, 0, 1, 0); | |
uniform float cliffA_O_Texture_light_affect = 1; | |
uniform sampler2D snowBaseColor: hint_albedo; | |
uniform float snowSpecular = 0.5; | |
uniform float snowMetallic; | |
uniform float snowRoughness : hint_range(0,1); | |
uniform float snowPoint_size : hint_range(0,128) = 1; | |
uniform sampler2D snowMetallicTexture : hint_white; | |
uniform vec4 snowMetallicTexture_channel = vec4(1, 0, 0, 0); | |
uniform sampler2D snowRoughnessTexture : hint_white; | |
uniform vec4 snowRoughnessTexture_channel = vec4(0, 1, 0, 0); | |
uniform sampler2D snowNormalTexture : hint_normal; | |
uniform float snowNormalTexture_scale : hint_range(-16,16) = 1; | |
uniform float snowTexturesRes = 1; | |
uniform sampler2D snowAmbientOcclusionTexture : hint_white; | |
uniform vec4 snowAmbientOcclusionTexture_channel = vec4(0, 0, 1, 0); | |
uniform float snowA_O_Texture_light_affect = 1; | |
uniform vec3 uv1_scale = vec3(1); | |
uniform vec3 uv1_offset; | |
void vertex() { | |
UV=UV*uv1_scale.xy+uv1_offset.xy; | |
} | |
void fragment() { | |
vec3 splatmapColor; | |
vec3 groundColor; | |
vec3 dirtColor; | |
vec3 cliffColor; | |
vec3 snowColor; | |
splatmapColor = texture(splatmap, UV).rgb; | |
groundColor = texture(groundBaseColor, UV * groundTexturesRes).rgb; | |
dirtColor = texture(dirtBaseColor, UV * dirtTexturesRes).rgb * splatmapColor.r; | |
cliffColor = texture(cliffBaseColor, UV * cliffTexturesRes).rgb * splatmapColor.b; | |
snowColor = texture(snowBaseColor, UV * snowTexturesRes).rgb * splatmapColor.g; | |
ALBEDO = groundColor + dirtColor + cliffColor + snowColor; | |
float ground_metallic_tex = dot(texture(groundMetallicTexture, UV), groundMetallicTexture_channel); | |
float dirt_metallic_tex = dot(texture(dirtMetallicTexture, UV), dirtMetallicTexture_channel) * splatmapColor.r; | |
float cliff_metallic_tex = dot(texture(cliffMetallicTexture, UV), cliffMetallicTexture_channel) * splatmapColor.b; | |
float snow_metallic_tex = dot(texture(snowMetallicTexture, UV), snowMetallicTexture_channel) * splatmapColor.g; | |
float ground_metallic = ground_metallic_tex * groundMetallic; | |
float dirt_metallic = dirt_metallic_tex * dirtMetallic; | |
float cliff_metallic = cliff_metallic_tex * cliffMetallic; | |
float snow_metallic = snow_metallic_tex * snowMetallic; | |
METALLIC = ground_metallic + dirt_metallic + cliff_metallic + snow_metallic; | |
float ground_roughness_tex = dot(texture(groundRoughnessTexture, UV * groundTexturesRes), groundRoughnessTexture_channel); | |
float dirt_roughness_tex = dot(texture(dirtRoughnessTexture, UV * groundTexturesRes), dirtRoughnessTexture_channel) * splatmapColor.r; | |
float cliff_roughness_tex = dot(texture(cliffRoughnessTexture, UV * groundTexturesRes), cliffRoughnessTexture_channel) * splatmapColor.b; | |
float snow_roughness_tex = dot(texture(snowRoughnessTexture, UV * groundTexturesRes), snowRoughnessTexture_channel) * splatmapColor.g; | |
float ground_roughness = ground_roughness_tex * groundRoughness; | |
float dirt_roughness = dirt_roughness_tex * dirtRoughness; | |
float cliff_roughness = cliff_roughness_tex * cliffRoughness; | |
float snow_roughness = snow_roughness_tex * snowRoughness; | |
ROUGHNESS = ground_roughness + dirt_roughness + cliff_roughness + snow_roughness; | |
SPECULAR = groundSpecular + (dirtSpecular * splatmapColor.r) + (cliffSpecular * splatmapColor.b) + (snowSpecular * splatmapColor.g); | |
vec3 groundNormal = texture(groundNormalTexture, UV * groundTexturesRes).rgb; | |
vec3 dirtNormal = texture(dirtNormalTexture, UV * dirtTexturesRes).rgb * splatmapColor.r; | |
vec3 cliffNormal = texture(cliffNormalTexture, UV * cliffTexturesRes).rgb * splatmapColor.b; | |
vec3 snowNormal = texture(snowNormalTexture, UV * snowTexturesRes).rgb * splatmapColor.g; | |
NORMALMAP = groundNormal + dirtNormal + cliffNormal + snowNormal; | |
NORMALMAP_DEPTH = groundNormalTexture_scale + dirtNormalTexture_scale + cliffNormalTexture_scale + snowNormalTexture_scale; | |
float ground_AO = dot(texture(groundAmbientOcclusionTexture, UV * dirtTexturesRes), groundAmbientOcclusionTexture_channel); | |
float dirt_AO = dot(texture(dirtAmbientOcclusionTexture, UV * dirtTexturesRes), dirtAmbientOcclusionTexture_channel) * splatmapColor.r; | |
float cliff_AO = dot(texture(cliffAmbientOcclusionTexture, UV * cliffTexturesRes), cliffAmbientOcclusionTexture_channel) * splatmapColor.b; | |
float snow_AO = dot(texture(snowAmbientOcclusionTexture, UV * snowTexturesRes), snowAmbientOcclusionTexture_channel) * splatmapColor.g; | |
AO = ground_AO + dirt_AO + cliff_AO + snow_AO; | |
AO_LIGHT_AFFECT = groundA_O_Texture_light_affect + (dirtA_O_Texture_light_affect * splatmapColor.r) + (cliffA_O_Texture_light_affect * splatmapColor.b) + (snowA_O_Texture_light_affect * splatmapColor.g); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment