天道酬勤,学无止境

shader

如何获取片段的当前颜色?(How do I get the current color of a fragment?)

问题 我正在尝试围绕 GLSL 中的着色器进行思考,并且我找到了一些有用的资源和教程,但是我一直在为一些应该是基本和微不足道的事情而陷入困境:我的片段着色器如何检索当前片段? 您可以通过说gl_FragColor = whatever设置最终颜色,但显然这是一个仅输出值。 如何获得输入的原始颜色,以便对其进行计算? 那肯定是在某个地方的一个变量中,但是如果那里有人知道它的名字,他们似乎没有将它记录在我迄今为止遇到的任何教程或文档中,这让我感到沮丧。 回答1 片段着色器接收gl_Color和gl_SecondaryColor作为顶点属性。 它还有四个不同的变量: gl_FrontColor 、 gl_FrontSecondaryColor 、 gl_BackColor和gl_BackSecondaryColor ,它可以写入值。 如果您想直接传递原始颜色,您可以执行以下操作: gl_FrontColor = gl_Color; gl_FrontSecondaryColor = gl_SecondaryColor; gl_BackColor = gl_Color; gl_BackSecondaryColor = gl_SecondaryColor; 紧跟顶点着色器的管道中的固定功能然后会将这些限制在范围 [0..1] 内,并确定顶点是正面还是背面。 然后它会像往常一样插入所选的

2021-06-21 08:49:04    分类:技术分享    opengl   shader   glsl   fragment-shader

Add alpha to shader in Unity3D

I don't have any idea about shader programming but right now I need to add alpha to the shader that I want to use. Actually I want to fade in and fade out my sprite but it's not in the shader that I use. Shader : Shader "Sprites/ClipArea2Sides" { Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {} _Length ("Length", Range(0.0, 1.0)) = 1.0 _Width ("Width", Range(0.0, 1.0)) = 1.0 } SubShader { LOD 200 Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } Pass { Cull Off Lighting Off ZWrite Off Offset -1, -1 Fog { Mode Off } ColorMask RGB Blend

2021-06-15 17:14:01    分类:问答    unity3d   shader   fade   alpha

Glitchy Facial Morph Target Animation in OpenGL (C++)

I've been trying to implement Morph Target animation in OpenGL with Facial Blendshapes but following this tutorial. The vertex shader for the animation looks something like this: #version 400 core in vec3 vNeutral; in vec3 vSmile_L; in vec3 nNeutral; in vec3 nSmile_L; in vec3 vSmile_R; in vec3 nSmile_R; uniform float left; uniform float right; uniform float top; uniform float bottom; uniform float near; uniform float far; uniform vec3 cameraPosition; uniform vec3 lookAtPosition; uniform vec3 upVector; uniform vec4 lightPosition; out vec3 lPos; out vec3 vPos; out vec3 vNorm; uniform vec3 pos

2021-06-15 06:59:17    分类:问答    c++   opengl   animation   shader   morphing

Full setup of Transform Feedback(openGL)

GLSL 1.50, openGL 3.3. I've been lately trying to get my tranform feedback working but without success. I still receive error after glBeginTranformFeedback() and as I haven't found any full working code I have stacked up my knowledge with some code that I found and documentation, it should be working well by now but I am missing something. So if anybody got full code (initializing of buffers, setting up, updating, rendering, reading back) it would definitelly help and if you don't but know what's going on you could take look at my code. I excluded some benchmarking, handling of windows and it

2021-06-15 06:44:01    分类:问答    c++   opengl   glsl   shader   feedback

How to define an array of floats in Shader properties?

I'd like to define an array of floats in my shader, something like this: Properties { _TilesX ("Tiles X", Int) = 10 _TilesY ("Tiles Y", Int) = 10 _TileData1 ("Tile data", Float[]) = {} // THIS!!! _Texture1 ("Texture odd", 2D) = "white" {} _Texture2 ("Texture even", 2D) = "white" {} } I'm trying to create a single plane that I'll use as a grid and I want to modify the _TileData1 at run-time to change the Y offset of a tile. I'm using _TilesX and _TilesY to get a 2d position of the tile from a 1d array. Just to be clear, I just want to find out how to define a property type of float[] since I

2021-06-14 21:44:29    分类:问答    unity3d   shader

How do i display 2 or more objects in openGL (model - view - projection matrices and shaders)

It's all ok when i want to draw one object, for example a cube. I create vertices for cube, i create the buffer, i create the MVP matrix and send it to shader and it works nice. But, what to do when i want to draw 2 or more objects, for example both cube and a triangle? I believe that View and Projection matrices should be same both for triangle and cube, i only need different Model matrix, right? So that means that i will have two MVPs? //Example (using GLM): glm::mat4 MVPC = Projection * View * ModelCube; glm::mat4 MVPT = Projection * View * ModelTriangle; So what do i do with those two now

2021-06-14 12:13:26    分类:问答    opengl   glsl   shader

Shader's function parameters performance

I'm trying to understand how passing parameters is implemented in shader languages. I've read several articles and documentation, but still I have some doubts. In particular I'm trying to understand the differences with a C++ function call, with a particular emphasis on performances. There are slightly differences between HSLS,Cg and GLSL but I guess the underline implementation is quite similar. What I've understood so far: Unless otherwise specified a function parameter is always passed by value (is this true even for matrix?) Passing by value in this context hasn't the same implications as

2021-06-14 06:03:35    分类:问答    opengl   directx   glsl   shader   hlsl

Normal mapping GLSL using LibGDX

I try to implement normal mapping using LibGDX. So I got some positive results when I calculate diffuse and specular color in vertex shader (at least I think so). Vertex shader: attribute vec4 a_position; attribute vec2 a_texCoord0; attribute vec3 a_normal; varying vec2 v_texCoord; varying float v_diffuse; varying vec3 v_specular; varying vec3 v_lightVec; uniform mat4 u_worldTrans; uniform mat4 u_projTrans; uniform mat4 u_matViewInverseTranspose; uniform mat4 u_matModelView; const vec3 lightVector = vec3(0.0,0.0,-1.0); void main() { // Output the unmodified vertex position. gl_Position = u

2021-06-13 22:18:16    分类:问答    opengl   libgdx   glsl   opengl-es-2.0   shader

Are 1D Textures Supported in WebGL yet?

I've been trying to find a clear answer, but it seems no one has clearly asked the question. Can I use a 1D sampler and 1D texture in WebGL Chrome, Firefox, Safari, IE, etc? EDIT Understandably 1 is indeed a power of 2 (2^0=1) meaning you could effectively use a 2D sampler and texture using a height of 1 and a width of 256 or 512 etc. to replicate a 1D texture. 1D textures are not moot, they exist because they not only have a purpose, but are intended to translate into optimizations on the GPU itself (as opposed to a 2D texture). Remember that each parameter takes time to load onto the call

2021-06-13 09:00:58    分类:问答    glsl   webgl   shader   fragment-shader   glsles

Using different push-constants in different shader stages

I have a vertex shader with a push-constant block containing one float: layout(push_constant) uniform pushConstants { float test1; } u_pushConstants; And a fragment shader with another push-constant block with a different float value: layout(push_constant) uniform pushConstants { float test2; } u_pushConstants; test1 and test2 are supposed to be different. The push-constant ranges for the pipeline layout are defined like this: std::array<vk::PushConstantRange,2> ranges = { vk::PushConstantRange{ vk::ShaderStageFlagBits::eVertex, 0, sizeof(float) }, vk::PushConstantRange{ vk

2021-06-13 08:32:34    分类:问答    glsl   shader   vulkan