linear shaders modified
This commit is contained in:
parent
0d49820cad
commit
4ca794f7db
@ -347,15 +347,15 @@ namespace
|
||||
QTransform transform( rect.width(), 0, 0, rect.height(), rect.x(), rect.y());
|
||||
#endif
|
||||
|
||||
const QVector4D gradientRect(
|
||||
const QVector4D vector(
|
||||
rect.left() + gradient.start().x() * rect.width(),
|
||||
rect.top() + gradient.start().y() * rect.height(),
|
||||
gradient.finalStop().x() * rect.width(),
|
||||
gradient.finalStop().y() * rect.height() );
|
||||
|
||||
if ( m_gradientRect != gradientRect )
|
||||
if ( m_gradientVector != vector )
|
||||
{
|
||||
m_gradientRect = gradientRect;
|
||||
m_gradientVector = vector;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@ -372,7 +372,7 @@ namespace
|
||||
{
|
||||
const auto mat = static_cast< const LinearMaterial* >( other );
|
||||
|
||||
if ( m_gradientRect != mat->m_gradientRect )
|
||||
if ( m_gradientVector != mat->m_gradientVector )
|
||||
return QSGMaterial::compare( other );
|
||||
else
|
||||
return GradientMaterial::compare( other );
|
||||
@ -380,7 +380,11 @@ namespace
|
||||
|
||||
QSGMaterialShader* createShader() const override;
|
||||
|
||||
QVector4D m_gradientRect;
|
||||
/*
|
||||
xy: position
|
||||
zw: relative to position ( sign matters )
|
||||
*/
|
||||
QVector4D m_gradientVector;
|
||||
};
|
||||
|
||||
#ifdef SHADER_GL
|
||||
@ -395,17 +399,17 @@ namespace
|
||||
void initialize() override
|
||||
{
|
||||
GradientShaderGL::initialize();
|
||||
m_rectId = program()->uniformLocation( "rect" );
|
||||
m_vectorId = program()->uniformLocation( "vector" );
|
||||
}
|
||||
|
||||
void updateUniformValues( const GradientMaterial* newMaterial ) override
|
||||
{
|
||||
auto material = static_cast< const LinearMaterial* >( newMaterial );
|
||||
program()->setUniformValue( m_rectId, material->m_gradientRect );
|
||||
program()->setUniformValue( m_vectorId, material->m_gradientVector );
|
||||
}
|
||||
|
||||
private:
|
||||
int m_rectId = -1;
|
||||
int m_vectorId = -1;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -437,9 +441,9 @@ namespace
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if ( matOld == nullptr || matNew->m_gradientRect != matOld->m_gradientRect )
|
||||
if ( matOld == nullptr || matNew->m_gradientVector != matOld->m_gradientVector )
|
||||
{
|
||||
memcpy( data + 64, &matNew->m_gradientRect, 16 );
|
||||
memcpy( data + 64, &matNew->m_gradientVector, 16 );
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@ layout( location = 0 ) out vec4 fragColor;
|
||||
layout( std140, binding = 0 ) uniform buf
|
||||
{
|
||||
mat4 matrix;
|
||||
vec4 rect;
|
||||
vec4 vector;
|
||||
float opacity;
|
||||
} ubuf;
|
||||
|
||||
|
@ -6,7 +6,7 @@ layout( location = 0 ) out float colorIndex;
|
||||
layout( std140, binding = 0 ) uniform buf
|
||||
{
|
||||
mat4 matrix;
|
||||
vec4 rect;
|
||||
vec4 vector;
|
||||
float opacity;
|
||||
} ubuf;
|
||||
|
||||
@ -14,9 +14,9 @@ out gl_PerVertex { vec4 gl_Position; };
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 l = vertexCoord.xy - ubuf.rect.xy;
|
||||
vec2 size = ubuf.rect.zw;
|
||||
vec2 pos = vertexCoord.xy - ubuf.vector.xy;
|
||||
vec2 span = ubuf.vector.zw;
|
||||
|
||||
colorIndex = dot( l, size ) / dot( size, size );
|
||||
colorIndex = dot( pos, span ) / dot( span, span );
|
||||
gl_Position = ubuf.matrix * vertexCoord;
|
||||
}
|
||||
|
Binary file not shown.
@ -1,15 +1,15 @@
|
||||
attribute vec4 vertexCoord;
|
||||
|
||||
uniform mat4 matrix;
|
||||
uniform vec4 rect;
|
||||
uniform vec4 vector;
|
||||
|
||||
varying float colorIndex;
|
||||
|
||||
void main()
|
||||
{
|
||||
highp vec2 l = vertexCoord.xy - rect.xy;
|
||||
highp vec2 size = rect.zw;
|
||||
highp vec2 pos = vertexCoord.xy - vector.xy;
|
||||
highp vec2 span = vector.zw;
|
||||
|
||||
colorIndex = dot( l, size ) / dot( size, size );
|
||||
colorIndex = dot( pos, span ) / dot( span, span );
|
||||
gl_Position = matrix * vertexCoord;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user