glsles

Is it OK to use highp in fragment shaders for iOS/Android?

心已入冬 提交于 2021-01-29 04:01:06
问题 According to the GLSL ES reference, support for highp in fragment shaders is optional. So I have been using precision mediump float; in all my fragment shaders so I don't have device compatibility issues. In some cases it's quite difficult to produce good-looking output with only 10 bits of relative precision, and I would love to be able to switch to highp when necessary. How safe is it in practice to require highp support in a fragment shader? I've tried it on a variety of devices, and it

CPU to GPU normal mapping

大憨熊 提交于 2020-06-27 18:32:06
问题 I'm creating a terrain mesh, and following this SO answer I'm trying to migrate my CPU computed normals to a shader based version, in order to improve performances by reducing my mesh resolution and using a normal map computed in the fragment shader. I'm using MapBox height map for the terrain data. Tiles look like this: And elevation at each pixel is given by the following formula: const elevation = -10000.0 + ((red * 256.0 * 256.0 + green * 256.0 + blue) * 0.1); My original code first

Passing values between SCNShadable entry points

两盒软妹~` 提交于 2020-06-25 18:04:27
问题 In an OpenGL program you typical declare something like this in a vertex shader varying bool aBooleanVariable; and then read the value in the fragment shader. How do you do this within the framework of an SCNShadable entry point? For example from SCNShaderModifierEntryPointGeometry to SCNShaderModifierEntryPointFragment . Receiving the argument seems to be defined by using the pragma arguments, I provide my test SCNShaderModifierEntryPointFragment to illustrate. #pragma arguments bool

Workaround to use uniforms (or similar) in WebGL for loops?

北城以北 提交于 2020-04-11 08:30:11
问题 I'm working on implementing a fragment shader in WebGL, and came across the limitation of being able to only use constant expressions in for loops. Does anyone have any suitable workarounds for this? In my specific case, I'm implementing a bilateral filter, and currently have a window size specified as a const in my fragment shader, but would like to be able to change this from JavaScript. Uniforms aren't considered constants and thus can't be used in a for loop, so I'm looking for some other

Workaround to use uniforms (or similar) in WebGL for loops?

社会主义新天地 提交于 2020-04-11 08:30:10
问题 I'm working on implementing a fragment shader in WebGL, and came across the limitation of being able to only use constant expressions in for loops. Does anyone have any suitable workarounds for this? In my specific case, I'm implementing a bilateral filter, and currently have a window size specified as a const in my fragment shader, but would like to be able to change this from JavaScript. Uniforms aren't considered constants and thus can't be used in a for loop, so I'm looking for some other

OpenGLES 3.0 Shader Compile error on Android Device for in and out storage qualifiers

梦想的初衷 提交于 2020-03-23 07:34:12
问题 So I am updating my app to use OpenGLES 3.0 to take advantage of transform feedback, but the shader isn't compiling. error: 06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ Could not compile shader 35633: 06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ ERROR: 0:1: 'in' : Syntax error: syntax error INTERNAL ERROR: no main() function! ERROR: 1 compilation errors. No code generated. Here is the vertex shader code: private final

OpenGLES 3.0 Shader Compile error on Android Device for in and out storage qualifiers

心不动则不痛 提交于 2020-03-23 07:34:06
问题 So I am updating my app to use OpenGLES 3.0 to take advantage of transform feedback, but the shader isn't compiling. error: 06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ Could not compile shader 35633: 06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ ERROR: 0:1: 'in' : Syntax error: syntax error INTERNAL ERROR: no main() function! ERROR: 1 compilation errors. No code generated. Here is the vertex shader code: private final

OpenGL ES fragment shader apparently impossibly returning white

回眸只為那壹抹淺笑 提交于 2020-02-02 06:24:58
问题 This is a weird one. I have a fragment shader that as far as I can tell can only return black or red, but it's rendering the pixels in white. And if I remove one specific line, it returns the colour I'd expect. It works in WebGL, but not in OpenGL ES on the Raspberry Pi. Here's the shader code. It returns black if the pixel represents a point inside the Mandelbrot set, red otherwise. precision mediump float; varying vec2 vPosition; void main(void) { float cx = vPosition.x; float cy =

Render to 16bits unsigned integer 2D texture in WebGL2

99封情书 提交于 2020-01-25 04:36:05
问题 As stated in the WebGL 2 official specs or docs (look here), gl.RGBA16UI internal size format is a color-renderable format. That means I should be able to render to a RGBA16UI texture. I can easily fill a texture with an UInt16Array and then use it. But I fail filling a texture rendering into it with a shader. Then, I only get zeros when I sample the values in the next shader. Did anyone already succeed in rendering to an unsigned integer texture with WebGL 2 ? I would be very grateful, I'm

GLSL ES fragment shader produces very different results on different devices

删除回忆录丶 提交于 2020-01-14 18:45:53
问题 I am developing a game for Android using OpenGL ES 2.0 and have a problem with a fragment shader for drawing stars in the background. I've got the following code: precision mediump float; varying vec2 transformed_position; float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } void main(void) { float distance = 10.0; float quantization_strength = 4.0; vec3 background_color = vec3(0.09, 0.0, 0.288); vec2 zero = vec2(0.0, 0.0); vec2 distance_vec = vec2