shader

Passing own struct into opengl es 2.0 shader

跟風遠走 提交于 2019-12-05 17:26:19
问题 I want to try a lighting example from the book OpenGL ES 2.0 Programming Guide. In the shader they have made two structures. struct directional_light { vec3 direction; // normalized light direction in eye space vec3 halfplane; // normalized half-plane vector vec4 ambient_color; vec4 diffuse_color; vec4 specular_color; }; struct material_properties { vec4 ambient_color; vec4 diffuse_color; vec4 specular_color; float specular_exponent; }; They have also made two uniforms, based on these

How to define an array of floats in Shader properties?

五迷三道 提交于 2019-12-05 16:43:11
I'd like to define an array of floats in my shader, something like this: Properties { _TilesX ("Tiles X", Int) = 10 _TilesY ("Tiles Y", Int) = 10 _TileData1 ("Tile data", Float[]) = {} // THIS!!! _Texture1 ("Texture odd", 2D) = "white" {} _Texture2 ("Texture even", 2D) = "white" {} } I'm trying to create a single plane that I'll use as a grid and I want to modify the _TileData1 at run-time to change the Y offset of a tile. I'm using _TilesX and _TilesY to get a 2d position of the tile from a 1d array. Just to be clear, I just want to find out how to define a property type of float[] since I

Some simple XNA/HLSL questions

岁酱吖の 提交于 2019-12-05 16:10:15
问题 I've been getting into HLSL programming lately and I'm very curious as to HOW some of the things I'm doing actually work. For example, I've got this very simple shader here that shades any teal colored pixels to a red-ish color. sampler2D mySampler; float4 MyPixelShader(float2 texCoords : TEXCOORD0): COLOR { float4 Color; Color = tex2D(mySampler, texCoords.xy); if(Color.r == 0 && Color.g == 1.0 && Color.b == 1.0) { Color.r = 1.0; Color.g = 0.5; Color.b = 0.5; } return Color; } technique

Three.js using WebRTC and applying a Shader

强颜欢笑 提交于 2019-12-05 15:12:55
I can't figure out how to apply a shader to a three.js object that has a video texture. I've been playing around with webRTC and three.js and successfully mapped a video texture onto a mesh using a standard material: var material = new THREE.MeshBasicMaterial({ color : 0xffffff, map : videoTexture }); I want to take it one step further by applying a shader (for this example a sobel shader) to this texture. My attempt is here: http://jsfiddle.net/xkpsE/1/ I'm receiving a bunch of INVALID_OPERATION warnings, but am having trouble understanding how to debug the issue. I also haven't seen anyone

OpenGL - Fixed pipeline shader defaults (Mimic fixed pipeline with shaders)

不羁的心 提交于 2019-12-05 14:34:35
Can anyone provide me the shader that are similar to the Fixed function Pipeline? I need the Fragment shader default the most, because I found a similar vertex shader online. But if you have a pair that should be fine! I want to use fixed pipeline, but have the flexability of shaders, so I need similar shaders so I'll be able to mimic the functionality of the fixed pipeline. Thank you very much! I'm new here so if you need more information tell me:D This is what I would like to replicate: (texture unit 0) functionality of glTranslatef functionality of glColor4f functionality of glTexCoord2f

Vertex shader with array inputs

倾然丶 夕夏残阳落幕 提交于 2019-12-05 13:40:06
Given a vertex shader that looks something like #version 400 compatibility const int max_valence = 6; in int valence; in vec3 patch_data[1 + 2 * max_valence]; ... What is the the proper way to map the data to the correct vertex attribs? I'm trying to use a VBO, but I can't figure out how to pass that large of a value in. glVertexAttribPointer takes at most a vector of size 4. What's the correct way to get the vertex attributes into the shader? Arrays of vertex attributes are legal in OpenGL. However, each member of the array takes up a separate attribute index. They are allocated contiguously,

Passing custom type (struct) uniform from Qt to GLSL using QGLShaderProgram

筅森魡賤 提交于 2019-12-05 12:26:49
I defined a struct for light parameters which contains two vectors. The struct is defined in both C++ and GLSL in an analogous way (note: QVector3D encapsulates 3 float s, not double s): C++ host program: struct LightParameters { QVector3D pos; QVector3D intensity; }; Fragment Shader: struct LightParameters { vec3 pos; vec3 intensity; }; In the fragment shader, I also define the following uniforms. The numbers of lights is limited to 8, so the uniform array has a constant size (but only numLights are actually used): const int maxLights = 8; uniform int numLights; uniform LightParameters lights

Metal emulate geometry shaders using compute shaders

扶醉桌前 提交于 2019-12-05 11:45:46
I'm trying to implement voxel cone tracing in Metal. One of the steps in the algorithm is to voxelize the geometry using a geometry shader. Metal does not have geometry shaders so I was looking into emulating them using a compute shader. I pass in my vertex buffer into the compute shader, do what a geometry shader would normally do, and write the result to an output buffer. I also add a draw command to an indirect buffer. I use the output buffer as the vertex buffer for my vertex shader. This works fine, but I need twice as much memory for my vertices, one for the vertex buffer and one for the

Fast, inaccurate sin function without lookup

时光毁灭记忆、已成空白 提交于 2019-12-05 11:34:39
For an ocean shader, I need a fast function that computes a very approximate value for sin(x). The only requirements are that it is periodic, and roughly resembles a sine wave. The taylor series of sin is too slow, since I'd need to compute up to the 9th power of x just to get a full period. Any suggestions? EDIT: Sorry I didn't mention, I can't use a lookup table since this is on the vertex shader. A lookup table would involve a texture sample, which on the vertex shader is slower than the built in sin function. It doesn't have to be in any way accurate, it just has to look nice. Use a

SceneKit pass uniform vector to shader modifiers

情到浓时终转凉″ 提交于 2019-12-05 10:02:46
I'm trying to pass a GLKVector4 to a shader that should receive it as a vec4 . I'm using a fragment shader modifier: material.shaderModifiers = [ SCNShaderModifierEntryPoint.fragment: shaderModifier ] where shaderModifier is: // color changes uniform float colorModifier; uniform vec4 colorOffset; vec4 color = _output.color; color = color + colorOffset; color = color + vec4(0.0, colorModifier, 0.0, 0.0); _output.color = color; (I'm simply adding a color offset) I've tried: material.setValue(GLKVector4(v: (250.0, 0.0, 0.0, 0.0)), "colorOffset") which doesn't work (no offset is added and the