当前位置: 首页>>代码示例>>Python>>正文


Python shaders.compileShader方法代码示例

本文整理汇总了Python中OpenGL.GL.shaders.compileShader方法的典型用法代码示例。如果您正苦于以下问题:Python shaders.compileShader方法的具体用法?Python shaders.compileShader怎么用?Python shaders.compileShader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenGL.GL.shaders的用法示例。


在下文中一共展示了shaders.compileShader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _init_shaders

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def _init_shaders(self):
    """Initializes the shaders used to render the textures fullscreen quad."""
    vs = shaders.compileShader(_VERTEX_SHADER, GL.GL_VERTEX_SHADER)
    fs = shaders.compileShader(_FRAGMENT_SHADER, GL.GL_FRAGMENT_SHADER)
    self._shader = shaders.compileProgram(vs, fs)

    stride = _FLOATS_PER_VERTEX * _SIZE_OF_FLOAT
    var_position = GL.glGetAttribLocation(self._shader, _VAR_POSITION)
    GL.glVertexAttribPointer(
        var_position, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, None)
    GL.glEnableVertexAttribArray(var_position)

    var_uv = GL.glGetAttribLocation(self._shader, _VAR_UV)
    uv_offset = ctypes.c_void_p(_FLOATS_PER_XY * _SIZE_OF_FLOAT)
    GL.glVertexAttribPointer(
        var_uv, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, uv_offset)
    GL.glEnableVertexAttribArray(var_uv)

    self._var_texture_sampler = GL.glGetUniformLocation(
        self._shader, _VAR_TEXTURE_SAMPLER) 
开发者ID:deepmind,项目名称:dm_control,代码行数:22,代码来源:fullscreen_quad.py

示例2: shader

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def shader(self):
        if self.compiled is None:
            try:
                self.compiled = shaders.compileShader(self.code, self.shaderType)
            except NullFunctionError:
                raise Exception("This OpenGL implementation does not support shader programs; many OpenGL features in pyqtgraph will not work.")
            except RuntimeError as exc:
                ## Format compile errors a bit more nicely
                if len(exc.args) == 3:
                    err, code, typ = exc.args
                    if not err.startswith('Shader compile failure'):
                        raise
                    code = code[0].decode('utf_8').split('\n')
                    err, c, msgs = err.partition(':')
                    err = err + '\n'
                    msgs = re.sub('b\'','',msgs)
                    msgs = re.sub('\'$','',msgs)
                    msgs = re.sub('\\\\n','\n',msgs)
                    msgs = msgs.split('\n')
                    errNums = [()] * len(code)
                    for i, msg in enumerate(msgs):
                        msg = msg.strip()
                        if msg == '':
                            continue
                        m = re.match(r'(\d+\:)?\d+\((\d+)\)', msg)
                        if m is not None:
                            line = int(m.groups()[1])
                            errNums[line-1] = errNums[line-1] + (str(i+1),)
                            #code[line-1] = '%d\t%s' % (i+1, code[line-1])
                        err = err + "%d %s\n" % (i+1, msg)
                    errNums = [','.join(n) for n in errNums]
                    maxlen = max(map(len, errNums))
                    code = [errNums[i] + " "*(maxlen-len(errNums[i])) + line for i, line in enumerate(code)]
                    err = err + '\n'.join(code)
                    raise Exception(err)
                else:
                    raise
        return self.compiled 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:40,代码来源:shaders.py

示例3: _load_shaders

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def _load_shaders(self, vertex_shader, fragment_shader):
        """Load and compile shaders from strings.
        """
        shader = shaders.compileProgram(
            shaders.compileShader(vertex_shader, GL_VERTEX_SHADER),
            shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER)
        )

        return shader 
开发者ID:BerkeleyAutomation,项目名称:meshrender,代码行数:11,代码来源:render.py

