shader

openGL shader: two object and one line to connect them

杀马特。学长 韩版系。学妹 提交于 2020-01-03 05:21:27
问题 I'm using shaders and the programmable pipeline, I need to connect two meshes with a line (maybe colored) but I just have the model matrices of these two objects. The line should start at the center of these objects so I assume the object-coords of the two points should be: start point: 0,0,0 end point: 0,0,0 to connect the two objects I assume I'll have to multiply these points in the shader by their respective object's model matrix. And then multiply everything by the view matrix (this is

Fragment shader: No uniform with name in shader

£可爱£侵袭症+ 提交于 2020-01-03 05:09:06
问题 I have problem with fragment shader in libgdx. Below is my fragment shader. #ifdef GL_ES precision mediump float; #endif uniform float u_aspectRatio; varying vec2 v_texCoords; uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, v_texCoords); } In program I do shader.setUniformi("u_texture", 0); // work fine shader.setUniformf("u_aspectRatio", 0.0f); //no uniform with name 'u_aspectRatio' in shader shader.isCompiled() return true and first set work fine, but in

unity光源自带的Halo效果

老子叫甜甜 提交于 2020-01-03 03:37:23
之前看过一个用来实现光晕效果的shader,但是这个shader似乎只适用于球状物,对于非球状物就不是很友好。效果如图1、图2所示。 图1 用shader实现的光晕效果 图2 光晕shader对非球状物体很不友好 今天发现unity中的光源居然自带halo效果(版本是2019.1.4f1),在inspector面板勾选Draw Halo即可,用它就可以来模拟光晕,效果还不错。如图3所示。 图3 用Draw Halo来实现光晕效果 搭配standard shader中的emission,感觉贼好用。(如图4的不明物体所示) 图4 Draw Halo和Emission配合使用的某不明物体 之前用的那个shader的实现原理似乎只是将纹理沿着模型方向伸展,然后再用一个类似于高光反射模型计算一下,得到的光晕并不是真正的光,所以暂时无法实现光照之间的交互(如阴影、反光等等)。这个halo就不一样了,由于它是跟光源捆绑在一起的,所以一般光源能实现的光照交互它基本上都有!如图5所示的反射效果。 图5 看左边球体上的红色反光! 当然这个halo也不是没有缺点,比如说在模拟非球形的光晕时还是略僵硬。如图6所示。 图6 用Draw Halo模拟非球状物体的光晕 图6中cube的scale分别是1、1、1,point light的range是2,必须要把point

Shader(1)_渐变色

核能气质少年 提交于 2020-01-02 14:11:52
(不懂shader的请自行转到我的Shader(0)_解剖Shader) 效果图: 原理: 根据uv是0到1的一个浮点数即可得到渐变的原理,在片段着色器的函数里面只需要把返回的颜色的xy值对应此像素uv值即可 代码: //仅修改片段着色器即可 fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); return fixed4(i.uv,0.5,1); } 来源: CSDN 作者: unity热爱者 链接: https://blog.csdn.net/weixin_43933605/article/details/103799852

Shader - Simple SSS lighting issue

夙愿已清 提交于 2020-01-02 09:28:07
问题 I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface color (red). As you might notice when the light is above the surface and really close to this surface its influence appears to minimize which is the expected behavior. But the problem is

Loading SPIRV binary shader fails

被刻印的时光 ゝ 提交于 2020-01-02 09:20:07
问题 In my program I tried to load precompiled binary shaders with the example code from Sasha Willems (https://github.com/SaschaWillems/openglcpp/blob/master/SPIRVShader/main.cpp): bool loadBinaryShader(const char *fileName, GLuint stage, GLuint binaryFormat, GLuint &shader) { std::ifstream shaderFile; shaderFile.open(fileName, std::ios::binary | std::ios::ate); if (shaderFile.is_open()) { size_t size = shaderFile.tellg(); shaderFile.seekg(0, std::ios::beg); char* bin = new char[size]; shaderFile

Metal emulate geometry shaders using compute shaders

北战南征 提交于 2020-01-02 03:40:09
问题 I'm trying to implement voxel cone tracing in Metal. One of the steps in the algorithm is to voxelize the geometry using a geometry shader. Metal does not have geometry shaders so I was looking into emulating them using a compute shader. I pass in my vertex buffer into the compute shader, do what a geometry shader would normally do, and write the result to an output buffer. I also add a draw command to an indirect buffer. I use the output buffer as the vertex buffer for my vertex shader. This

Metal SCNProgram - can't render a SpriteKit scene that has video content

不问归期 提交于 2020-01-01 12:08:10
问题 I'm (desperately) trying to use a video as texture in a SCNScene with some fancy shader modifiers. I'd like to use a SCNProgram for that part. I've just taken the one from here: #include <metal_stdlib> using namespace metal; #include <SceneKit/scn_metal> struct MyNodeBuffer { float4x4 modelTransform; float4x4 modelViewTransform; float4x4 normalTransform; float4x4 modelViewProjectionTransform; }; typedef struct { float3 position [[ attribute(SCNVertexSemanticPosition) ]]; float2 texCoords [[

Get accurate integer modulo in WebGL shader

拜拜、爱过 提交于 2020-01-01 10:49:13
问题 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)

Unity Shader中两种模拟瓶中液体的方法

别来无恙 提交于 2020-01-01 10:42:26
前言 作为一个没有什么实际项目可以让我去操作练手的shader新手,只能在网上看看别人的一些想法并学习一下。我之前通过科学上网在推特上看到了Joyce[MinionsArt]@minionsart大神(有条件的朋友可以关注一下他,真的很有帮助)的用shader模拟液体晃动的效果,便尝试写了写,大体思路总归是那个思路,但是具体实现还是很有我个人风格的,与他的并不完全一致,可以说是简单了很多。写这篇博客是因为并没有在国内网站上找到类似的实现,所以给大家分享一下。 两种方法介绍 第一种方法是用 片元裁剪 控制水面高低,然后用背面渲染模拟水面(这是上面提到的Joyce的想法,这种方法实现简单且对液体形状要求比较灵活,但是因为没有水面,所以有些后续效果实现不了)。第二种就是 顶点动画 ,知乎上已经有人实现了一些基本效果,想看具体的实现可以 点击这里 ,也可以继续看我的这篇博文(实现方法类似但是我的在某些细节处理上比较简单)。 最终效果 首先话不多说,上效果图 上面这张图片是第一种方法的最终效果图,第二种方法是一样的,所以我就只写了Shader,没有脚本去控制动画。 第二种方法的效果图如下 具体实现方法 片元裁剪 这种方法对于外面的罩子可以用一个稍大于液体的同样形状的物体来模拟,也可以把罩子和液体当作一个物体渲染,就是在液体的基础上按法线方向挤出一定距离来渲染罩子