I want to know the different methods in different formats YUV420 to RGB. Who can help me? ]]>

Basically; it's a full screen quad. Here's my heightmap:

https://i.stack.imgur.com/fIViN.png

Combined with a grass texture and I get:

https://i.stack.imgur.com/LBdzx.jpg

The actual shader is here:

Code :

#version 330
precision highp float;
layout(location=0) out vec4 frag_colour;
varying vec2 texelCoords;
uniform sampler2D uTexture;
uniform sampler2D uTextureHeightmap;
uniform float uSunDistance = -10000000.0;
uniform float uSunInclination - 0.15;
uniform float uSunAzimuth = 5.148;
uniform float uQuality = 1.0;
void main()
{
vec4 c = texture(uTexture,texelCoords);
vec2 textureD = textureSize(uTexture,0);
float d = max(textureD.x,textureD.y);
float aspectCorrection = textureD.x / textureD.y;
float minStepSize = 1.0f / d;
vec3 sunPosition = vec3(textureD.x/2.0f,textureD.y/2.0f,0) + vec3( uSunDistance*sin(uSunInclination)*cos(uSunAzimuth),
uSunDistance*sin(uSunInclination)*sin(uSunAzimuth),
uSunDistance*cos(uSunInclination) );
vec4 heights = texture(uTextureHeightmap, texelCoords);
float height = max(max(heights.r,heights.g),heights.b);
vec3 direction = normalize(vec3(texelCoords,height) - sunPosition);
direction.y *= aspectCorrection;
float samples = 100;//d*uQuality;
float maxDistance = (1.0f - height) * length(direction.xy) / abs(direction.z);
float stepSize = max(minStepSize, maxDistance / samples);
float shadow = 0.3f;
vec3 startPoint = vec3(texelCoords, height);
for(float sampleDistance = stepSize; sampleDistance <= maxDistance; sampleDistance += stepSize)
{
vec3 newPoint = startPoint + direction * sampleDistance;
vec4 h = texture(uTextureHeightmap,newPoint.xy);
float base = h.r;
float middle = h.g;
float top = h.b;
if(newPoint.z < base)
{
c *= shadow;
break;
}
if(newPoint.z >= middle && newPoint.z <= top)
{
c *= shadow;
break;
}
}
frag_colour = vec4(c.rgb,1.0);
//frag_colour = vec4(minStepSize,minStepSize,minStepSize,1.0);
}

I cannot figure out where the striation pattern is coming from. I thought it might be the "angle" of the sun, but even if I set it to just slightly off "directly above" is still has that pattern.

You can sort of ignore anything over the first channel in the heightmap; I'm using and checking multiple channels to allow overhangs and stuff. Even with just a single channel it still has the same result.

I'm sure it's not the step size, I've attempted to purposefully set this to be extremely low values.

Any help would be massively appreciated. ]]>

https://www.opengl.org/discussion_bo...Gather-problem

Which describes a problem with OpenGL and Direct3D where you are trying to implement a bilinear filter yourself. As I just hit this exact problem and found Menzel's post very useful I thought I'd add my solution which avoids the unpredictability of the strange offset.

We're trying to pull in 4 texels and then sum them with weights. If one uses gather to load the samples, then one can't exactly predict which samples will be loaded as the HW is doing integer maths and the shader is doing float maths.

So the trick is to force the Gather to pull in the texels you want. This is the modified version of the filter code Menzel put in his thread.

Code :

vec4 textureBilinear( in sampler2D tex, in vec2 coord, in float useOffset )
{
// Get texture size in pixels:
vec2 colorTextureSize = vec2(textureSize(tex, 0));
// Convert UV coordinates to pixel coordinates and get pixel index of top left pixel (assuming UVs are relative to top left corner of texture)
vec2 pixCoord = coord * colorTextureSize - 0.5f; // First pixel goes from -0.5 to +0.4999 (0.0 is center) last pixel goes from (size - 1.5) to (size - 0.5000001)
vec2 originPixCoord = floor(pixCoord); // Pixel index coordinates of bottom left pixel of set of 4 we will be blending
// For Gather we want UV coordinates of bottom right corner of top left pixel
vec2 gatherUV = ((originPixCoord + 1.0f) / colorTextureSize;
// Gather from all surounding texels:
vec4 red = textureGather(tex, gatherUV, 0);
vec4 green = textureGather(tex, gatherUV, 1);
vec4 blue = textureGather(tex, gatherUV, 2);
vec4 alpha = textureGather(tex, gatherUV, 3);
// Swizzle the gathered components to create four colours
vec4 c00 = vec4(red.w, green.w, blue.w, alpha.w);
vec4 c01 = vec4(red.x, green.x, blue.x, alpha.x);
vec4 c11 = vec4(red.y, green.y, blue.y, alpha.y);
vec4 c10 = vec4(red.z, green.z, blue.z, alpha.z);
// Filter weight is fract(coord * colorTextureSize - 0.5f) = (coord * colorTextureSize - 0.5f) - floor(coord * colorTextureSize - 0.5f)
vec2 filterWeight = pixCoord - originPixCoord;
// Bi-linear mixing:
vec4 temp0 = mix(c01, c11, filterWeight.x);
vec4 temp1 = mix(c00, c10, filterWeight.x);
return mix(temp1, temp0, filterWeight.y);
}

It's worth noting that we can avoid the Swizzle of the gathered components by using Sample, in which case we need to sample half a pixel different because we want the center of the specific texel. We should have point sampling enabled, but if bilinear is enabled it will still work.

Code :

// For Sample we want UV coordinates of center of top left pixel
vec2 sampleUV = ((originPixCoord + 0.5f) / colorTextureSize;
// Sample from all surounding texels
vec4 c00 = texture(tex, sampleUV);
vec4 c01 = textureOffset(tex, sampleUV, vec2(0,1));
vec4 c11 = textureOffset(tex, sampleUV, vec2(1,1));
vec4 c10 = textureOffset(tex, sampleUV, vec2(1,0));