shader

How can I tint a sprite to white in XNA?

≯℡__Kan透↙ 提交于 2019-12-07 04:44:47
问题 I don't think this is possible just using the color setting in SpriteBatch, so I'm trying to work out a simple shader that would take every pixel and make it white, while respecting the alpha value of the pixel. The answer Joel Martinez gave looks right, but how do I incorporate that when I draw the sprite with SpriteBatch? 回答1: I think this is what you're looking for sampler2D baseMap; struct PS_INPUT { float2 Texcoord : TEXCOORD0; }; float4 ps_main( PS_INPUT Input ) : COLOR0 { float4 color

Threejs DataTexture Not Updating

99封情书 提交于 2019-12-07 03:15:28
UPDATE: Issue was that texData object was recreated each time and thus reference for DataTexture was lost. Solution by WestLangley was to overwrite the data in texData instead of recreating texData object. I have a simple threejs scene with a DataTexture in a ShaderMaterial . The data array passed to it once during initialization is updated on mouse events. However the DataTexture does not seem to update. Did i assign uniforms or texture data wrongly? Or using the needsUpdate flags wrongly? It does work when deleting and recreating the texture, material, mesh and scene objects each time, but

How to modify/displace pixel position in a Cg fragment shader?

房东的猫 提交于 2019-12-07 03:11:27
Is it possible to modify pixel coordinates in a fragment (pixel) shader using Cg? I'm sure such functionality became available in 2nd/3rd-generation shaders but I don't know what profiles exactly, or how to do it. No, it is not possible. The only coordinate you can modify in a fragment shader is the Z, going into the Z-buffer. And even that has performance implications, as it defeats some optimizations (like Hierarchical Z). the X and Y positions are set before the fragment shader is ever executed (in the Rasterizer ). Typical rasterizers actually generate at the very least 2x2 chunks of

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

℡╲_俬逩灬. 提交于 2019-12-07 02:11:35
问题 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

Shader's function parameters performance

我怕爱的太早我们不能终老 提交于 2019-12-07 02:05:28
问题 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

Directx 11, send multiple textures to shader

吃可爱长大的小学妹 提交于 2019-12-07 02:01:15
问题 using this code I can send one texture to the shader: devcon->PSSetShaderResources(0, 1, &pTexture); Of course i made the pTexture by: D3DX11CreateShaderResourceViewFromFile Shader: Texture2D Texture; return color * Texture.Sample(ss, texcoord); I'm currently only sending one texture to the shader, but I would like to send multiple textures, how is this possible? Thank You. 回答1: By using Texture Arrays. When you fill out your D3D11_TEXTURE2D_DESC look at the ArraySize member. This desc struct

Full setup of Transform Feedback(openGL)

 ̄綄美尐妖づ 提交于 2019-12-07 02:01:07
问题 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

【Shader】通过Shader实现森林树木随风摆动效果

情到浓时终转凉″ 提交于 2019-12-06 22:15:45
大家首先可以想象一下这样的场景:场景中有一大片森林,我想让这片森林的树木有微风轻轻吹拂而缓缓摆动的效果,应该要怎么实现呢? A:给每棵树加个动画,让动画来控制摆动 方案A如果在树木少的情况下还是属于可接受范围的,而且用美术童鞋做的动画来控制树木摆动会显得更真实更生动。不过注意,当是“森林”的时候,这一动起来,CPU估计就吃不消了,若是美术童鞋为了让树木更生动,加的是骨骼动画,那CPU和DrawCall将会爆表! B:用代码控制树木位移来实现 方案B当然不可能是每棵树挂个脚本,那对性能是极大的浪费。若是直接控制整片森林的位移,首先是要把整片森林形成一个整体,然后是用代码每帧循环地去控制位移。虽然能达到摆动,但是动起来会非常的怪异,很难达到理想的效果,大神们可以去尝试一下。 C:使用Unity自带的Tree和WindZone 方案C不失为一个好方法,能够实现很真实的效果。不过使用Unity自带的Tree有很多美术上的限制,而且配置Tree和Wind Zone也是非常麻烦,性能也有一定的消耗。有时候当我们只需要实现简单的摆动功能,就会显得有些得不偿失,性价比不是很高。 D:… 总而言之,方案各式各样,种类繁多,选中最适合自己的那一个才重要。综上所述,要实现符合简单、仿真、高性能的三大条件,通过Shader的帧动画变换UV采样贴图来实现效果,将是一个不错的选择。 简要说一下原理

Unity中使用GPU Instancing优化SkinnedMesh渲染

主宰稳场 提交于 2019-12-06 22:12:11
有这么个需求: 一堆不会动的SkinnedMesh, 通过物理模拟出死亡姿势后, 需要优化性能, 不然才10FPS 首先想到的做法是转成StaticMesh. 试了一下直接超出了Unity的顶点Index数量限制, 所以放弃, 再说转换完后也不方便编辑. 另一个思路就是使用Instanced Skinned Mesh Rendering, 找到两个参考: https://github.com/Unity-Technologies/Animation-Instancing https://github.com/chengkehan/GPUSkinning 不过这两个实现都是考虑了Animation的, 会采样AnimationClip的Transform序列帧写入纹理. 直接拿来是没法用的, 所以就参考他们的做法自己也实现了个Instancing的优化. 大家做SkinnedMeshInstancing的思路都差不多, 所以整个优化的流程就比较容易理清了: 把SkinnedMesh转换成StaticMesh, 把每个顶点的蒙皮混合权重和骨骼索引写到顶点的color/uv1/uv2, 通常情况下都是4个bone index加上4个blend weight. 每个SkinnedMesh的Pose都是一系列的变换矩阵, 去掉一行后做为3个Color写入RGBAHalf纹理

GLSL : accessing framebuffer to get RGB and change it

随声附和 提交于 2019-12-06 19:34:33
I'd like to access framebuffer to get RGB and change their values for each pixel. It is because the glReadPixels, and glDrawPixels are too slow to use, so that i should use shaders instead of using them. Now, I write code, and success to display three-dimensional model using GLSL shaders. I drew two cubes as follows. .... glDrawArrays(GL_TRIANGLES, 0, 12*6); .... and fragment shader : varying vec3 fragmentColor; void main() { gl_FragColor = vec4(fragmentColor, 1); } Then, how can I access to RGB values and change it? For example, If the pixel values at (u1, v1) on window and (u2, v2) are (0,0