shader

OpenGL ES 2.0 GLSL texture2D return value when unbound

时光总嘲笑我的痴心妄想 提交于 2019-12-02 03:22:17
问题 In the following code: gl_FragColor = vColor * texture2D(u_Texture, v_TexCoordinate); I noticed the default value returned by texture2D is a white (1,1,1,1) if u_Texture is unbound. Is it safe to base my shader on this fact? 回答1: I wouldn't have thought so. I have seen other instances where the default value has been black. It could theoretically be any colour in the case where the memory used by the sampler is a section of uninitialised video memory, it depends on the opengl implementation

Assimp里的一些知识(1)

浪尽此生 提交于 2019-12-02 02:48:38
OpenGL 学习到模型加载的时候,介绍了一个模型导入库(Open Asset Import Library,Assimp)的用法。初学的时候觉得稍微有些复杂,故借由这篇blog来简单地捋一下其中的细节。 首先,当我们使用Assimp导入模型的时候,它通常会将整个模型加载到一个场景(Scene)对象,这个对象包含了导入模型的所有数据。具体结构如下图所示(这个图结构十分重要,需要充分理解): Scene 场景。 Scene 场景有3个成员,分别是 mRootNode (场景根节点), mMeshes (场景中所有网格 Mesh 的集合), mMaterials (网格的材质属性)。 Node 节点。 场景的根节点( Root Node , mRootNode 指向)包含了子节点,同时每个节点中有一系列指向场景对象中具体mMeshes成员的索引(Scene下的 mMeshes 数组储存了真正的 Mesh 对象,节点中的 mMeshes 数组保存的只是场景中网格数组的索引)。此外,这个子结构让我们可以使用递归的方式来处理节点(稍后讲到)。 Mesh 网格, 一个 Mesh 网格是可以看做渲染的一个单位,它包含了顶点数据,法线,纹理坐标(只是坐标数据,不是纹理对象),面等 数组 ,以及材质索引(指向 Scene 中的 mMaterials ) Face 面, 面数组由面组成(废话),概念上

What is the fastest shadowing algorithm (CPU only)?

久未见 提交于 2019-12-02 02:37:48
Suppose I have a 3D model: The model is given in the form of vertices, faces (all triangles) and normal vectors. The model may have holes and/or transparent parts. For an arbitrarily placed light source at infinity, I have to determine: [ required ] which triangles are (partially) shadowed by other triangles Then, for the partially shadowed triangles: [ bonus ] what fraction of the area of the triangle is shadowed [ superbonus ] come up with a new mesh that describe the shape of the shadows exactly My final application has to run on headless machines , that is, they have no GPU . Therefore,

Unity粒子系统和其他

前提是你 提交于 2019-12-02 02:36:05
1、Shuriken粒子系统   在3D游戏里,大部分的游戏对象可以用meshes(网格模型)的形式来呈现。2D游戏通常用sprites(精灵)来显示。对于固定形状的游戏对象,网格模型和精灵的确是非常理想的视觉呈现方式。但在游戏里还需要其他的元素或对象,它们的自然形状并非固定不变,因而难以用网格模型或精灵实现。   例如风云雷电雨雾等,这类的对象通常要靠粒子系统特效完成。 (1)什么是粒子系统   粒子系统是指很小很简单的2D图像或者3D网格模型。在粒子系统中,通过各种设置让微小的粒子以某种特定的形态展示出来,就形成了粒子特效。   一般来说,每个粒子都有预定的生命周期。通常设置为数秒。在这段时间内,粒子会经历不同的变化。 (2)Shuriken粒子系统   2012年,Unity从3.5版本开始支持Shuriken粒子系统。在Unity里,粒子系统是以组件的形式实现的。   粒子系统虽然有很多属性,但大体上可以分为三类: 粒子系统的主模块、粒子系统的具体属性模块、以及默认的粒子纹理及Shader 。 2、Shader的使用 (1)什么是Shader   在计算机图形学中,Shader(着色器)是指专用于渲染着色的计算机程序,其作用是设置图像的光照、阴暗和色彩等。Shader通常以极高的灵活性在图形硬件上计算所渲染的效果。大多数的Shader在编码时是针对图形处理单元(GPU)的

