コード例 #1
0
ファイル: shader_data_node.py プロジェクト: zero804/armory
        self.outputs.new('NodeSocketInt', 'Int')

    def parse(self, frag: Shader, vert: Shader) -> str:
        if self.input_type == "uniform":
            frag.add_uniform(f'{self.variable_type} {self.variable_name}',
                             link=self.variable_name)
            vert.add_uniform(f'{self.variable_type} {self.variable_name}',
                             link=self.variable_name)

            if self.variable_type == "sampler2D":
                frag.add_uniform('vec2 screenSize', link='_screenSize')
                return f'texture({self.variable_name}, gl_FragCoord.xy / screenSize).rgb'

            return self.variable_name

        else:
            if self.input_source == "frag":
                frag.add_in(f'{self.variable_type} {self.variable_name}')
                return self.variable_name

            # Reroute input from vertex shader to fragment shader (input must exist!)
            else:
                vert.add_out(f'{self.variable_type} out_{self.variable_name}')
                frag.add_in(f'{self.variable_type} out_{self.variable_name}')

                vert.write(f'out_{self.variable_name} = {self.variable_name};')
                return 'out_' + self.variable_name


add_node(ShaderDataNode, category='Armory')
コード例 #2
0
            vertshdr.write(f'                         -sin({rot}.z) , cos({rot}.z), 0.0,')
            vertshdr.write(f'                         cos({rot}.z) * sin({rot}.y), sin({rot}.z) * sin({rot}.y), cos({rot}.y));')
        
        if(self.rotX and self.rotY and self.rotZ):
            vertshdr.write(f'mat3 part_rot_mat = mat3(cos({rot}.z) * cos({rot}.y), sin({rot}.z) * cos({rot}.y), -sin({rot}.y),') 
            vertshdr.write(f'                         -sin({rot}.z) * cos({rot}.x) + cos({rot}.z) * sin({rot}.y) * sin({rot}.x), cos({rot}.z) * cos({rot}.x) + sin({rot}.z) * sin({rot}.y) * sin({rot}.x), cos({rot}.y) * sin({rot}.x),')
            vertshdr.write(f'                         sin({rot}.z) * sin({rot}.x) + cos({rot}.z) * sin({rot}.y) * cos({rot}.x), -cos({rot}.z) * sin({rot}.x) + sin({rot}.z) * sin({rot}.y) * cos({rot}.x), cos({rot}.y) * cos({rot}.x));')
        
        if(self.rotX or self.rotY or self.rotZ):
            vertshdr.write('spos.xyz = part_rot_mat * spos.xyz;')
            if((part_con.data['name'] == 'mesh' or 'translucent') and vertshdr.contains('wnormal')):
                vertshdr.write('wnormal = transpose(inverse(part_rot_mat)) * wnormal;')
        
        if(self.posX or self.posY or self.posZ):
            pos = parse_vector_input(self.inputs[0])
        
        if(self.posX):
            vertshdr.write(f'spos.x += {pos}.x;')

        if(self.posY):
            vertshdr.write(f'spos.y += {pos}.y;')

        if(self.posZ):
            vertshdr.write(f'spos.z += {pos}.z;')
                
        if(vertshdr.contains('vec3 disp')):
            vertshdr.write('wposition = vec4(W * spos).xyz;')
        
       
add_node(CustomParticleNode, category='Armory')