shader

WebGL/GLSL - How does a ShaderToy work?

◇◆丶佛笑我妖孽 提交于 2019-12-29 10:09:11
问题 I've been knocking around Shadertoy - https://www.shadertoy.com/ - recently, in an effort to learn more about OpenGL and GLSL in particular. From what I understand so far, the OpenGL user first has to prepare all the geometry to be used and configure the OpenGL server (number of lights allowed, texture storage, etc). Once that's done, the user then has to provide at least one vertex shader program, and one fragment shader program before an OpenGL program compiles. However, when I look at the

WebGL/GLSL - How does a ShaderToy work?

萝らか妹 提交于 2019-12-29 10:09:08
问题 I've been knocking around Shadertoy - https://www.shadertoy.com/ - recently, in an effort to learn more about OpenGL and GLSL in particular. From what I understand so far, the OpenGL user first has to prepare all the geometry to be used and configure the OpenGL server (number of lights allowed, texture storage, etc). Once that's done, the user then has to provide at least one vertex shader program, and one fragment shader program before an OpenGL program compiles. However, when I look at the

unity shader之预备知识

北城以北 提交于 2019-12-26 20:09:18
1.渲染流水线 任务:从一个三维场景出发,生成(或者渲染)一张二维图像。即:计算机需要从一系列的定点出数据,纹理等信息出发,把这些信息最终转换程一张人眼可以看到的图像。而这个工作通常是由CPU和GPU共同完成的。 三个阶段: (1)应用阶段(CPU):1.准备场景数据。2.粗粒度剔除工作。3设置模型的渲染状态,输出渲染所需要的几何信息. 应用阶段大致可以分为三个阶段: 1.把数据加载到显存中。 2.设置渲染状态。渲染状态:定义场景中的网格是怎样被渲染的。如:使用那个顶点着色器/片元着色器。 3.调用DrawCall。DrawCall是一个命令,发起方为CPU,接收方为GPU。 (2)几何阶段:把定点坐标变换到屏幕空间中,再交给光栅器进行处理。对输入的渲染图源进行多部处理后,将会输出屏幕空间的二维顶点坐标,每个定点对应的深度值,着色等相关信息。 (3)光栅化阶段:产生屏幕上的像素,并渲染最终的图像。光栅化的任主要是决定每个渲染图源中的那些像素应该被绘制再屏幕上。对上一阶段得到的逐定点数据进行插值,然后再进行逐像素处理。 为了避免我们看到的那些正在进行光栅化的图元,GPU会使用双重缓冲策略(前置缓冲,后置缓冲)。当场景被渲染到后置缓冲中,GPU会交换前后置缓冲中的内容,前置缓冲事之前显示在屏幕上的图像。 (1)顶点着色器:处理单位是顶点,输入进来的每个定点都会调用一次定点着色器

Unity Shader学习笔记(一)坐标变换

喜夏-厌秋 提交于 2019-12-26 20:08:58
基本问题   试想我们的美术做了一个3D模型,然后渲染引擎把模型渲染到屏幕上。我们还可以选定不同的视角,模拟不同的光照条件去观察模型。现在来分析一下这个过程。如果说我们把这个过程看成一个函数,那么函数的输出就是屏幕上的图像。确切地说,是屏幕上的每个像素。这个函数的主要输入是这个3D模型,我们观察的视角,光照情况等等因素。渲染过程就是给出这些因素决定每个像素值的过程。   首先来看模型。模型通常是由可视化的建模软件制作,看上去是一个“实体”。然而从计算机的角度来说,模型文件只不过是包含渲染它所需要的数据的文件。真实世界中的物体细节是无法穷尽,极其复杂的。所以我们进行简化,把物体简化成多面体,进一步的,简化成每个面是三角形的多面体。(对于曲面和细节较多的地方,我们可以用更多更小的三角面来拟合)。很显然,每个顶点的相对位置是重要的。它决定了模型的形状。由于需要描述位置,自然就有了选择坐标空间的问题。模型描述自身顶点坐标的空间称为模型空间。于是我们可以得出模型文件里一定要包含模型空间下的顶点坐标。   通常,在一个渲染的场景中,包含了多个渲染的物体。它们根据不同的位置摆放,当然会构成不同的场景。那么为了描述场景里模型之间的相对位置,我们会选择一个独立于模型的坐标空间,称为世界空间。有了世界空间,我们也可以描述观察者的位置和观察的角度。这个观察者,通常我们可以叫它为camera

