shader

OpenGL Shader Compilation Issue — Unexpected EOF

久未见 提交于 2019-12-04 11:56:53
问题 So I decided to try writing a simple OpenGL app using Java, just to see how it compared to my other efforts, and I'm running into an issue where my shaders refuse to compile. They really couldn't get much simpler, here's my vertex shader to demonstrate what I mean: //Minimal vertex shader #version 330 in vec3 in_Position; in vec3 in_Color; out vec3 var_Color; void main(void) { gl_Position = vec4(in_Position, 1.0); var_Color = in_Color; } The fragment shader is just as simple, so I won't

OpenGL ES 2: Are vertex and fragment shaders necessary for simple drawing?

纵然是瞬间 提交于 2019-12-04 10:25:50
I'm currently working on some drawing routines using geometry generated at runtime and only flat colored. While searching for a minimal GL setup to do my drawing (I'm matching the screen resolution and on I'm iOS, but the question holds for other ES 2 platforms as well) , I'm seeing that most examples use vertex and fragment shaders, but not all of them. If I don't plan to use any textures or lighting (just direct color copying/blending) and I don't plan on doing any transformations that can't be done by manipulating the view matrix, do I really need to set up vertex and/or fragment shaders?

Unable to retrieve an error message from glGetShaderInfoLog

两盒软妹~` 提交于 2019-12-04 10:03:01
I am attempting to build a simple OpenGL 3.2 program which consists of a single fragment shader, but I do not seem to be able to actually compile the shader. I'm fairly sure that my shader syntax is correct, but even if it's not, I am unable to retrieve an error message using glGetShaderInfoLog . I have developed a short program that shows this in action: GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); const char *shaderData = "#version 120\n" "void main()\n" "{\n" " gl_FragColor = gl_Color;\n" "}\n"; glShaderSource(shader, 1, &shaderData, NULL); GLint status; glGetShaderiv(shader, GL

Unity3D Sprite … but single sided?

时光怂恿深爱的人放手 提交于 2019-12-04 10:01:29
Unity's excellent new Sprite s (to wit, Unity's excellent new sprites ), among other worthy advantages, are in fact double-sided. In a 2D or 3D use case, you can flip the little bastards around and still see them from behind - they are rendered from both sides. I also love the unlit shader used on them (ie, Sprite-Default, not Sprite-Diffuse). However I have need for an old-fashioned single-sided Sprite . Fortunately, you can freely download the source of the excellent shader used by Unity ... confusingly, you can't just open it in the Editor, but see here and thence here . After considerable

Using a Metal shader in SceneKit

Deadly 提交于 2019-12-04 09:59:54
I'd like to use a Metal shader to apply a toon/cell shading to materials used in the scene. The shader I'm trying to implement is Apple's own AAPLCelShader found in the MetalShaderShowcase . I'm a little new to implementing shaders in SceneKit so I could be doing everything completely wrong. From what I understand in the documentation a Metal or GL shader can be used to modify SceneKit rendering as of iOS 9 and Xcode 7. The documentation suggests that this is done in the same way as GL shaders. My method is to try and get the path for the .metal file and then load it into a string to be used

Passing an array of vectors to a uniform

我怕爱的太早我们不能终老 提交于 2019-12-04 09:36:14
问题 I am trying to implement multiple lights in my shader but I have trouble to fill the uniform with my light data. My vertex shader: attribute vec3 aVertex; attribute vec3 aNormal; attribute vec2 aTexture; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; uniform mat4 uNMatrix; uniform vec3 uAmbientColor; uniform vec3 uPointLightingLocation[16]; uniform vec3 uPointLightingColor[16]; varying vec2 vTexture; varying vec3 vLightWeighting; void main(void) { vec4 mvPosition = uMVMatrix * vec4(aVertex, 1

Shader optimization for retina screen on iOS

旧城冷巷雨未停 提交于 2019-12-04 09:11:29
I make a 3D iphone application which use many billboards. My frame buffer is twice larger on retina screen because I want to increase their quality on iPhone 4. The problem is that fragment shaders consume much more time due to the framebuffer size. Is there a way to manage retina screen and high definition textures without increase shader precision ? Brad Larson If you're rendering with a framebuffer at the full resolution of the Retina display, it will have four times as many pixels to raster over when compared with the same physical area of a non-Retina display. If you are fill-rate limited

Inline webgl shader code in javascript

故事扮演 提交于 2019-12-04 08:47:44
I'm writing a simple Javascript library that makes use of some WebGL code. I'd like to include the shader sources inline in the .js file, because my alternatives are to include them as script tags in each page, or to have them as separate files which are loaded as AJAX. Neither of these options are particularly modular. However, due to the lack of multi-line strings in javascript, I don't have any good ideas for how to inline the WebGL code. Is there an approach I'm not thinking of? Stefan Haustein Use a single string per line and then join them together, e.g. var shader = [ "// line1 ", "//

Get accurate integer modulo in WebGL shader

喜夏-厌秋 提交于 2019-12-04 08:17:12
I want to get an accurate modulo of x and y in a WebGL fragment shader. x and y are integers. Graphing mod(x,y) , we get the following: The actual code used to generate the red-and-black rectangle is: gl_FragColor = vec4(mod( float(int(v_texCoord[0]*15.))/15., float(int(v_texCoord[1]*15.))/15. ), 0, 0, 1); Where v_texCoord is a vec2 ranging from 0,0 at the top-left to 1,1 at the bottom-right. Precision is set to mediump for both float and int. Reading the chart, we see that although mod(6,6) is correctly 0 , mod(7,7) is actually 7 ! How do I fix this? I tried to implement my own mod() function

Rotate Normals in Shader

爷,独闯天下 提交于 2019-12-04 08:13:03
I have a scene with several models with individual positions and rotations. Given normals, the shaders apply simple bidirectional lighting to each pixel. That is my vertex shader. #version 150 in vec3 position; in vec3 normal; in vec2 texcoord; out vec3 f_normal; out vec2 f_texcoord; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { mat4 mvp = proj * view * model; f_normal = normal; f_texcoord = texcoord; gl_Position = mvp * vec4(position, 1.0); } And here is the fragment shader. #version 150 in vec3 f_normal; in vec2 f_texcoord; uniform sampler2D tex; vec3 sun = vec3(0.5