Blend file: Use alpha blending flag, add alpha in principled & teximage nodes.

This commit is contained in:
Alberto Torres 2024-12-16 21:30:37 +01:00
parent 11ef0fbd41
commit fc39a93a94
3 changed files with 12 additions and 6 deletions

View file

@ -306,7 +306,7 @@ proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, s
ob.passes.setLen mat_count
var tangents: seq[string]
for i in 0 ..< mat_count:
assert i < 16, "More than 16 materials not supported yet"
assert i < 16, "More than 16 materials not supported yet" # TODO
let is_oblink = matbits[i].testBit(0)
let mat = if is_oblink:
obn.mat[i]
@ -318,6 +318,10 @@ proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, s
continue
var backface_culling = (mat.blend_flag.i8[0] and 4'i8) != 0
let blend_method = mat.blend_method.i8[0]
let alpha_blend = blend_method == 5
if alpha_blend:
ob.passes[i] = 1
# this gives the "sons" error
# dump (mat.id.name.cstr.strip2, backface_culling)

View file

@ -642,7 +642,7 @@ node_functions = {
let s = texture_uniform(img.name.str.strip2)
var v = ins["Vector"].uv_socket
# TODO: output float directly from single channel textures
return mkOutput(&"$0 = texture({s}, {vec2(v)});", vec4tmp())
return mkOutput(&"$0 = texture({s}, {vec2(v)});$1 = $0.a;", vec4tmp(), flttmp())
,
"ShaderNodeTexEnvironment": proc(ins: InputMapper): seq[Expr] {.closure.} =
let img = ins.node.id
@ -1015,7 +1015,7 @@ node_functions = {
let metallic = ins["Metallic"].flt
let roughness = ins["Roughness"].flt
let ior = ins["IOR"].flt
# let alpha = ins["Alpha"].flt
let alpha = ins["Alpha"].flt
let normal = ins["Normal"].normal_socket_to_world
# let weight1 = ins["Weight"].flt
# let subsurface_weight = ins["Subsurface Weight"].flt
@ -1047,7 +1047,8 @@ node_functions = {
&"{world_position()}, " &
&"{metallic}, " &
&"{roughness}, " &
&"{ior} " &
&"{ior}, " &
&"{alpha} " &
&") + vec4({emission_color} * {emission_strength}, 0.0);", vec4tmp())
,
"ShaderNodeRGBCurve": proc(ins: InputMapper): seq[Expr] {.closure.} =

View file

@ -205,7 +205,8 @@ vec4 diffuse_node(vec3 base, vec3 I, vec3 normal, vec3 pos){
return vec4(color, 1.0);
}
vec4 principled_node(vec3 base, vec3 I, vec3 normal, vec3 pos, float metallic, float roughness, float ior){
vec4 principled_node(vec3 base, vec3 I, vec3 normal, vec3 pos, float metallic,
float roughness, float ior, float alpha){
vec3 N = normal;
#if FIX_BORDERS
float dotNI = dot(N, I);
@ -293,7 +294,7 @@ vec4 principled_node(vec3 base, vec3 I, vec3 normal, vec3 pos, float metallic, f
// color += mix(env_diffuse, env_specular, F);
// adding instead of mixing because F is already in diffuse
color += diffuse * env_diffuse + F * env_specular;
return vec4(color, 1.0);
return vec4(color, alpha);
}
vec3 refraction_dominant_dir(vec3 N, vec3 V, float roughness, float ior)