shader

Organizing GLSL shaders in OpenGL engine

泪湿孤枕 提交于 2019-12-02 15:09:23
Which is better ? To have one shader program with a lot of uniforms specifying lights to use, or mappings to do (e.g. I need one mesh to be parallax mapped, and another one parallax/specular mapped). I'd make a cached list of uniforms for lazy transfers, and just change a couple of uniforms for every next mesh if it needs to do so. To have a lot of shader programs for every needed case, each one with small amount of uniforms, and do the lazy bind with glUseProgram for every mesh if it needs to do so. Here I assume that meshes are properly batched, to avoid redundant switches. Most modern

OpenGL ES 2.0 Multiple Programs or Multiple Shaders or what? How does it work?

扶醉桌前 提交于 2019-12-02 15:04:41
The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL ES 2.0 expects me to write and use multiple shaders; or if it is even advisable/expected that a person will do so. The fundamental question here is: if I have an apple, a glowing rock and a fuzzy mesh, all in the same 3D world, all best drawn with different shader programs but using the same mvpMatrix then how would I go about using all of them in the same OpenGL render such that they all use their most appropriate shaders that I have written? What Have I done So I have written a basic OpenGL ES 2.0 program for my

In OpenGL is there a way to get a list of all uniforms & attribs used by a shader program?

拥有回忆 提交于 2019-12-02 13:59:35
I'd like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation() & glGetUniformLocation() can be used to map a string to a location, but what I would really like is the list of strings without having to parse the glsl code. Note: In OpenGL 2.0 glGetObjectParameteriv() is replaced by glGetProgramiv() . And the enum is GL_ACTIVE_UNIFORMS & GL_ACTIVE_ATTRIBUTES . NeARAZ Variables shared between both examples: GLint i; GLint count; GLint size; // size of the variable GLenum type; // type of the variable (float, vec3 or mat4, etc) const GLsizei bufSize =

U3D 自定义shader创建Editor扩展

夙愿已清 提交于 2019-12-02 12:27:18
“工欲善其事,必先利其器”Shader学习工具篇 最近一直忙于录制关于Shader入门的视频教程,其中一个反复的机械动作就是右键创建所需要的新Shader。悲剧的是每次打开的都是Unity3D默认的Shader菜单,看过我关于 Shader体系分类 的同学都知道默认菜单Shader都是干什么的,每次都要选择,每次都要删除一些多余的代码,并不是新手学习所需要的简单的Vertex frage shader和简单Surface shader。 “身为一个程序员,必须有懒得气质,必须干掉这样的重复的操作!” “怎么能让我们的可爱同学把宝贵的时间花在做重复的事情上呢?” 在这两点的驱动下,终于“功夫不负有心人”在百度的帮助下我找到了大神的神作, http://blog.csdn.net/mobilebbki399/article/details/51869487 【Unity编辑器】Unity基于模板生成代码的原理与应用 学习Shader的同学也可以看这位大神的文章,很多中高级的知识。 虽然大神的文章很代码流,很飘逸。总结下核心思想就是 通过反射系统的类方法实现创建模板到代码文件的生成, 最良心的是大神给我们提供了源码。 这里其实我们不是特别关心代码运行的机制和原理(想学习的可以看大神的帖子有三篇之多,还是比较详细的),我们只关心如何扩展我们自己的Shader模板和创建菜单不用做重复工作。

Fragment shader on plane with modified vertices

落花浮王杯 提交于 2019-12-02 11:52:43
I have a PlaneGeometry and I'm randomly animating the vertices in order to create random spikes. I use this FragmentShader : void main() { vec3 light = vec3(cos(time),sin(time),1.0); light = normalize(light); float dProd = max(0.0, dot(vNormal, light)); gl_FragColor = vec4(dProd,dProd,dProd,1.0); } I expected to have some faces of each spike colored in black, but instead I got a solid color. I placed a Sphere on my plane and applied the same shader: When I turn the wireframe OFF : Not sure I understand what's happening on the plane?! I thought that since each spike has different normals, they

OpenGL ES write depth data to color

余生颓废 提交于 2019-12-02 11:19:29
I'm trying to implement DepthBuffer-like functionality using OpenGL ES on Android. In other words I'm trying to get the 3D point on surface that is rendered on point [x, y] on the user device. In order to make that I need to be able to read the distance of the fragment at that given point. Answer in different circumstances: When using normal OpenGL you could achieve this by creating FrameBuffer and then attach either RenderBuffer or Texture with depth component to it. Both of those approaches use glReadPixels , with internal format of GL_DEPTH_COMPONENT to retrieve the data from the buffer

Problems with Shaders in OpenGL

我只是一个虾纸丫 提交于 2019-12-02 11:06:59
I'm trying to use stuff like glShaderSource in C++. Visual Studio says that functions like glCompileShader or glCreateProgram dont exist. I use FreeGLUT to include OpenGL. Does anybody have an idea how I can fix this? On windows, anything beyond GL1.1 must be loaded via the extension mechansim. The most convenient way to do so is by using a GL loader like glew . 来源: https://stackoverflow.com/questions/20722756/problems-with-shaders-in-opengl

HLSL: Index to unaligned/packed floats

心已入冬 提交于 2019-12-02 10:49:35
问题 I have a vertex shader (2.0) doing some instancing - each vertex specifies an index into an array. If I have an array like this: float instanceData[100]; The compiler allocates it 100 constant registers. Each constant register is a float4 , so it's allocating 4 times as much space as is needed. I need a way to make it allocate just 25 constant registers and store four values in each of them. Ideally I'd like a method where it still looks like a float[] on both the CPU and GPU (Right now I am

GLSL point light shader moving with camera

风格不统一 提交于 2019-12-02 10:16:14
问题 I've been trying to make a basic static point light using shaders for an LWJGL game, but it appears as if the light is moving as the camera's position is being translated and rotated. These shaders are slightly modified from the OpenGL 4.3 guide, so I'm not sure why they aren't working as intended. Can anyone explain why these shaders aren't working as intended and what I can do to get them to work? Vertex Shader: varying vec3 color, normal; varying vec4 vertexPos; void main() { color = vec3

Can't draw triangle using Opengl

跟風遠走 提交于 2019-12-02 10:15:04
in this code i want to draw a simple triangle on a blue background using openGL however when i compile and run the code only a window with the blue background appears (without the white triangle that is supposed to be drawn), iam using Xcode my code #include <iostream> #include <string> #include <GLUT/glut.h> #include <OpenGL/gl3.h> #include <fstream> using namespace std; // VAO & VBO objects GLuint VBO; GLuint VAO; void display(); // vertex Data (position) float vertex[] = {-1.0, 0.0 , 1.0, 0.0, 1.0 , 0.0, 0.0, 0.0 , 0.0 }; GLuint Program; GLuint Vshader; GLuint Fshader; // main program int