示例4: compileProgram

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def compileProgram(self, vertCode, fragCode):
        """
        A compileProgram version that ensures we don't recompile unnecessarily.
        """
        program = self.__cache.get((vertCode, fragCode), None)
        if program:
            return program
        program = compileProgram(
            shaders.compileShader(vertCode, GL_VERTEX_SHADER),
            shaders.compileShader(fragCode, GL_FRAGMENT_SHADER),
            validate=canValidateShaders()
        )
        self.__cache[(vertCode, fragCode)] = program
        return program 
开发者ID:trevorvanhoof,项目名称:sqrmelon,代码行数:16,代码来源:scene.py

示例5: _add_to_context

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def _add_to_context(self):
        if self._program_id is not None:
            raise ValueError('Shader program already in context')
        shader_ids = []

        # Load vert shader
        shader_ids.append(gl_shader_utils.compileShader(
            self._load(self.vertex_shader), GL_VERTEX_SHADER)
        )
        # Load frag shader
        shader_ids.append(gl_shader_utils.compileShader(
            self._load(self.fragment_shader), GL_FRAGMENT_SHADER)
        )
        # Load geometry shader
        if self.geometry_shader is not None:
            shader_ids.append(gl_shader_utils.compileShader(
                self._load(self.geometry_shader), GL_GEOMETRY_SHADER)
            )

        # Bind empty VAO PYOPENGL BUG
        if self._vao_id is None:
            self._vao_id = glGenVertexArrays(1)
        glBindVertexArray(self._vao_id)

        # Compile program
        self._program_id = gl_shader_utils.compileProgram(*shader_ids)

        # Unbind empty VAO PYOPENGL BUG
        glBindVertexArray(0) 
开发者ID:musyoku,项目名称:gqn-dataset-renderer,代码行数:31,代码来源:shader_program.py

示例6: init_gl

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def init_gl(self):
        vertex_shader = compileShader(
            shader_string("""
            layout(location = 0) in vec3 in_Position;
            layout(location = 1) in vec3 in_Normal;
            layout(location = 2) in vec2 in_TexCoord;
            
            layout(location = 0) uniform mat4 projection = mat4(1);
            layout(location = 4) uniform mat4 model_view = mat4(1);
            layout(location = 8) uniform mat4 normal_matrix = mat4(1);
            
            out vec3 color;
            out vec2 fragTexCoord;
            
            void main() {
              gl_Position = projection * model_view * vec4(in_Position, 1.0);
              vec3 normal = normalize((normal_matrix * vec4(in_Normal, 0)).xyz);
              color = (normal + vec3(1,1,1)) * 0.5; // color by normal
              fragTexCoord = in_TexCoord;
              // color = vec3(in_TexCoord, 0.5); // color by texture coordinate
            }
            """),
            GL.GL_VERTEX_SHADER)
        fragment_shader = compileShader(
            shader_string("""
            uniform sampler2D diffuse;
            in vec3 color;
            in vec2 fragTexCoord;
            out vec4 fragColor;
            
            void main() {
              // fragColor = vec4(color, 1.0);
              fragColor = texture(diffuse, fragTexCoord);
            }
            """),
            GL.GL_FRAGMENT_SHADER)
        self.shader = compileProgram(vertex_shader, fragment_shader)
        self._check_devices()
        GL.glEnable(GL.GL_DEPTH_TEST) 
开发者ID:cmbruns,项目名称:pyopenvr,代码行数:41,代码来源:tracked_devices_actor.py

