fragment-shader

GLSL reusable/shared functions, shared constants (OpenGL ES 2.0)?

笑着哭i 提交于 2019-12-04 18:49:27
问题 Short: Can I define a function that every shader can use? Or I have to define it per shader? The whole story: I want to create numerous shaders intended to colorize the input fragments with predefined gradient ramps (something like this - http://www.thinkboxsoftware.com/storage/krakatoa-support-images/krakatoa15_kcm_densitybyage_gradientrampmap.png). I want to define a gradient ramp constant for each shader (an array of vec4 color samples, where the alpha value holds the gradient position,

OpenGL ES 2.0 Shader - 2D Radial Gradient in Polygon

天涯浪子 提交于 2019-12-04 15:50:33
I am trying to paint a radial gradient inside a Polygon. My Stage is 600x320 . I am able to draw a gradient but it`s 'distorted/streched'. The goal is a gradient like a light would produce. u_lightPosition is passed as a relative value : {0.5, 0.5} . Currently unused lightPositionAbsolute is passed in as absolute value {300.0, 160.0} . My fragment-shader currently looks like this: #ifdef GL_ES precision lowp float; #endif varying vec4 v_fragmentColor; uniform vec2 u_lightPosition; uniform vec2 u_lightPositionAbsolute; uniform vec4 u_outerColor; uniform vec4 u_innerColor; uniform float u_radius

Creating a Gradient Color in Fragment Shader

孤人 提交于 2019-12-04 13:04:33
I'm trying to achieve making a gradient color as the design apps (Photoshop for example) does, but can't get the exact result i want. My shader creates very nice 'gradients' but also contains other colors that are different from the colors I want to switch in. It looks nice but, my aim is adding blending functions later and make a kind of color correction shader. but first of all I have to get the right colors. Here is my fragment shader http://player.thebookofshaders.com/?log=171119111216 uniform vec2 u_resolution; void main() { vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color1 = vec3(1

Custom Shader SCNProgram iOS 9 Scenekit

六眼飞鱼酱① 提交于 2019-12-04 08:32:11
问题 I am trying to mess around in SceneKit and teach myself it. Basically, I am creating a quad with 3 rectangular sides and 1 sloping slide. I want my texture on it to stretch and warp/deform across the surface. Reading some stuff online, it seems that I need to make an SCNProgram with custom vertex and fragment shaders to get the effect. But, I can't seem to get the texture to spread across the surface. Need help please. (I am new to graphics programming hence trying to teach it to myself). My

Get accurate integer modulo in WebGL shader

喜夏-厌秋 提交于 2019-12-04 08:17:12
I want to get an accurate modulo of x and y in a WebGL fragment shader. x and y are integers. Graphing mod(x,y) , we get the following: The actual code used to generate the red-and-black rectangle is: gl_FragColor = vec4(mod( float(int(v_texCoord[0]*15.))/15., float(int(v_texCoord[1]*15.))/15. ), 0, 0, 1); Where v_texCoord is a vec2 ranging from 0,0 at the top-left to 1,1 at the bottom-right. Precision is set to mediump for both float and int. Reading the chart, we see that although mod(6,6) is correctly 0 , mod(7,7) is actually 7 ! How do I fix this? I tried to implement my own mod() function

OpenGL GLSL Binding Sampler for Fragment Shader

こ雲淡風輕ζ 提交于 2019-12-04 05:28:54
问题 I am hoping to implement a shader on a 2D OpenGL application. My plan is to render a scene to a framebuffer object, and then render that framebuffer object to the screen using a shader. Here is the scene, which I have drawn to a framebuffer object, and then to the screen from there. Using the arrow keys makes the moon move around (I am quite proud of it!) However, when I try to render the framebuffer object to the screen using my shader program, I get this: It is very sad. This fragment

Three.js, custom shader and png texture with transparency

…衆ロ難τιáo~ 提交于 2019-12-04 04:47:58
I have an extremely simple PNG texture: a grey circle with a transparent background. I use it as a uniform map for a THREE.ShaderMaterial : var uniforms = THREE.UniformsUtils.merge( [basicShader.uniforms] ); uniforms['map'].value = THREE.ImageUtils.loadTexture( "img/particle.png" ); uniforms['size'].value = 100; uniforms['opacity'].value = 0.5; uniforms['psColor'].value = new THREE.Color( 0xffffff ); Here is my fragment shader (just part of it): gl_FragColor = vec4( psColor, vOpacity ); gl_FragColor = gl_FragColor * texture2D( map,vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) ); gl_FragColor

How to add transparency with a shader in SceneKit?

被刻印的时光 ゝ 提交于 2019-12-04 04:27:36
问题 I would like to have a transparency effect from an image, for now I just test with a torus, but the shader does not seem to work with alpha. From what I understood from this thread (Using Blending Functions in Scenekit) and this wiki link about transparency : (http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Transparency), GLBlendFunc is replaced by pragma transparency in SceneKit. Would you know what is wrong with this code? I created a new project with SceneKit, and I changed the ship

Render an SCNGeometry as a wireframe

醉酒当歌 提交于 2019-12-04 03:06:46
I'm using SceneKit on iOS and I have a geometry I want to render as a wireframe. So basically I want to draw only the lines, so no textures. I figured out that I could use the shaderModifiers property of the used SCNMaterial to accomplish this. Example of a shader modifier: material.shaderModifiers = [ SCNShaderModifierEntryPointFragment: "_output.color.rgb = vec3(1.0) - _output.color.rgb;" ] This example apparently simply inverts the output colors. I know nothing about this 'GLSL' language I have to use for the shader fragment. Can anybody tell me what code I should use as the shader fragment

LookAt function: I'm going crazy

我怕爱的太早我们不能终老 提交于 2019-12-04 00:55:49
问题 I must do a homework and I try to implement a lookAt function. I tried in many ways but the only result I got is a blue screen. The rest of my program works greatly, infact if I use glm::lookAt all is good. This is my code: mat4 Transform::lookAt(const vec3 &eye, const vec3 &center, const vec3 &up) { vec3 w(glm::normalize(eye - center)) ; vec3 u(glm::normalize(glm::cross(up, w))); vec3 v(glm::cross(w, u)) ; mat4 ret = mat4 ( vec4 (u.x,v.x,w.x,0), vec4 (u.y,v.y,w.y,0), vec4 (u.z,v.z,w.z,0),