vertex-shader

HLSL: Index to unaligned/packed floats

僤鯓⒐⒋嵵緔 提交于 2019-12-02 03:30:57
I have a vertex shader (2.0) doing some instancing - each vertex specifies an index into an array. If I have an array like this: float instanceData[100]; The compiler allocates it 100 constant registers. Each constant register is a float4 , so it's allocating 4 times as much space as is needed. I need a way to make it allocate just 25 constant registers and store four values in each of them. Ideally I'd like a method where it still looks like a float[] on both the CPU and GPU (Right now I am calling EffectParamter.SetValue(Single[]) , I'm using XNA). But manually packing and unpacking a float4

DirectX 11 Pixel Shader What Is SV_POSITION?

痞子三分冷 提交于 2019-12-01 22:24:38
问题 I am learning HLSL for DirectX 11, and I was wondering what exactly is the SV_POSITION that is the output for a Vertex Shader, and the input for a Pixel Shader. 1: Is this x,y,z of every pixel on your screen, or of the object? 2: Why is it 4 32bit floats? 3: Do you need this System Variable for the vertex output? Thank you! 回答1: The vertex shader stage only has one required output: the position of the vertex. This value is then used by the fixed-function rasterizer to compute which pixels are

DirectX 11 Pixel Shader What Is SV_POSITION?

扶醉桌前 提交于 2019-12-01 20:53:52
I am learning HLSL for DirectX 11, and I was wondering what exactly is the SV_POSITION that is the output for a Vertex Shader, and the input for a Pixel Shader. 1: Is this x,y,z of every pixel on your screen, or of the object? 2: Why is it 4 32bit floats? 3: Do you need this System Variable for the vertex output? Thank you! The vertex shader stage only has one required output: the position of the vertex. This value is then used by the fixed-function rasterizer to compute which pixels are being drawn and invoke the pixel shader for each one. That's what the system value semantic SV_Position

vertex shader doesn't run on galaxy tab10 (tegra 2)

不羁的心 提交于 2019-12-01 11:22:19
I created an app that uses GLES2.0 on a HTC Desire S. It works on the HTC, but not on an Samung Galaxy tab10.1. The program cannot be linked (GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linOk,0) gives-1) and glGetError() gives me an error 1282 (Invalid Operation). When I replace this line (in the shader): graph_coord.z = (texture2D(mytexture, graph_coord.xy / 2.0 + 0.5).r); by graph_coord.z = 0.2; it works also on the galaxy tab. My shader looks like this: private final String vertexShaderCode = "attribute vec2 coord2d;" + "varying vec4 graph_coord;" + "uniform mat4 texture

vertex shader doesn't run on galaxy tab10 (tegra 2)

不羁的心 提交于 2019-12-01 08:57:39
问题 I created an app that uses GLES2.0 on a HTC Desire S. It works on the HTC, but not on an Samung Galaxy tab10.1. The program cannot be linked (GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linOk,0) gives-1) and glGetError() gives me an error 1282 (Invalid Operation). When I replace this line (in the shader): graph_coord.z = (texture2D(mytexture, graph_coord.xy / 2.0 + 0.5).r); by graph_coord.z = 0.2; it works also on the galaxy tab. My shader looks like this: private final String

How vertex and fragment shaders communicate in OpenGL?

人盡茶涼 提交于 2019-12-01 08:54:46
问题 I really do not understand how fragment shader works. I know that vertex shader runs once per vertices fragment shader runs once per fragment Since fragment shader does not work per vertex but per fragment how can it send data to the fragment shader? The amount of vertices and amount of fragments are not equal. How can it decide which fragment belong to which vertex? 回答1: To make sense of this, you'll need to consider the whole render pipeline. The outputs of the vertex shader (besides the

Why isn't this orthographic vertex shader producing the correct answer?

半世苍凉 提交于 2019-12-01 05:23:59
问题 My issue is that I have a (working) orthographic vertex and fragment shader pair that allow me to specify center X and Y of a sprite via 'translateX' and 'translateY' uniforms being passed in. I multiply by a projectionMatrix that is hardcoded and works great. Everything works as far as orthographic operation. My incoming geometry to this shader is based around 0, 0, 0 as its center point. I want to now figure out what that center point (0, 0, 0 in local coordinate space) becomes after the

billboarding vertices in the vertex shader

笑着哭i 提交于 2019-11-30 15:07:11
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.updateProjectionMatrix(); }; window.onresize(); scene = new THREE.Scene(); camera.position.z = 25; camera

What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

扶醉桌前 提交于 2019-11-30 06:45:40
I have pass-through vertex and fragment shaders. vertex shader void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } fragment shader void main(void) { gl_FragColor = gl_Color; } Those produce empty rendering (black not background color like glClearBuffer does). If I modify the vertex shader to set the gl_FrontColor to gl_Color it does render untouched OpenGl buffer ... with is the expected behavior of pass-through shaders. void main(void) { gl_FrontColor = gl_Color; //Added line gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl

Can you tell if a vertex attribute is enabled from within a vertex shader?

江枫思渺然 提交于 2019-11-29 14:05:56
I was wondering if there was a way to tell if a vertex attribute is enabled from within a vertex shader? I know that if the vertex attribute is disabled all the values will be treated as 0.0, so I could do a test like the following: if (attribute == 0) { // Do something different to normal. } else { // Use the attribute. } But this has the obvious problem for the case that the attribute is enabled and the value is just set to 0 (it will be treated as if it's disabled)! The other solution would be to just use a uniform variable that states whether or not to use the attribute, but I wondered if