glsl

Convert floating-point numbers to decimal digits in GLSL?

情到浓时终转凉″ 提交于 2019-11-26 02:14:34
问题 As others have discussed, GLSL lacks any kind of printf debugging. But sometimes I really want to examine numeric values while debugging my shaders. I\'ve been trying to create a visual debugging tool. I found that it\'s possible to render an arbitrary series of digits fairly easily in a shader, if you work with a sampler2D in which the digits 0123456789 have been rendered in monospace. Basically, you just juggle your x coordinate. Now, to use this to examine a floating-point number, I need

Should I ever use a `vec3` inside of a uniform buffer or shader storage buffer object?

自古美人都是妖i 提交于 2019-11-26 01:43:14
问题 The vec3 type is a very nice type. It only takes up 3 floats, and I have data that only needs 3 floats. And I want to use one in a structure in a UBO and/or SSBO: layout(std140) uniform UBO { vec4 data1; vec3 data2; float data3; }; layout(std430) buffer SSBO { vec4 data1; vec3 data2; float data3; }; Then, in my C or C++ code, I can do this to create matching data structures: struct UBO { vector4 data1; vector3 data2; float data3; }; struct SSBO { vector4 data1; vector3 data2; float data3; };

Normal mapping gone horribly wrong

末鹿安然 提交于 2019-11-26 01:02:31
问题 I tried to implement normal mapping in my opengl application but I can\'t get it to work. This is the diffuse map (which I add a brown color to) and this is the normal map. In order to get the tangent and bitangent (in other places called binormals?) vectors, I run this function for every triangle in my mesh: void getTangent(const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec2 &uv0, const glm::vec2 &uv1, const glm::vec2 &uv2, std::vector<glm::vec3> &vTangents, std:

How to render depth linearly in modern OpenGL with gl_FragCoord.z in fragment shader?

和自甴很熟 提交于 2019-11-26 01:02:01
问题 I read lots of information about getting depth with fragment shader. such as http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234519 but I still don\'t know whether or not the gl_FragCoord.z is linear. GLSL specification said its range is [0,1] in screen sapce without mentioning it\'s linear or not. I think linearity it is vital since I will use the rendered model to match depth map from Kinect. Then if it is not linear, how to linearlize it in the world space? 回答1:

ray and ellipsoid intersection accuracy improvement

柔情痞子 提交于 2019-11-26 00:38:58
问题 I need to enhance precision for function in one of mine Atmospheric scattering GLSL fragment shader which computes the intersection between single ray and axis aligned ellipsoid. This is the core function for mine atmospheric scattering shader. The old original shader was on floats and for normal rendering was fine, but after addition of zoom I found that with relatively small distances the precision get lost. On floats the usable distances for Earth was only up to 0.005 AU (Astronomical Unit

Reflection and refraction impossible without recursive ray tracing?

一世执手 提交于 2019-11-25 23:19:01
问题 I am writing a GPU-based real-time raytracing renderer using a GLSL compute shader. So far, it works really well, but I have stumbled into a seemingly unsolvable problem when it comes to having both reflections and refractions simultaneously. My logic tells me that in order to have reflections and refractions on an object, such as glass, the ray would have to split into two, one ray reflects off the surface, and the other refracts through the surface. The ultimate colours of these rays would

Normal mapping gone horribly wrong

与世无争的帅哥 提交于 2019-11-25 22:54:17
I tried to implement normal mapping in my opengl application but I can't get it to work. This is the diffuse map (which I add a brown color to) and this is the normal map. In order to get the tangent and bitangent (in other places called binormals?) vectors, I run this function for every triangle in my mesh: void getTangent(const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec2 &uv0, const glm::vec2 &uv1, const glm::vec2 &uv2, std::vector<glm::vec3> &vTangents, std::vector<glm::vec3> &vBiangents) { // Edges of the triangle : postion delta glm::vec3 deltaPos1 = v1-v0;