fragment-shader

How to use texture2d_array array in metal?

北城以北 提交于 2019-12-06 10:08:12
I have been trying to use texture2d_array for my application of live filters in metal. But I'm not getting the proper result. Im creating the texture array like this, Code: Class MetalTextureArray . class MetalTextureArray { private(set) var arrayTexture: MTLTexture private var width: Int private var height: Int init(_ width: Int, _ height: Int, _ arrayLength: Int, _ device: MTLDevice) { self.width = width self.height = height let textureDescriptor = MTLTextureDescriptor() textureDescriptor.textureType = .type2DArray textureDescriptor.pixelFormat = .bgra8Unorm textureDescriptor.width = width

OpenGL ES 2.0 Shader - 2D Radial Gradient in Polygon

北战南征 提交于 2019-12-06 09:27:50
问题 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

Multiple subroutine types defined in the same fragment shader does not work correctly using GLSL Shaders

喜夏-厌秋 提交于 2019-12-06 09:20:14
I'm working on a program using GLSL shaders. I coded 2 different ways to compute ADS (Ambient + Diffuse + Specular) shading in 2 different methods. To do the job properly I used subroutines to use one or the other method to compute ADS shading. Here's a piece of the fragment shader code : subroutine vec3 LightShadingEffectType(int idx, vec3 normal, vec3 lightDir); subroutine uniform LightShadingEffectType LightShadingEffect; subroutine (LightShadingEffectType) vec3 Basic_ADS_Shading(int idx, vec3 normal, vec3 lightDir) { vec3 reflectDir = reflect(-lightDir, normal); vec3 viewDir = normalize(

Three.js - a vertex shader to color based on location of pixel on screen

こ雲淡風輕ζ 提交于 2019-12-06 09:14:13
问题 Using Three.js, I have written a vertex shader that colors each point in a plane according to which quadrant of the screen a pixel is rendered. // vertex shader uniform float width; uniform float height; varying float x; varying float y; void main() { vec4 v = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); x = v.x; y = v.y; gl_Position = v; } // fragment shader varying float x; varying float y; void main() { gl_FragColor = vec4(x, y, 0.0, 1.0); } Live example at jsFiddle: http:/

Unity 3d Sprite Shader (How do I limit Max Brightness to 1 with Multiple Lights Hitting)

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:43:30
I am creating a videogame in Unity. Every sprite is rendered with a Sprite Renderer with a Material that has the CornucopiaShader.shader. The problem I have is I want to limit the max brightness (or color) of the sprite to just be a normal image of the sprite regardless of the power of how many point lights are hitting it, the intensity of the lights, and also the ambient light in the unity scene. When the intensity of the lights hitting the sprite is below that max brightness level I want it to act like a normal lit sprite and be black if no lights are hitting it, and be half lit up if an

How fragment shader determines the number of fragments from vertex shader output?

你说的曾经没有我的故事 提交于 2019-12-06 06:07:22
问题 I'm familiar with vertex and fragment shaders but still confused about how a fragment shader determines the amount of fragments from the output of vertex shader. If I have 3 vertices and I draw a triangle primitive in GLSL, then vertex shader will run three times for every vertex and then fragment shader will run many times (depending upon the number of fragments, once for each fragment). I want to know how fragment shader determines the fragments? Does it use gl_Position? If I don't set gl

Three.js, custom shader and png texture with transparency

瘦欲@ 提交于 2019-12-05 23:51:48
问题 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

Metal shader in SceneKit to outline an object

≯℡__Kan透↙ 提交于 2019-12-05 21:17:38
I'm playing around and trying to implement Metal shader in SceneKit that will outline an object. The idea is to draw an outline (or silhouette) similar to this image found in this blogpost (the blogpost doesn't contain any code): I'm new to SceneKit and Metal shaders so I'm able just to draw some geometry and write simple vertex or fragment shader. I'm curious how can I achieve this kind of effect? Is it done in multiple passes? Cheers! The basic idea here is to clone the "selected" node and its geometry, then use a custom vertex and fragment shader to "push" the geometry out along the vertex

OpenGL - Fixed pipeline shader defaults (Mimic fixed pipeline with shaders)

不羁的心 提交于 2019-12-05 14:34:35
Can anyone provide me the shader that are similar to the Fixed function Pipeline? I need the Fragment shader default the most, because I found a similar vertex shader online. But if you have a pair that should be fine! I want to use fixed pipeline, but have the flexability of shaders, so I need similar shaders so I'll be able to mimic the functionality of the fixed pipeline. Thank you very much! I'm new here so if you need more information tell me:D This is what I would like to replicate: (texture unit 0) functionality of glTranslatef functionality of glColor4f functionality of glTexCoord2f

Three.js - shader code for halo effect, normals need transformation

安稳与你 提交于 2019-12-05 00:02:47
问题 I am attempting to create a shader to produce a glowing halo effect in Three.js. My current attempt is live here: http://stemkoski.github.io/Three.js/Shader-Halo.html The shader code is currently: <script id="vertexShader" type="x-shader/x-vertex"> varying vec3 vNormal; void main() { vNormal = normalize( normalMatrix * normal ); gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); } </script> <script id="fragmentShader" type="x-shader/x-vertex"> varying vec3 vNormal; void