vertex-shader

Three.js - shader code for halo effect, normals need transformation

安稳与你 提交于 2019-12-05 00:02:47
问题 I am attempting to create a shader to produce a glowing halo effect in Three.js. My current attempt is live here: http://stemkoski.github.io/Three.js/Shader-Halo.html The shader code is currently: <script id="vertexShader" type="x-shader/x-vertex"> varying vec3 vNormal; void main() { vNormal = normalize( normalMatrix * normal ); gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); } </script> <script id="fragmentShader" type="x-shader/x-vertex"> varying vec3 vNormal; void

Rotate Normals in Shader

爷,独闯天下 提交于 2019-12-04 08:13:03
I have a scene with several models with individual positions and rotations. Given normals, the shaders apply simple bidirectional lighting to each pixel. That is my vertex shader. #version 150 in vec3 position; in vec3 normal; in vec2 texcoord; out vec3 f_normal; out vec2 f_texcoord; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { mat4 mvp = proj * view * model; f_normal = normal; f_texcoord = texcoord; gl_Position = mvp * vec4(position, 1.0); } And here is the fragment shader. #version 150 in vec3 f_normal; in vec2 f_texcoord; uniform sampler2D tex; vec3 sun = vec3(0.5

How can I feed compute shader results into vertex shader w/o using a vertex buffer?

半腔热情 提交于 2019-12-03 17:14:21
Before I go into details I want outline the problem: I use RWStructuredBuffers to store the output of my compute shaders (CS). Since vertex and pixel shaders can’t read from RWStructuredBuffers, I map a StructuredBuffer onto the same slot (u0/t0) and (u4/t4): cbuffer cbWorld : register (b1) { float4x4 worldViewProj; int dummy; } struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; RWStructuredBuffer<float4> colorOutputTable : register (u0); // 2D color data StructuredBuffer<float4> output2 : register (t0); // same as u0

Are there DirectX guidelines for binding and unbinding resources between draw calls?

蓝咒 提交于 2019-12-03 16:19:23
All DirectX books and tutorials strongly recommend reducing resource allocations between draw calls to a minimum – yet I can’t find any guidelines that get more into details. Reviewing a lot of sample code found in the web, I have concluded that programmers have completely different coding principles regarding this subject. Some even set and unset VS/PS VS/PS ResourceViews RasterizerStage DepthStencilState PrimitiveTopology ... before and after every draw call (although the setup remains unchanged), and others don’t. I guess that's a bit overdone... From my own experiments I have found that

Apply color gradient to material on mesh - three.js

亡梦爱人 提交于 2019-12-03 06:24:07
I have an STL file loaded into my scene with a single colour applied to a phong material I'd like a way of applying two colours to this mesh's material with a gradient effect applied on the Z axis a like the example below. Gradient Vase ] 1 I have a feeling I may have to introduce shaders but I've not gotten this far with three.js. Simple gradient shader, based on uvs: var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000); camera.position.set(13, 25, 38); camera.lookAt(scene.position); var renderer = new THREE.WebGLRenderer({ antialias: true }); var canvas =

Is it important to call glDisableVertexAttribArray()?

强颜欢笑 提交于 2019-12-03 04:04:25
问题 I'm not entirely clear on the scope of enabling vertex attrib arrays. I've got several different shader programs with differing numbers of vertex attributes. Are glEnableVertexAttribArray calls local to a shader program, or global? Right now I'm enabling vertex attrib arrays when I create the shader program, and never disabling them, and all seems to work, but it seems like I'm possibly supposed to enable/disable them right before/after draw calls. Is there an impact to this? (I'm in WebGL,

Is it important to call glDisableVertexAttribArray()?

寵の児 提交于 2019-12-02 17:23:47
I'm not entirely clear on the scope of enabling vertex attrib arrays. I've got several different shader programs with differing numbers of vertex attributes. Are glEnableVertexAttribArray calls local to a shader program, or global? Right now I'm enabling vertex attrib arrays when I create the shader program, and never disabling them, and all seems to work, but it seems like I'm possibly supposed to enable/disable them right before/after draw calls. Is there an impact to this? (I'm in WebGL, as it happens, so we're really talking about gl.enableVertexAttribArray and gl.disableVertexAttribArray

HLSL: Index to unaligned/packed floats

心已入冬 提交于 2019-12-02 10:49:35
问题 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

Can't draw triangle using Opengl

跟風遠走 提交于 2019-12-02 10:15:04
in this code i want to draw a simple triangle on a blue background using openGL however when i compile and run the code only a window with the blue background appears (without the white triangle that is supposed to be drawn), iam using Xcode my code #include <iostream> #include <string> #include <GLUT/glut.h> #include <OpenGL/gl3.h> #include <fstream> using namespace std; // VAO & VBO objects GLuint VBO; GLuint VAO; void display(); // vertex Data (position) float vertex[] = {-1.0, 0.0 , 1.0, 0.0, 1.0 , 0.0, 0.0, 0.0 , 0.0 }; GLuint Program; GLuint Vshader; GLuint Fshader; // main program int

How to draw a star in iOS OpenGL ES 2.0

怎甘沉沦 提交于 2019-12-02 08:14:17
This question has been asked before but the quite a few years ago in my searches. The answer was always to use texture mapping but what I really want to do is represent the star as a single vertex - you may think I'm copping out with a simplistic method but in fact, a single point source of light actually looks pretty good and realistic. But I want to process that point of light with something like a gaussian blur too give it a little more body when zooming in or for brighter stars. I was going to texture map a gaussian blur image but if I understand things correctly I would then have to draw