Explanation of working principle of openGL [closed]

十年热恋 提交于 2019-12-25 18:39:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I'm trying to understand how coding in openGL works. I found this code on the internet and I want to understand it clearly. For my vertex shader I have: Vertex uniform vec3 fvLightPosition; varying vec2 Texcoord; varying vec2 Texcoordcut; varying vec3 ViewDirection; varying vec3

Silhouette-Outlined shader

一个人想着一个人 提交于 2019-12-25 11:59:30
问题 I'm trying to implement GLSL shader which would highlight the outer edges of rendered 3D mesh. The problem is that I do not have access to the OpenGL client side code so this must be done only in GLSL shaders. My first attempt was to use/adopt this shader from Unity and do it in OpenGL GLSL . Here how it should look: And here is what I got: I'm not sure If I compute the stuff correctly but as you can see the output is nowhere near my expectations. Here is the ogre material material Chassis {

Java Opengl: Discarding Texture Background with Shaders

喜你入骨 提交于 2019-12-25 06:04:02
问题 I'm trying to follow this tutorial to remove the background color of texture with a shader. https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/discard.php Everything is running correctly, I copied the shader code directly from the tutorial, however the fragment shader is throwing several errors. sampler2D myTexture; varying vec2 vTexCoord; void main (void) { vec4 color = texture2D(myTexture, vTexCoord); if (color.rgb == vec3(1.0,0.0,0.0)) discard; gl_FragColor = color; } ERROR: 0:3:

OpenGL multiple draw calls with unique shaders gives blank screen

孤街浪徒 提交于 2019-12-25 05:19:57
问题 I am trying to render two different vertex collections on top of one another. Right now, my main loop renders one correctly when it's by itself, and the other correctly when it's by itself, but when I call both of my draw functions, I see a blank window. Why might this be happening? The first draw call uses one shader, while the second draw call uses a different one. I don't clear the screen in between. If it makes the code more clear, my shader programs are stored as class variables, as are

修正半透明头发的渲染异常

霸气de小男生 提交于 2019-12-25 03:30:25
修正半透明头发的渲染异常 这两天在整理 小甜甜 的捏脸系统,顺带把前项目 半透明头发渲染异常的bug 修正了,效果如下: 其实,前项目的头发工作良好,只是有一点 半透明渲染顺序 的小瑕疵,但正如前文 一个自阴影的Bug 所提到的:我在迁移shader的时候因为偷懒,把头发改成了 Surface Shader ,从而带来了一些新的问题。 问题一:关于Surface Shader的alpha指令 首先,我犯了第一个错误,改 Surface Shader 的过程中,我漏掉了 alpha 指令的设置,shader变成了 实体渲染 ,表现如下: 关于 Surface Shader的alpha指令 ,可以参考Unity帮助文档: alpha or alpha:auto - Will pick fade-transparency (same as alpha:fade) for simple lighting functions, and premultiplied transparency (same as alpha:premul) for physically based lighting functions. alpha:blend - Enable alpha blending. alpha:fade - Enable traditional fade-transparency.

Is there anything wrong with my glsl shader loading code?

妖精的绣舞 提交于 2019-12-25 02:10:05
问题 The problem is that, shaders (pretty simple ones, as I'm learning OpenGL) fail to compile in a seemingly random manner (and gives random error messages * ). The same shaders, however, compile after about 3 or 4 tries. Here is the code: Shader::Shader(GLenum Type,std::string filename) { shader_type = Type; std::ifstream ifs(filename); if(!ifs) throw(std::runtime_error("File:"+filename+" not opened.")); std::ostringstream stream; stream<<ifs.rdbuf(); const GLchar* data = stream.str().c_str();