shader

Three js - Cloning a shader and changing uniform values

ⅰ亾dé卋堺 提交于 2019-12-03 11:33:45
I'm working on creating a shader to generate terrain with shadows. My starting point is to clone the lambert shader and use a ShaderMaterial to eventually customise it with my own script. The standard method works well: var material = new MeshLambertMaterial({map:THREE.ImageUtils.loadTexture('images/texture.jpg')}); var mesh = new THREE.Mesh(geometry, material); etc The result: However I'd like to use the lambert material as a base and work on top of it, so I tried this: var lambertShader = THREE.ShaderLib['lambert']; var uniforms = THREE.UniformsUtils.clone(lambertShader.uniforms); var

SKShader performance slowdown

萝らか妹 提交于 2019-12-03 10:09:24
I need to implement a custom shader node using SpriteKit. In simulator everything is ok. On a device (iPad 3rd gen) shader animation is smooth just for first ~30 seconds, after that shader's fps are gradually falling down until it looks like a slideshow (1 fps or even less) It is worth noting, that SpriteKit shows 60 fps, so does Xcode. CPU is ~75% busy, but shader itself shows ~1fps. I own only 3rd generation iPad and I currently don't have an opportunity to test it on other devices Shader code is taken from wwdc session, but the issue is reproduced with any animated shaders I've tried.

OpenGL shader: a spotlight and a directional light

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to have two light sources: a directional one and a spotlight. I cannot seem to get what I am doing wrong -- probably not understanding how shaders work! I get the first light fine but no sign of the effects of the second one (aka spotlight). Here is the fragement shader that I came up with: varying vec4 diffuse,ambientGlobal, ambient; varying vec3 normal,lightDir,halfVector; varying float dist; void main() { vec3 n, halfV, viewV, ldir; float NdotL, NdotHV; vec4 color = ambientGlobal; float att, spotEffect; n = normalize(normal); NdotL

Trouble with Phong Shading

痞子三分冷 提交于 2019-12-03 08:49:29
I am writing a shader according to the Phong Model . I am trying to implement this equation: where n is the normal, l is direction to light, v is the direction to the camera, and r is the light reflection. The equations are described in more detail in the Wikipedia article. As of right now, I am only testing on directional light sources so there is no r^2 falloff. The ambient term is added outside the below function and it works well. The function maxDot3 returns 0 if the dot product is negative, as it usually done in the Phong model. Here's my code implementing the above equation: #include

Passing uniform 4x4 matrix to vertex shader program

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to learn OpenGL and following this: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ Up until the point where they started passing matrices to the vertex shader to translate the triangle they where drawing I was following along. This is the shader program where it starts to go wrong: #version 330 core layout ( location = 0 ) in vec3 vertexPosition_modelspace ; uniform mat4 MVP ; void main (){ vec4 v = vec4 ( vertexPosition_modelspace , 1 ); // Transform an homogeneous 4D vector gl_Position = MVP *

Only glsl shader version 120 works on mac OS X

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem with the glsl's version on my mac os X 10.9.2. I'm making a program in c++ with OpenGL and SDL2 I can't upgrade from my version 120 to any version higher. How I can upgrade please ? I compile like this : g++ and my flag is : -framework SDL2 -lSDLmain -framework OpenGL -framework SDL2_image -framework cocoa ERROR: 0:3: '' : version '330' is not supported 回答1: On OS/X 10.9 to create an OpenGL 3.3/4.1 context you need to add the following snippet before SDL_CreateWindow . A full example is available here: https://gist.github

Threejs Custom Shader - Screen Tearing

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So to implement a tilemap using Threejs and Brandon Jone's tilemap method ( found here ) I am using a THREE.Plane geometry for each layer, and painting the face with the following custom shaders: Vertex Shader: var tilemapVS = [ "varying vec2 pixelCoord;", "varying vec2 texCoord;", "uniform vec2 mapSize;", "uniform vec2 inverseTileTextureSize;", "uniform float inverseTileSize;", "void main(void) {", " pixelCoord = (uv * mapSize);", " texCoord = pixelCoord * inverseTileTextureSize * inverseTileSize;", " gl_Position = projectionMatrix *

THREE.js blur the frame buffer

痞子三分冷 提交于 2019-12-03 08:00:21
问题 I need to blur the frame buffer and I don't know how to get the frame buffer using THREE.js. I want to blur the whole frame buffer rather than blur each textures in the scene. So I guess I should read the frame buffer and then blur, rather than doing this in shaders. Here's what I have tried: Call when init: var renderTarget = new THREE.WebGLRenderTarget(512, 512, { wrapS: THREE.RepeatWrapping, wrapT: THREE.RepeatWrapping, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format

why should we go in eye-space coordinates during fragment stage in the OpenGL pipeline?

守給你的承諾、 提交于 2019-12-03 07:40:06
问题 I'm currently programming a small 3D engine, and I was wondering why I should go in eye-space coordinates in the fragment shader. To do that, I have to put my camera matrix in a uniform to convert light positions in eye-coordinates, and a camera_normal matrix to put the light directions in eye-coordinates. Why is everyone using these coordinates? I don't really see any advantage. 回答1: There are several reasons eye-space is used: It's convenient. It's a well-defined space that exists, and one

Cesium原理篇:6 Render模块(3: Shader)【转】

微笑、不失礼 提交于 2019-12-03 07:37:19
https://www.cnblogs.com/fuckgiser/p/5975274.html 在介绍Renderer的第一篇,我就提到WebGL1.0对应的是OpenGL ES2.0,也就是可编程渲染管线。之所以单独强调这一点,算是为本篇埋下一个伏笔。通过前两篇,我们介绍了VBO和Texture两个比较核心的WebGL概念。假设生产一辆汽车,VBO就相当于这个车的骨架,纹理相当这个车漆,但有了骨架和车漆还不够,还需要一台机器人来加工,最终才能成产出这辆汽车。而Shader模块就是负责这个生产的过程,加工参数(VBO,Texture),执行渲染任务。 这里假设大家对Shader有一个基本的了解,这一块内容也很多,不可能简单两句轻描淡写就豁然开朗,而且我也没有进行过系统的学习,所以就不班门弄斧了。进入主题,来看看Cesium对Shader的封装。 图1:ES2.0可编程渲染管线 上图是可编程渲染管线的一个大概流程,我们关注的两个橙色的圆角矩形部分,分别是顶点着色器和片源着色器。既然是可编程渲染管线,面向Shader的开发者提供了一种称为GLSL的语言,如果你懂C的话,两者语法是相当的,所以从语法层面学习成本不大。 ShaderSource创建 首先,Cesium提供了ShaderSource类来加载GLSL代码,我们来看一下它对应的拷贝构造函数: ShaderSource