glsl

How to make a wave warp effect in shader?

五迷三道 提交于 2019-11-30 15:13:43
问题 I want to make a wave warp effect like this: But I can only create the normal sine wave. Here is my fragment shader: precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_baseMap; vec2 SineWave( vec2 p ){ float pi = 3.14159; float A = 0.15; float w = 10.0 * pi; float t = 30.0*pi/180.0; float y = sin( w*p.x + t) * A; return vec2(p.x, p.y+y);  } void main(){ vec2 p = v_texCoord; vec2 uv = SineWave( p ); vec4 tcolor = texture2D(s_baseMap, uv); gl_FragColor = tcolor; } and result

billboarding vertices in the vertex shader

笑着哭i 提交于 2019-11-30 15:07:11
Code demonstrating issue (comment/uncomment out the gl_Position lines in the vertex shader) var scene; var book; var shaderMaterial; var renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setClearColor(0x000000); document.body.appendChild(renderer.domElement); var camera = new THREE.PerspectiveCamera(55, 1, 0.1, 40000); window.onresize = function () { renderer.setSize(window.innerWidth, window.innerHeight); camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); }; window.onresize(); scene = new THREE.Scene(); camera.position.z = 25; camera

Alternative to texelFetch? [duplicate]

牧云@^-^@ 提交于 2019-11-30 14:58:39
问题 This question already has answers here : OpenGL Texture Coordinates in Pixel Space (3 answers) Closed 2 years ago . I'm getting into GLSL and need some help with texture lookups. I'm trying to use a texture for storage but I cannot get "proper" texture lookups. I would prefer using the usual texture2D method (using GLSL 1.2) but the results are not good enough. Using texture2D: Using texelFetch: Now obviously something is wrong with the first one. Here is what I am trying to do (yes sizes are

GLSL branching behaviour

不羁岁月 提交于 2019-11-30 14:46:07
问题 I have a rather simple fragment shader with a branch and I'm a bit unsure how it is handled by the GLSL compiler and how it would affect performance. uniform sampler2D sampler; uniform vec2 texSize; uniform vec2 targetSize; void main() { vec4 color; if(texSize == targetSize) color = texture2DNearest(sampler, gl_TexCoord[0]); else color = texture2DBicubic(sampler, gl_TexCoord[0]); gl_FragColor = color; } I have read from an AMDs document that sometimes both branches are executed, which would

Parallax mapping glitch in OpenGL

淺唱寂寞╮ 提交于 2019-11-30 14:19:05
问题 And this is result when I invert the tangent vector right after transferring it to vertex shader: The "shadow" is in the wrong place. (And it works only when I rotate it through Y axis so the last image seem to present a good parallax mapped cube) IM SURE IT IS NOT A TANGENT VECTOR OR TEXTURE COORDINATES PROBLEM Because I used exactly the same tangent calculation functions and exactly the same cube position, normal and texture coordinate data as in working demo. After all, I exported arrays

(OpenGL 3.1 - 4.2) Dynamic Uniform Arrays?

拈花ヽ惹草 提交于 2019-11-30 13:25:38
问题 Lets say I have 2 species such as humans and ponies. They have different skeletal systems so the uniform bone array will have to be different for each species. Do I have to implement two separate shader programs able to render each bone array properly or is there a way to dynamically declare uniform arrays and iterate through that dynamic array instead? Keeping in mind performance (There's all of the shaders suck at decision branching going around). 回答1: Until OpenGL 4.3, arrays in GLSL had

GLSL branching behaviour

别等时光非礼了梦想. 提交于 2019-11-30 11:43:54
I have a rather simple fragment shader with a branch and I'm a bit unsure how it is handled by the GLSL compiler and how it would affect performance. uniform sampler2D sampler; uniform vec2 texSize; uniform vec2 targetSize; void main() { vec4 color; if(texSize == targetSize) color = texture2DNearest(sampler, gl_TexCoord[0]); else color = texture2DBicubic(sampler, gl_TexCoord[0]); gl_FragColor = color; } I have read from an AMDs document that sometimes both branches are executed, which would not be a good idea in this case. Without further information nor access to disassembly I'm unsure what

Debug GLSL code in webgl

℡╲_俬逩灬. 提交于 2019-11-30 11:41:55
Is it possible to debug GLSL code or print the variable values from within the glsl code while using it with webgl ? Do three.js or scene.js contain any such functionality? Not really, The way I usually debug GLSL is to output colors. So for example, given 2 shaders like // vertex shader uniform mat4 worldViewProjection; uniform vec3 lightWorldPos; uniform mat4 world; uniform mat4 viewInverse; uniform mat4 worldInverseTranspose; attribute vec4 position; attribute vec3 normal; attribute vec2 texCoord; varying vec4 v_position; varying vec2 v_texCoord; varying vec3 v_normal; varying vec3 v

Applying part of a texture (sprite sheet / texture map) to a point sprite in iOS OpenGL ES 2.0

本秂侑毒 提交于 2019-11-30 11:37:19
问题 It seems this should be easy but I'm having a lot of difficulty using part of a texture with a point sprite. I have googled around extensively and turned up various answers but none of these deal with the specific issue I'm having. What I've learned so far: Basics of point sprite drawing How to deal with point sprites rendering as solid squares How to alter orientation of a point sprite How to use multiple textures with a point sprite, getting closer here.. That point sprites + sprite sheets

glLineStipple deprecated in OpenGL 3.1

…衆ロ難τιáo~ 提交于 2019-11-30 11:24:06
问题 glLineStipple has been deprecated in the latest OpenGL APIs. What is it replaced with? If not replaced, how can I get a similar effect? (I don't want to use a compatibility profile of course...) 回答1: Sorry, it hasn't been replaced with anything. The first idea coming to my mind for emulating it would be the geometry shader. You feed the geometry shader with a line, compute its screen space length and based on that you generate a variable number of sub lines between its start and end vertex.