Reading a shader from a .txt file using a structure

你。 提交于 2019-12-02 01:29:10
I've started learning how to use OpenGL and I absolutely hate having my shaders declared as global variables before my main(). I thought it would be cool to make a structure or class that would read the shader from a file in my project directory. The file reading works perfectly fine, but for some reason it won't actually output an image like it would if I had the shader declared before main. Here is my example. Shader Reading Structure: #include "allHeader.h" struct shaderReader { shaderReader::shaderReader(std::string); const GLchar* source; }; shaderReader::shaderReader(std::string name) {

How to pass-through fixed-function material and lighting to fragment shader?

旧城冷巷雨未停 提交于 2019-12-02 01:19:43
问题 I am adding a vertex and fragment shader to my OpenGL 2.1/GLSL 1.2 application. Vertex shader: #version 120 void main(void) { gl_Position = ftransform(); gl_FrontColor = gl_Color; } Fragment shader: #version 120 void main(void) { if (/* test some condition */) { discard; } else { gl_FragColor = gl_Color; } } The problem is that if the condition fails, gl_FragColor just gets set to whatever the last call to gl.glColor3f() was in my fixed-function method. Instead, I want to pass through the

GLSL: pow vs multiplication for integer exponent

孤街浪徒 提交于 2019-12-02 00:52:34
Which is faster in GLSL: pow(x, 3.0f); or x*x*x; ? Does exponentiation performance depend on hardware vendor or exponent value? While this can definitely be hardware/vendor/compiler dependent, advanced mathematical functions like pow() tend to be considerably more expensive than basic operations. The best approach is of course to try both, and benchmark. But if there is a simple replacement for an advanced mathematical functions, I don't think you can go very wrong by using it. If you write pow(x, 3.0) , the best you can probably hope for is that the compiler will recognize the special case,

HLSL 3 Can a Pixel Shader be declared alone?

江枫思渺然 提交于 2019-12-01 21:11:25
I've been asked to split the question below into multiple questions: HLSL and Pix number of questions This is asking the first question, can I in HLSL 3 run a pixel shader without a vertex shader. In HLSL 2 I notice you can but I can't seem to find a way in 3? The shader will compile fine, I will then however get this error from Visual Studio when calling SpriteBatch Draw(). "Cannot mix shader model 3.0 with earlier shader models. If either the vertex shader or pixel shader is compiled as 3.0, they must both be." I don't believe I've defined anything in the shader to use anything earlier then

Three.js object self shadow itself depending on geometry

有些话、适合烂在心里 提交于 2019-12-01 20:29:47
I have playing a little with clara.io and i want to reproduce an image done with it. I have searched the web for days looking up to reproduce what they call "Realistic" rendering. As you can see on the image the six round part have they own shadows on the (one piece) brick from multiple lights sources. I have no idea how they done that, if it is a simple setup, or a complex shader. the best i can do is that and i have no idea how to proceed to make and object shadowing itself depending of it's geometry. any trails ? ie. Actually it is a very simple setup. The THREE.Object3D has two attributes

Export from Shadertoy to Three.js

假装没事ソ 提交于 2019-12-01 20:21:46
I am making my first steps coding. I made some courses on internet, then I played with some three.js experiments, and now I would like to continue learning experimenting with Shaders. I found Shadertoy.com and it's really amazing! There are a lot of difference experiments with incredible effects. I am trying to use one of these shaders in Three.js but is not so easy. The Shaders are already written, it's true. But I don't know what to do with that, I don't know how I can use it. Because it's not only copy and paste the code. There is a relation that I have to write to can apply some of these