Im計算片段着色器中一個點周圍的圓。問題是紋理的變化部分不是圓,它是一個橢圓。形式實際上取決於紋理的形式。如果紋理是一個完美的正方形,我會得到一個完美的圓形,但當它的矩形我得到一個橢圓形。這是當前片段着色器:如何計算圍繞opengl中一個點的圓(紋素)
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform highp vec2 center;
uniform highp float radius;
uniform highp float scale;
void main()
{
highp vec2 textureCoordinateToUse = textureCoordinate;
highp float dist = distance(center, textureCoordinate);
textureCoordinateToUse -= center;
if (dist < radius)
{
highp float percent = 1.0 - ((radius - dist)/radius) * scale;
percent = percent * percent;
textureCoordinateToUse = textureCoordinateToUse * percent;
textureCoordinateToUse += center;
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse);
}
textureCoordinateToUse += center;
gl_FragColor = texture2D(inputImageTexture,textureCoordinate);
}
UPDATE shader代碼:
highp float aspectRatio = 854.0/480.0;
//highp vec2 textureCoordinateToUse = textureCoordinate;
highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float dist = distance(center, textureCoordinateToUse);
textureCoordinateToUse -= center;
if (dist < radius)
{
highp float percent = 1.0 - ((radius - dist)/radius) * scale;
percent = percent * percent;
textureCoordinateToUse = textureCoordinateToUse * percent;
textureCoordinateToUse += center;
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse);
return;
}
textureCoordinateToUse += center;
gl_FragColor = texture2D(inputImageTexture,textureCoordinate);
而你的問題是? – Alexander
你可以在你的代碼中加入一些註釋嗎?什麼是比例和百分比= 1.0 - ((半徑 - 距離)/半徑)*比例;應該代表? –
問題是如何得到一個圓圈而不是橢圓。比例是1.百分比影響圓/橢圓的內容,但不是它的形式,所以不要注意它 – Sol