glsl

How to implement a ground fog GLSL shader

本小妞迷上赌 提交于 2019-11-29 21:20:03
问题 I'm trying to implement a ground fog shader for my terrain rendering engine. The technique is described in this article: http://www.iquilezles.org/www/articles/fog/fog.htm The idea is to consider the ray going from the camera to the fragment and integrate the fog density function along this ray. Here's my shader code: #version 330 core in vec2 UV; in vec3 posw; out vec3 color; uniform sampler2D tex; uniform vec3 ambientLightColor; uniform vec3 camPos; const vec3 FogBaseColor = vec3(1., 1., 1.

Explanation of dFdx

断了今生、忘了曾经 提交于 2019-11-29 20:51:17
I am trying to understand the dFdx and dFdy functions in GLSL. I understand the following: The derivative is the rate of change The partial derivative of a function with two parameters is when you differentiate the function while keeping one of the parameters constant. dFdx and dFdy find the rate that a value changes between the current fragment and a neighboring fragment. I don't understand what the rate of change is referring to. Is it the rate of change of fragment coordinates? Could it possibly be that you can find the rate of change of an arbitrary variable between two invokations of the

GLSL multiple shaderprogram VS uniforms switches

人走茶凉 提交于 2019-11-29 19:52:06
I'm working on a shader manager architecture and I have several questions for more advanced people. My current choice oppose two designs which are: 1. Per material shader program => Create one shader program per material used in the program. Potential cons: Considering every object might have its own material, it involves a lot of glUseProgram calls. Implies the creation of a lot of shaderprogram objects. More complex architecture that #2. Pros: Shader code can be generated specifically for each "options" used in the material. If i'm not wrong, uniforms have to be set only one time (when the

WebGL/GLSL - How does a ShaderToy work?

江枫思渺然 提交于 2019-11-29 19:40:35
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 code samples on Shadertoy, I only ever see one shader program, and most of the geometry used appears to

Vertex shader attribute mapping in GLSL

给你一囗甜甜゛ 提交于 2019-11-29 19:37:27
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 a little bit stuck in trying to design a way for the GLSL shader to define the stream mappings

Tools for GLSL editing [closed]

落爺英雄遲暮 提交于 2019-11-29 19:14:22
I'm looking for some kind of tool to work with GLSL. I want to experiment with shaders in the WebGL application, so what I'm looking for is something like RenderMonkey. As far as I know - RenderMonkey is not supported anymore, so there must be some other tool that took it's place. The best would be if I could do both the "effect composing" like RM and the raw GLSL code development. George Profenza Looking forward to see some nice answers. In the meantime, I recommend having a play with ShaderToy and FractalLab It's not a full IDE, but the WebGL inspector browser extension by benvanik seems

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

≯℡__Kan透↙ 提交于 2019-11-29 19:04:24
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 function that I've come across is this archive from Feb '08 , the original page now being gone from

Issue when porting from OpenGL 1.1 to OpenGL-ES 2.0

岁酱吖の 提交于 2019-11-29 17:29:38
this is my opengl-es 2.0 code : { for (surfnum=0;surfnum<surftotal;surfnum++){ for (i=0;i<triNum[surfnum];i++){ GLfloat *Vertices[] = { triArray[surfnum][i].normpt1, triArray[surfnum][i].normpt2,triArray[surfnum][i].normpt3}; glGenBuffers(1, &ui32Vbo); glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); unsigned int uiSize = 3 * (sizeof(GLfloat) * 1); glBufferData(GL_ARRAY_BUFFER, uiSize,*Vertices, GL_STATIC_DRAW); } } } for(int i = 0; i < 80000; ++i) { glClear(GL_COLOR_BUFFER_BIT); int i32Location = glGetUniformLocation(uiProgramObject, "projmatrix"); glUniformMatrix4fv( i32Location, 1, GL_FALSE,

How to do a shader to convert to azimuthal_equidistant

守給你的承諾、 提交于 2019-11-29 17:13:44
I have a 360 texture in Equirectangular Projection. With what GLSL shader can I convert it into a azimuthal equidistant projection ? See also: http://earth.nullschool.net/#current/wind/isobaric/500hPa/azimuthal_equidistant=24.64,98.15,169 I would do it in Fragment shader. bind Equirectangular texture as 2D texture bind projection shader draw Quad covering the screen or target texture store or use the result. In Vertex shader I would: Just pass the vertex coordinates as varying to fragment shader (no point using matrices here you can directly use x,y coordinates in range <-1,+1> ) In fragment

Index expression must be constant - WebGL/GLSL error

蓝咒 提交于 2019-11-29 17:06:01
问题 I'm having trouble accessing an array in a fragment shader using a non-constant int as the index. I've removed the formula as it wouldn't make much sense here anyway, but my code is meant to calculate the tileID based on the current pixel and use that to determine the color. Here's my code: int tileID = <Insert formula here>; vec3 colorTest; int arrayTest[1024]; for (int x = 0; x < 1024; x++) { if (x == 1) arrayTest[x] = 1; else arrayTest[x] = 2; } if (arrayTest[tileID] == 1) colorTest = vec3