shader

How do I create free hand mask on Image Like below using glsl Shader In android?

こ雲淡風輕ζ 提交于 2019-12-13 03:16:51
问题 I'm new to OpenGL and GLSL Programming. Recently I need to do freehand masking on an image like below Image. How could I achieve this using Fragment Shader? Currently, I am trying this with below fragment shader but Nothing Change on Image. precision mediump float; varying vec2 v_TexCoordinate; varying vec2 v_TexCoordinate2; uniform sampler2D u_Texture; uniform sampler2D u_Texture2; uniform bool u_alpha_test_enable; void main() { float mask = texture2D(u_Texture, v_TexCoordinate).a; // if (u

DirectX compute shader: how to write a function with variable array size argument?

纵然是瞬间 提交于 2019-12-13 03:07:58
问题 I'm trying to write a function within a compute shader (HLSL) that accept an argument being an array on different size. The compiler always reject it. Example (not working!): void TestFunc(in uint SA[]) { int K; for (K = 0; SA[K] != 0; K++) { // Some code using SA array } } [numthreads(1, 1, 1)] void CSMain( uint S1[] = {1, 2, 3, 4 }; // Compiler happy and discover the array size uint S2[] = {10, 20}; // Compiler happy and discover the array size TestFunc(S1); TestFunc(S2); } If I give an

How to use a 3x3 2D transformation in a vertex/fragment shader (Metal)

梦想的初衷 提交于 2019-12-13 02:37:43
问题 I have a supposedly simple task, but apparently I still don't understand how projections work in shaders. I need to do a 2D perspective transformation on a texture quad (2 triangles), but visually it doesn't look correct (e.g. trapezoid is slightly higher or more stretched than what it is in the CPU version). I have this struct: struct VertexInOut { float4 position [[position]]; float3 warp0; float3 warp1; float3 warp2; float3 warp3; }; And in the vertex shader I do something like ( texCoords

Change color in middle of circle

自作多情 提交于 2019-12-13 01:19:13
问题 I'm new to WebGL and I'm trying to create a black ring in the middle of this green circle without making additional circles. I believe I can do this by making the normal of those triangles go the other way but I'm not sure exactly how to do this. My friend suggested changing the texture coordinates but I don't really understand how this would help. Can anyone shine some light on these ideas and possible intuition? _______HTML File__________ <!DOCTYPE html> <html> <head> <script id="vertex

Libgdx 3D - Point Light shows black box & rect (PointLight not working)

旧时模样 提交于 2019-12-13 00:59:45
问题 I am creating a 3d scene currently a box and rect, and trying to enable lighting. When i create a PointLight and add it to Environment everything turns to black color? all i want to do is create a 3d scene and enable point light, like a sun or rays coming from a point and shading the objects. Code: environment = new Environment(); environment.add(new PointLight().set(1f, 1f, 1f, 0, 0, 20f, 100f)); modelBatch=new ModelBatch(); .. square=new ModelBuilder().createBox(300,300,300,new Material

WebGL fragment shader opacity

风流意气都作罢 提交于 2019-12-12 22:11:31
问题 Alright, first off, I'm pretty new at GLSL shaders, and I'm trying to wrap my head around the following shader #ifdef GL_ES //precision mediump float; precision highp float; #endif uniform vec2 uTimes; varying vec2 texCoord; varying vec2 screenCoord; void main(void) { vec3 col; float c; vec2 tmpv = texCoord * vec2(0.8, 1.0) - vec2(0.95, 1.0); c = exp(-pow(length(tmpv) * 1.8, 2.0)); col = mix(vec3(0.02, 0.0, 0.03), vec3(0.96, 0.98, 1.0) * 1.5, c); gl_FragColor = vec4(col * 0.5, 0); } So far, I

How to draw cylinder in modern opengl

余生颓废 提交于 2019-12-12 17:54:21
问题 My question is simple, how do I draw a cylinder in modern OpenGL? I'm using GLFW together with OpenGL 3.x. My thought at first was to create a function that computes the vertex positions at the bottom and at the top as circles and then draw lines between these vertices. But I have no idea how to implement this.. Does anyone have a good solution? 回答1: You can do that with a triangle strip and generate a vertex at the bottom then one at the top. That should generate the sides easily. Then just

GLSL How to retrieve vertex position after a shader process it?

谁说胖子不能爱 提交于 2019-12-12 16:45:01
问题 I wrote a program that simulates soft bodies using springs. It looks nice but the problem is it consumes a lot of CPU time. So I can not run it on my laptop or any not high end PC. I thought It would be a good idea to write a vertex shader and move the logic to the GPU. I've read some tutorials and made a toon shader so I thought (wrong) I was ready to go. The big problem I have is that I need to know the old position of a vertex to calculate the new one. I don't know how could I retrieve a

unity: gameobjects invisible?

妖精的绣舞 提交于 2019-12-12 15:15:58
问题 I combined two shaders which can show transparency and cutoff Alpha. It works pretty fine, just two small problems stay. (1) in some specific camera angles the cutoff regions of an object are visible (only if a another object with the same shader is located behind that one) (2) if I fade out an object it's getting black not transparent I'm new to shader-coding, thanks a lot for your help!! Here's the shader: Shader "Unlit/MyTransparent" { Properties{ _Color("Main Color", Color) = (1,1,1,0.5)

Libgdx shader setup NullPointerException

偶尔善良 提交于 2019-12-12 14:49:50
问题 I try to setup my shader like this: fog = new ShaderProgram(Gdx.files.local("shader/shad.vert"), Gdx.files.local("shader/shad.frag")); But it gives me this exception: Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113) Caused by: java.lang.NullPointerException at com.badlogic.gdx.graphics.glutils.ShaderProgram.loadShader(ShaderProgram.java:194) at