vertex-shader

Implementing a 32-bit heightmap vertex shader in threejs

帅比萌擦擦* 提交于 2019-12-20 06:57:43
问题 I am attempting to repurpose the heightmap shader example found here into one that will work with 32-bits of precision instead of 8. The work-in-progress code is on github: https://github.com/bgourlie/three_heightmap The height map is being generated in .NET. The heights are within 0f...200f and converted into a 32-bit color value (Unity's Color struct) using the following method: private static Color DepthToColor(float height) { var depthBytes = BitConverter.GetBytes(height); int enc =

Implementing a 32-bit heightmap vertex shader in threejs

安稳与你 提交于 2019-12-20 06:52:30
问题 I am attempting to repurpose the heightmap shader example found here into one that will work with 32-bits of precision instead of 8. The work-in-progress code is on github: https://github.com/bgourlie/three_heightmap The height map is being generated in .NET. The heights are within 0f...200f and converted into a 32-bit color value (Unity's Color struct) using the following method: private static Color DepthToColor(float height) { var depthBytes = BitConverter.GetBytes(height); int enc =

billboarding vertices in the vertex shader

前提是你 提交于 2019-12-18 16:58:36
问题 Code demonstrating issue (comment/uncomment out the gl_Position lines in the vertex shader) var scene; var book; var shaderMaterial; var renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setClearColor(0x000000); document.body.appendChild(renderer.domElement); var camera = new THREE.PerspectiveCamera(55, 1, 0.1, 40000); window.onresize = function () { renderer.setSize(window.innerWidth, window.innerHeight); camera.aspect = window.innerWidth / window.innerHeight; camera

In OpenGL vertex shaders, what is w, and why do I divide by it?

雨燕双飞 提交于 2019-12-17 21:49:25
问题 void main(void) { vec4 clipCoord = glModelViewProjectionmatrix * gl_Vertex; gl_Position = clipCoord; gl_FrontColor = gl_Color; vec3 ndc = clipCoord.xyz / clipCoord.w; So the clipCoord is just doing standard fixed pipeline transforms. Why do I divide by w , and what do I get from this? 回答1: W is the fourth coordinate of a three dimensional vertex; This vertex is called homogeneous vertex coordinate. In few words, the W component is a factor which divides the other vector components. When W is

HLSL: Enforce Constant Register Limit at Compile Time

三世轮回 提交于 2019-12-17 21:17:42
问题 In HLSL, is there any way to limit the number of constant registers that the compiler uses? Specifically, if I have something like: float4 foobar[300]; In a vs_2_0 vertex shader, the compiler will merrily generate the effect with more than 256 constant registers. But a 2.0 vertex shader is only guaranteed to have access to 256 constant registers, so when I try to use the effect, it fails in an obscure and GPU-dependent way at runtime. I would much rather have it fail at compile time. This

Why is there the need for the index argument in glEnableVertexAttribArray? [duplicate]

断了今生、忘了曾经 提交于 2019-12-14 03:27:43
问题 This question already has answers here : What is the purpose of `glEnableVertexAttribArray(GLuint index)` in OpenGL? (2 answers) Closed 3 years ago . Using glVertexAttribPointer the opengl implementation already knows to which attribute location/index in vertex shader Vertex Attribute Object is bound, so why is there the need to provide attribute index in glEnableVertexAttribArray again? I think after using glBindVertexArray(VAO); it could have been enough to use just

Passing uniform 4x4 matrix to vertex shader program

眉间皱痕 提交于 2019-12-14 00:19:47
问题 I am trying to learn OpenGL and following this: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ Up until the point where they started passing matrices to the vertex shader to translate the triangle they where drawing I was following along. This is the shader program where it starts to go wrong: #version 330 core layout(location = 0) in vec3 vertexPosition_modelspace; uniform mat4 MVP; void main(){ vec4 v = vec4(vertexPosition_modelspace,1); // Transform an homogeneous

gradient multicolor metaballs with threejs and marchingcubes

一个人想着一个人 提交于 2019-12-13 04:04:44
问题 I am looking on how to implement something similar than this work: https://vimeo.com/9121195 . But with explicitly attributing colors to each metaball from an array of given colors. As far as I can see, this is done entirely from the shader side in this example but I was wondering if this could not be implemented with Threejs and marchingcubes. By creating a new THREE.ShaderMaterial I assume I can pass positions of each metaball to the shader and then evaluate the distance of each vertex with

Receive and cast shadows (custom GEOMETRY Grass Shader) - Unity C#

ぃ、小莉子 提交于 2019-12-13 03:19:27
问题 I was following a tutorial made by Sam Wronski aka. World of Zero (Tutorial by World of Zero) where he codes a geometry shader for a point cloud grass generator. Great tutorial but I am wondering (and didn't find a proper solution after days of research) how I could implement shadows to the shader (casting and receiving shadows). I am trying to dig deeper into shaders, but this is a level to high for me yet. My question is : how can I implement shadow casting and receiving for this grass

GLSL Shader - Coverflow Reflection of a 2D object

百般思念 提交于 2019-12-13 00:04:12
问题 I want to write a shader that creates a reflection of an image similiar to the ones used for coverflows. // Vertex Shader uniform highp mat4 u_modelViewMatrix; uniform highp mat4 u_projectionMatrix; attribute highp vec4 a_position; attribute lowp vec4 a_color; attribute highp vec2 a_texcoord; varying lowp vec4 v_color; varying highp vec2 v_texCoord; mat4 rot = mat4( -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); void main() { gl_Position = (u