glsl

How can I pass multiple textures to a single shader?

巧了我就是萌 提交于 2019-11-28 17:56:10
I am using freeglut, GLEW and DevIL to render a textured teapot using a vertex and fragment shader. This is all working fine in OpenGL 2.0 and GLSL 1.2 on Ubuntu 14.04. Now, I want to apply a bump map to the teapot. My lecturer evidently doesn't brew his own tea, and so doesn't know they're supposed to be smooth . Anyway, I found a nice-looking tutorial on old-school bump mapping that includes a fragment shader that begins: uniform sampler2D DecalTex; //The texture uniform sampler2D BumpTex; //The bump-map What they don't mention is how to pass two textures to the shader in the first place.

What's the best way to draw a fullscreen quad in OpenGL 3.2?

北战南征 提交于 2019-11-28 17:55:37
I'm doing ray casting in the fragment shader. I can think of a couple ways to draw a fullscreen quad for this purpose. Either draw a quad in clip space with the projection matrix set to the identity matrix, or use the geometry shader to turn a point into a triangle strip. The former uses immediate mode, deprecated in OpenGL 3.2. The latter I use out of novelty, but it still uses immediate mode to draw a point. You can send two triangles creating a quad, with their vertex attributes set to -1/1 respectively. You do not need to multiply them with any matrix in the vertex/fragment shader. Here

How to design a simple GLSL wrapper for shader use

北慕城南 提交于 2019-11-28 17:20:11
UPDATE: Because I needed something right away, I've created a simple shader wrapper that does the sort of thing I need. You can find it here: ShaderManager on GitHub . Note that it's designed for Objective-C / iOS, so may not be useful to everyone. If you have any suggestions for design improvements, please let me know! Original Problem: I'm new to using GLSL shaders. I'm familiar enough with the GLSL language and the OpenGL interface, but I'm having trouble designing a simple API through which to use shaders. OpenGL's C interface to interact with shaders seems cumbersome. I can't seem to find

How to get a “Glow” shader effect in OpenGL ES 2.0?

与世无争的帅哥 提交于 2019-11-28 16:33:51
问题 I'm writing a 3D app for iOS. I'm new to OpenGL ES 2.0, so I'm still getting myself around writing basic shaders. I really need to implement a "Glow" effect on some of my models, based on the texturing. Here's a sample: . I'm looking for code examples for OpenGL ES 2.0. Most code I find on the internet is either for desktop OpenGL or D3D. Any ideas? 回答1: First of all there are tons of algorithms and techniques to generate a glow effect. I just want to present one possibility. Create a

What is the correct file extension for GLSL shaders? [closed]

泄露秘密 提交于 2019-11-28 15:24:15
I'm learning glsl shading and I've come across different file formats. I've seen people giving their vertex and fragment shaders .vert and .frag extensions. But I've also seen .vsh and .fsh extensions, and even both shaders together in a single .glsl file. So I'm wondering if there is a standard file format, or which way is the 'correct' one? There is no standard file extension for GLSL shaders. The most common ones are probably .vert and .frag , as these are the extensions that 3D Labs used in some of their tools. But that's about it for any form of standard extension. There's no official

Vertex shader attribute mapping in GLSL

随声附和 提交于 2019-11-28 15:21:01
问题 I'm coding a small rendering engine with GLSL shaders: Each Mesh (well, submesh) has a number of vertex streams (eg. position,normal,texture,tangent,etc) into one big VBO and a MaterialID. Each Material has a set of textures and properties (eg. specular-color, diffuse-color, color-texture, normal-map,etc) Then I have a GLSL shader, with it's uniforms and attributes. Let's say: uniform vec3 DiffuseColor; uniform sampler2D NormalMapTexture; attribute vec3 Position; attribute vec2 TexCoord; I'm

Curved Frosted Glass Shader?

南笙酒味 提交于 2019-11-28 14:30:37
Well making something transparent isn't that difficult, but i need that transparency to be different based on an object's curve to make it look like it isn't just a flat object. Something like the picture below. The center is more transparent than the sides of the cylinder, it is more black which is the background color. Then there is the bezel which seems to have some sort of specular lighting at the top to make it more shiny, but i'd have no idea how to go about that transparency in that case. Using the normals of the surface relative to the eye position to determine the transparency value?

What's the origin of this GLSL rand() one-liner?

旧巷老猫 提交于 2019-11-28 14:23:23
问题 I've seen this pseudo-random number generator for use in shaders referred to here and there around the web: float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } It's variously called "canonical", or "a one-liner I found on the web somewhere". What's the origin of this function? Are the constant values as arbitrary as they seem or is there some art to their selection? Is there any discussion of the merits of this function? EDIT: The oldest reference to this

glsl vector plus scalar

╄→尐↘猪︶ㄣ 提交于 2019-11-28 13:49:35
I searched a lot but could not find if the following statements are legal in a #version 330 vertex shader: #define note_the_following_whitespaces 0x01 (layout location = 7) vec3 out ov; (layout location = 8) vec3 out rv; void main() { rv = vec3(1.0,2.0,3.0); ov = (1.0+rv)/2.0; gl_Position = [whatever]... } I'm referring particularly to the (1.0+rv) - the shader compiles fine on every nVidia card, but refuses to compile on ATI cards. Unfortunately I don't have the exact compilation result, I just know that the compilation was unsuccessful. http://www.opengl.org/registry/doc/GLSLangSpec.3.30.6

Texture coordinates near 1 behave oddly

六眼飞鱼酱① 提交于 2019-11-28 13:43:13
I'm using (Py)OpenGL to display 256 colors indexed images. I use a shader together with a 1D texture containing the palette. Here's the Fragment shader code : #version 330 uniform sampler2D texture; uniform sampler1D palette; void main() { vec2 uv = gl_TexCoord[0].xy; vec4 color = texture2D(texture, uv); gl_FragColor = texture1D(palette, color.a) ; } To avoid rounding errors, all MAG and MIN filters are set to NEAREST. The way I was seeing the texture coordinates for the 1D texture was : color 0 lies in interval [0 ; 1/256[ color 1 lies in interval [1/256 ; 2/256[ ... color 255 lies in