示例7: compileShaders

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def compileShaders(self):
        try:
            vertex_shader = shaders.compileShader("""
                #extension GL_OES_standard_derivatives : enable
                uniform vec4 uColor;
                uniform float uTransparency;
                varying vec3 N;
                varying vec3 v;
                varying vec3 vBC;

                void main(void)
                {

                    v = vec3(gl_ModelViewMatrix * gl_Vertex);       
                    N = normalize(gl_NormalMatrix * gl_Normal);
                    vBC = gl_Color.xyz;
                    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                }
                """, GL_VERTEX_SHADER)

            fragment_shader = shaders.compileShader("""
                uniform vec4 uColor;
                uniform float uTransparency;
                varying vec3 N;
                varying vec3 v;
                varying vec3 vBC;
                float edgeFactor(){
                    vec3 d = fwidth(vBC);
                    vec3 a3 = smoothstep(vec3(0.0), d, vBC);
                    return min(min(a3.x, a3.y), a3.z);
                }

                void main(void)
                {
                    vec3 L = normalize(gl_LightSource[0].position.xyz - v);   
                    vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.)*uColor;  
                    Idiff = clamp(Idiff, 0.0, 1.0); 

                    if (Idiff==vec4(0.))
                    {
                        Idiff = (uTransparency > 0. ? gl_FrontLightProduct[0].diffuse : vec4(1., 0., 0., 0.))
                            * max(dot(-N,L), 0.);  
                        //Idiff = vec4(1., 0., 0., 0.);
                        Idiff = clamp(Idiff, 0.0, 1.0); 
                    }

                    gl_FragColor.rgb = mix(vec3(0.0), Idiff.xyz, edgeFactor());
                    gl_FragColor.a = 1. - uTransparency;

                }
                """, GL_FRAGMENT_SHADER)

            self.shaders = shaders.compileProgram(vertex_shader, fragment_shader)
            self.shaders_color_location = glGetUniformLocation(self.shaders, 'uColor')
            self.shaders_transp_location = glGetUniformLocation(self.shaders, 'uTransparency')
            return True
        except WindowsError as e:
            return False 
开发者ID:Oslandia,项目名称:albion,代码行数:60,代码来源:scene.py

示例8: init_gl

# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileShader [as 别名]
def init_gl(self):
        vertex_shader = compileShader(dedent(
                """
                #version 450 core
                #line 563
                
                layout(location = 0) uniform mat4 Projection = mat4(1);
                layout(location = 4) uniform mat4 ModelView = mat4(1);
                
                const vec3 FLOOR_QUAD[4] = vec3[4](
                    vec3(-1, 0, -1),
                    vec3(-1, 0, +1),
                    vec3(+1, 0, +1),
                    vec3(+1, 0, -1)
                );
                
                const int FLOOR_INDICES[6] = int[6](
                    2, 1, 0,
                    0, 3, 2
                );
                
                out vec2 texCoord;
                
                void main() {
                    int vertexIndex = FLOOR_INDICES[gl_VertexID];
                    vec3 v = FLOOR_QUAD[vertexIndex];
                    const float scale = 50; // meters per side
                    texCoord = scale * v.xz;
                    gl_Position = Projection * ModelView * vec4(scale * v, 1);
                }
                """
                ), GL_VERTEX_SHADER)
        fragment_shader = compileShader(dedent(
                """\
                #version 450 core
                #line 594

                in vec2 texCoord; // Floor texture coordinate in meters
                out vec4 FragColor;
                
                float filtered_noise(in vec2 texCoord, in float detail);

                void main() 
                {
                    // shift texture coordinate so origin artifact is probably far away,
                    // and shift intensity from range [-1,1] to range [0,1]
                    float noise = 0.50 * (filtered_noise(texCoord * 2 + vec2(10, 10), 8) + 1.0);
                    // interpolate final color between brown and green
                    const vec3 color1 = vec3(0.25, 0.3, 0.15); // green
                    const vec3 color2 = vec3(0.05, 0.05, 0.0); // dark brown
                    vec3 color = mix(color2, color1, noise);
                    FragColor = vec4(color, 1.0);
                }
                """), 
            GL_FRAGMENT_SHADER)
        self.shader = compileProgram(vertex_shader, fragment_shader, ProceduralNoiseShader().fragment_shader)
        #
        self.vao = glGenVertexArrays(1)
        glBindVertexArray(self.vao)
        glEnable(GL_DEPTH_TEST) 
开发者ID:cmbruns,项目名称:pyopenvr,代码行数:62,代码来源:test_obj.py


注:本文中的OpenGL.GL.shaders.compileShader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。