shader

HLSL branch avoidance

倾然丶 夕夏残阳落幕 提交于 2020-01-01 09:39:09
问题 I have a shader where I want to move half of the vertices in the vertex shader. I'm trying to decide the best way to do this from a performance standpoint, because we're dealing with well over 100,000 verts, so speed is critical. I've looked at 3 different methods: (pseudo-code, but enough to give you the idea. The <complex formula> I can't give out, but I can say that it involves a sin() function, as well as a function call (just returns a number, but still a function call), as well as a

“flat” qualifier in glsl?

主宰稳场 提交于 2020-01-01 02:40:16
问题 So I was reading "The Official OpenGL Guide" and in a section where they taught material lighting, they suddenly used the "flat" qualifier for an input variable in the fragment shader. I google'd the matter and all I came up with was "flat shading" and "smooth shading" and the differences between them, which I cannot understand how it is related to a simple "MatIndex" variable. here's the example code from the book: struct MaterialProperties { vec3 emission; vec3 ambient; vec3 diffuse; vec3

Creating blur filter with a shader - access adjacent pixels from fragment shader?

て烟熏妆下的殇ゞ 提交于 2019-12-31 22:39:46
问题 I want to create a blur effect using a fragment shader in OpenGL ES 2.0. The algorithm I am interested in is simply an averaging blur - add all adjacent pixels to myself and divide by 9 to normalize. However I have 2 issues: 1) does this require me to first render to a framebuffer, then switch rendering targets? Or is there an easier way 2) assume I bind my "source" image to blur as texture 0, and I'm outputting my blurred texture. How do I access the pixels that aren't the one I'm current

Draw a dashed and dotted bezier curve in QML

时光毁灭记忆、已成空白 提交于 2019-12-31 20:15:29
问题 I've seen there is an example implementation of a Bezier curve in QML, but I'm looking for a hint how to implement dashed or dotted bezier curve line. As far as I see, tha authors of Bezier curve example are using QSGGeometryNode to store inside QSGGeometry with a QSGFlatColorMaterial material applied on it. Then they simply create list of points and draw segments between them. Is it possible to write a shader and apply it to QSGFlatColorMaterial (to display line as dashed , dotted , etc)?

OpenGL / GLSL - Uniform block data values incorrect

五迷三道 提交于 2019-12-31 04:17:10
问题 My shader has a uniform block as such: layout (std140) uniform LightSourceBlock { vec3 test; vec3 color; } LightSources; The data for this block is supposed to come from a buffer object which is created like so: GLuint buffer; glGenBuffers(1,&buffer); GLfloat data[6] = { 0,0,0, 0,0,1 }; glBindBuffer(GL_UNIFORM_BUFFER,buffer); glBufferData(GL_UNIFORM_BUFFER,sizeof(data),&data[0],GL_DYNAMIC_DRAW); The buffer is linked to the uniform block before rendering: unsigned int locLightSourceBlock =

Regarding arrays in layout std140 uniform block for OpenGL

旧巷老猫 提交于 2019-12-31 00:44:08
问题 According to specification: If the member is an array of scalars or vectors, the base alignment + * and array stride are set to match the base alignment of a single + * array element, according to rules (1), (2), and (3), and rounded up + * to the base alignment of a vec4. The array may have padding at the + * end; the base offset of the member following the array is rounded up + * to the next multiple of the base alignment. Does this mean that if I had an array of size 3 of a (float)vec3,

Performance of different CG/GLSL/HLSL functions

不羁岁月 提交于 2019-12-30 17:58:13
问题 There are standard libraries of shader functions, such as for Cg. But are there resources which tell you how long each takes... I'm thinking similar to how you used to be able to look up how many cycles each ASM op would take. 回答1: There are no reliable resources that will tell you how long various standard shader functions take. Not even for a particular piece of hardware. The reason for this has to do with instruction scheduling and the way modern shader architectures work. Take a simple

FXC : error X3501: 'main': entrypoint not found

孤者浪人 提交于 2019-12-30 04:20:06
问题 I am following an example book called: Introduction to 3D Game Programming with DirectX 11 It is all written in VS2010. I would like to try using VS2013... It is an example project for Windows Desktop Program I have a program with the following in it (including some other files as part of common use): color.fx //*************************************************************************************** // color.fx by Frank Luna (C) 2011 All Rights Reserved. // // Transforms and colors geometry. /

glsl refraction getting mapped upside down

一个人想着一个人 提交于 2019-12-30 03:21:05
问题 I am implementing refraction in glsl. I am using the refract function provided in frag shader to get the desired effect. But the refraction I am getting, its upside down. I think this is wrong.. any idea why is it so? This is what I do in vertex shader: vec3 worldView = normalize(vec3(WorldCameraPosition-worldPos)); refractor = refract(-worldView, worldNorm, Eta); // eta = 0.66; and then frag shader I do: vec4 refractColor = textureCube(cubeMap, refractor); http://www.cse.ohio-state.edu/

How do I calculate pixel shader depth to render a circle drawn on a point sprite as a sphere that will intersect with other objects?

让人想犯罪 __ 提交于 2019-12-29 21:06:27
问题 I am writing a shader to render spheres on point sprites, by drawing shaded circles, and need to write a depth component as well as colour in order that spheres near each other will intersect correctly. I am using code similar to that written by Johna Holwerda: void PS_ShowDepth(VS_OUTPUT input, out float4 color: COLOR0,out float depth : DEPTH) { float dist = length (input.uv - float2 (0.5f, 0.5f)); //get the distance form the center of the point-sprite float alpha = saturate(sign (0.5f -