merge upstream
This commit is contained in:
		@ -170,32 +170,64 @@ vec3 random3(const vec3 c) {
 | 
			
		||||
    r.y = fract(512.0 * j);
 | 
			
		||||
    return r - 0.5;
 | 
			
		||||
}
 | 
			
		||||
float tex_musgrave_f(const vec3 p) {
 | 
			
		||||
 | 
			
		||||
float noise_tex(const vec3 p) {
 | 
			
		||||
    const float F3 = 0.3333333;
 | 
			
		||||
    const float G3 = 0.1666667;
 | 
			
		||||
 | 
			
		||||
    vec3 s = floor(p + dot(p, vec3(F3)));
 | 
			
		||||
    vec3 x = p - s + dot(s, vec3(G3));
 | 
			
		||||
    vec3 e = step(vec3(0.0), x - x.yzx);
 | 
			
		||||
    vec3 i1 = e*(1.0 - e.zxy);
 | 
			
		||||
    vec3 i2 = 1.0 - e.zxy*(1.0 - e);
 | 
			
		||||
    vec3 i1 = e * (1.0 - e.zxy);
 | 
			
		||||
    vec3 i2 = 1.0 - e.zxy * (1.0 - e);
 | 
			
		||||
 | 
			
		||||
    vec3 x1 = x - i1 + G3;
 | 
			
		||||
    vec3 x2 = x - i2 + 2.0*G3;
 | 
			
		||||
    vec3 x3 = x - 1.0 + 3.0*G3;
 | 
			
		||||
    vec4 w, d;
 | 
			
		||||
    w.x = dot(x, x);
 | 
			
		||||
    w.y = dot(x1, x1);
 | 
			
		||||
    w.z = dot(x2, x2);
 | 
			
		||||
    w.w = dot(x3, x3);
 | 
			
		||||
    w = max(0.6 - w, 0.0);
 | 
			
		||||
    vec3 x2 = x - i2 + 2.0 * G3;
 | 
			
		||||
    vec3 x3 = x - 1.0 + 3.0 * G3;
 | 
			
		||||
 | 
			
		||||
    vec4 w;
 | 
			
		||||
    w.x = max(0.6 - dot(x, x), 0.0);
 | 
			
		||||
    w.y = max(0.6 - dot(x1, x1), 0.0);
 | 
			
		||||
    w.z = max(0.6 - dot(x2, x2), 0.0);
 | 
			
		||||
    w.w = max(0.6 - dot(x3, x3), 0.0);
 | 
			
		||||
 | 
			
		||||
    w = w * w;
 | 
			
		||||
    w = w * w;
 | 
			
		||||
 | 
			
		||||
    vec4 d;
 | 
			
		||||
    d.x = dot(random3(s), x);
 | 
			
		||||
    d.y = dot(random3(s + i1), x1);
 | 
			
		||||
    d.z = dot(random3(s + i2), x2);
 | 
			
		||||
    d.w = dot(random3(s + 1.0), x3);
 | 
			
		||||
    w *= w;
 | 
			
		||||
    w *= w;
 | 
			
		||||
 | 
			
		||||
    d *= w;
 | 
			
		||||
    return clamp(dot(d, vec4(52.0)), 0.0, 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float tex_musgrave_f(const vec3 p, float detail, float distortion) {
 | 
			
		||||
    // Apply distortion to the input coordinates smoothly with noise_tex
 | 
			
		||||
    vec3 distorted_p = p + distortion * vec3(
 | 
			
		||||
        noise_tex(p + vec3(5.2, 1.3, 7.1)),
 | 
			
		||||
        noise_tex(p + vec3(1.7, 9.2, 3.8)),
 | 
			
		||||
        noise_tex(p + vec3(8.3, 2.8, 4.5))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    float value = 0.0;
 | 
			
		||||
    float amplitude = 1.0;
 | 
			
		||||
    float frequency = 1.0;
 | 
			
		||||
 | 
			
		||||
    // Use 'detail' as number of octaves, clamped between 1 and 8
 | 
			
		||||
    int octaves = int(clamp(detail, 1.0, 8.0));
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < octaves; i++) {
 | 
			
		||||
        value += amplitude * noise_tex(distorted_p * frequency);
 | 
			
		||||
        frequency *= 2.0;
 | 
			
		||||
        amplitude *= 0.5;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return clamp(value, 0.0, 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
# col: the incoming color
 | 
			
		||||
 | 
			
		||||
@ -254,10 +254,10 @@ if bpy.app.version < (4, 1, 0):
 | 
			
		||||
            co = 'bposition'
 | 
			
		||||
    
 | 
			
		||||
        scale = c.parse_value_input(node.inputs['Scale'])
 | 
			
		||||
        # detail = c.parse_value_input(node.inputs[2])
 | 
			
		||||
        # distortion = c.parse_value_input(node.inputs[3])
 | 
			
		||||
    
 | 
			
		||||
        res = f'tex_musgrave_f({co} * {scale} * 0.5)'
 | 
			
		||||
        detail = c.parse_value_input(node.inputs[3])
 | 
			
		||||
        distortion = c.parse_value_input(node.inputs[4])
 | 
			
		||||
 | 
			
		||||
        res = f'tex_musgrave_f({co} * {scale} * 0.5, {detail}, {distortion})'
 | 
			
		||||
    
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
@ -278,11 +278,11 @@ def parse_tex_noise(node: bpy.types.ShaderNodeTexNoise, out_socket: bpy.types.No
 | 
			
		||||
    distortion = c.parse_value_input(node.inputs[5])
 | 
			
		||||
    if bpy.app.version >= (4, 1, 0):
 | 
			
		||||
        if node.noise_type == "FBM":
 | 
			
		||||
            state.curshader.add_function(c_functions.str_tex_musgrave)
 | 
			
		||||
            if out_socket == node.outputs[1]:
 | 
			
		||||
                state.curshader.add_function(c_functions.str_tex_musgrave)
 | 
			
		||||
                res = 'vec3(tex_musgrave_f({0} * {1}), tex_musgrave_f({0} * {1} + 120.0), tex_musgrave_f({0} * {1} + 168.0))'.format(co, scale, detail, distortion)
 | 
			
		||||
                res = 'vec3(tex_musgrave_f({0} * {1}, {2}, {3}), tex_musgrave_f({0} * {1} + 120.0, {2}, {3}), tex_musgrave_f({0} * {1} + 168.0, {2}, {3}))'.format(co, scale, detail, distortion)
 | 
			
		||||
            else:
 | 
			
		||||
                res = f'tex_musgrave_f({co} * {scale} * 1.0)'
 | 
			
		||||
                res = f'tex_musgrave_f({co} * {scale} * 1.0, {detail}, {distortion})'
 | 
			
		||||
        else:
 | 
			
		||||
            if out_socket == node.outputs[1]:
 | 
			
		||||
                res = 'vec3(tex_noise({0} * {1},{2},{3}), tex_noise({0} * {1} + 120.0,{2},{3}), tex_noise({0} * {1} + 168.0,{2},{3}))'.format(co, scale, detail, distortion)
 | 
			
		||||
 | 
			
		||||
@ -86,7 +86,7 @@ def write(vert, particle_info=None, shadowmap=False):
 | 
			
		||||
        vert.write('p_fade = sin(min((p_age / 2) * 3.141592, 3.141592));')
 | 
			
		||||
 | 
			
		||||
    if out_index:
 | 
			
		||||
        vert.add_out('float p_index');
 | 
			
		||||
        vert.add_out('float p_index')
 | 
			
		||||
        vert.write('p_index = gl_InstanceID;')
 | 
			
		||||
 | 
			
		||||
def write_tilesheet(vert):
 | 
			
		||||
 | 
			
		||||
@ -209,7 +209,8 @@ def make_instancing_and_skinning(mat: Material, mat_users: Dict[Material, List[O
 | 
			
		||||
                    global_elems.append({'name': 'ipos', 'data': 'float3'})
 | 
			
		||||
                    if 'Rot' in inst:
 | 
			
		||||
                        global_elems.append({'name': 'irot', 'data': 'float3'})
 | 
			
		||||
                    if 'Scale' in inst:
 | 
			
		||||
                    #HACK: checking `mat.arm_particle_flag` to force appending 'iscl' to the particle's vertex shader
 | 
			
		||||
                    if 'Scale' in inst or mat.arm_particle_flag:
 | 
			
		||||
                        global_elems.append({'name': 'iscl', 'data': 'float3'})
 | 
			
		||||
 | 
			
		||||
            elif inst == 'Off':
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user