Skip to content

Commit

Permalink
[NUI] Fix several custom shader could be works at Vulkan backend
Browse files Browse the repository at this point in the history
Let we change custom shader codes as unified-dali-style shader codes.

Signed-off-by: Eunki Hong <[email protected]>
  • Loading branch information
Eunki Hong committed Feb 3, 2025
1 parent 195af2d commit fe2abe0
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 62 deletions.
29 changes: 21 additions & 8 deletions src/Tizen.NUI.Wearable/src/public/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,34 @@ namespace Tizen.NUI.Components
public class Title : TextLabel
{
private const string VERTEX_SHADER =
"attribute mediump vec2 aPosition;\n" +
"varying mediump vec2 vTexCoord;\n" +
"uniform highp mat4 uMvpMatrix;\n" +
"uniform mediump vec3 uSize;\n" +
"varying mediump vec2 sTexCoordRect;\n" +
"//@name NUI.Component.Tile.vert\n" +
"\n" +
"//@version 100\n" +
"\n" +
"INPUT mediump vec2 aPosition;\n" +
"OUTPUT mediump vec2 vTexCoord;\n" +
"UNIFORM_BLOCK VertBlock\n" +
"{\n" +
" UNIFORM highp mat4 uMvpMatrix;\n" +
" UNIFORM mediump vec3 uSize;\n" +
"};\n" +
"void main()\n" +
"{\n" +
" gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n" +
" vTexCoord = aPosition + vec2(0.5);\n" +
"}\n";

private const string FRAGMENT_SHADER =
"uniform lowp vec4 uColor;\n" +
"varying mediump vec2 vTexCoord;\n" +
"uniform sampler2D sTexture;\n" +
"//@name NUI.Component.Tile.frag\n" +
"\n" +
"//@version 100\n" +
"\n" +
"INPUT mediump vec2 vTexCoord;\n" +
"UNIFORM sampler2D sTexture;\n" +
"UNIFORM_BLOCK FragBlock\n" +
"{\n" +
" UNIFORM lowp vec4 uColor;\n" +
"};\n" +
"void main()\n" +
"{\n" +
" gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;\n" +
Expand Down
7 changes: 4 additions & 3 deletions src/Tizen.NUI/src/internal/FrameBroker/FrameBrokerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ private void OnUpdateNative(IntPtr context, IntPtr frame, IntPtr userData)

private Shader CreateShader()
{
string vertex_shader =
// TODO : How can we support native texture for vulkan case?
string vertexShader =
"attribute mediump vec2 aPosition;\n" +
"varying mediump vec2 vTexCoord;\n" +
"uniform highp mat4 uMvpMatrix;\n" +
Expand All @@ -262,7 +263,7 @@ private Shader CreateShader()
"vTexCoord = aPosition + vec2(0.5);\n" +
"}\n";

string fragment_shader =
string fragmentShader =
"#extension GL_OES_EGL_image_external:require\n" +
"uniform lowp vec4 uColor;\n" +
"varying mediump vec2 vTexCoord;\n" +
Expand All @@ -272,7 +273,7 @@ private Shader CreateShader()
"gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;\n" +
"}\n";

return new Shader(vertex_shader, fragment_shader);
return new Shader(vertexShader, fragmentShader);
}

[StructLayout(LayoutKind.Sequential)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,32 @@ public class ClippedImage
static Geometry geometry = null;

private static readonly string VERTEX_SHADER =
"attribute vec2 aPositionCircle;\n" +
"attribute vec2 aPositionQuad;\n" +
"uniform float uDelta;\n" +
"uniform mat4 uMvpMatrix;\n" +
"uniform vec3 uSize;\n" +
"\n" +
"void main()\n" +
"{\n" +
" vec4 vertexPosition = vec4(mix(aPositionCircle, aPositionQuad, uDelta), 0.0, 1.0);\n" +
" vertexPosition.xyz *= uSize;\n" +
" gl_Position = uMvpMatrix * vertexPosition;\n" +
"}\n";
"//@name ClippedImage.vert\n" +
"\n" +
"//@version 100\n" +
"\n" +
"INPUT highp vec2 aPositionCircle;\n" +
"INPUT highp vec2 aPositionQuad;\n" +
"\n" +
"UNIFORM_BLOCK VertBlock\n" +
"{\n" +
" UNIFORM highp mat4 uMvpMatrix;\n" +
" UNIFORM highp vec3 uSize;\n" +
" UNIFORM highp float uDelta;\n" +
"};\n" +
"\n" +
"void main()\n" +
"{\n" +
" vec4 vertexPosition = vec4(mix(aPositionCircle, aPositionQuad, uDelta), 0.0, 1.0);\n" +
" vertexPosition.xyz *= uSize;\n" +
" gl_Position = uMvpMatrix * vertexPosition;\n" +
"}\n";

private static readonly string FRAGMENT_SHADER =
"//@name ClippedImage.frag\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n" +
"void main()\n" +
"{\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ namespace Tizen.NUI.Samples
{
public class CircularText : IExample
{
private string VERSION_3_ES = "#version 300 es\n";

private static readonly string VERTEX_SHADER =
"//@name CircularText.vert\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n"+
"in vec2 aPosition;\n"+
"in vec2 aTexCoord;\n"+
"out vec2 vUV;\n"+
"uniform vec3 uSize;\n"+
"uniform mat4 uMvpMatrix;\n"+
"INPUT vec2 aPosition;\n"+
"INPUT vec2 aTexCoord;\n"+
"OUTPUT vec2 vUV;\n"+
"UNIFORM_BLOCK VertBlock\n" +
"{\n" +
" UNIFORM vec3 uSize;\n"+
" UNIFORM mat4 uMvpMatrix;\n"+
"};\n" +
"void main()\n"+
"{\n"+
" vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"+
Expand All @@ -28,15 +33,23 @@ public class CircularText : IExample
"}\n";

private static readonly string FRAGMENT_SHADER =
"//@name CircularText.frag\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n"+
"in vec2 vUV;\n"+
"out vec4 FragColor;\n"+
"uniform sampler2D sAlbedo;\n"+
"uniform vec4 uColor;\n"+
"INPUT vec2 vUV;\n"+
//"OUTPUT vec4 FragColor;\n"+
"UNIFORM sampler2D sAlbedo;\n"+
"UNIFORM_BLOCK FragBlock\n" +
"{\n" +
" UNIFORM vec4 uColor;\n"+
"};\n" +
"void main()\n"+
"{\n"+
" vec4 color = texture( sAlbedo, vUV );\n"+
" FragColor = vec4( color.rgb, uColor.a * color.a );\n"+
//" FragColor = vec4( color.rgb, uColor.a * color.a );\n"+
" gl_FragColor = vec4( color.rgb, uColor.a * color.a );\n"+
"}\n";

public struct Vec2
Expand Down Expand Up @@ -91,7 +104,7 @@ private Renderer CreateRenderer()
geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

// Create the shader
Shader shader = new Shader( VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER );
Shader shader = new Shader( VERTEX_SHADER, FRAGMENT_SHADER );

// Create the renderer
Renderer renderer = new Renderer( geometry, shader );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,32 @@ public class ClippedImage
static Geometry geometry = null;

private static readonly string VERTEX_SHADER =
"attribute vec2 aPositionCircle;\n" +
"attribute vec2 aPositionQuad;\n" +
"uniform float uDelta;\n" +
"uniform mat4 uMvpMatrix;\n" +
"uniform vec3 uSize;\n" +
"\n" +
"void main()\n" +
"{\n" +
" vec4 vertexPosition = vec4(mix(aPositionCircle, aPositionQuad, uDelta), 0.0, 1.0);\n" +
" vertexPosition.xyz *= uSize;\n" +
" gl_Position = uMvpMatrix * vertexPosition;\n" +
"}\n";
"//@name ClippedImage.vert\n" +
"\n" +
"//@version 100\n" +
"\n" +
"INPUT highp vec2 aPositionCircle;\n" +
"INPUT highp vec2 aPositionQuad;\n" +
"\n" +
"UNIFORM_BLOCK VertBlock\n" +
"{\n" +
" UNIFORM highp mat4 uMvpMatrix;\n" +
" UNIFORM highp vec3 uSize;\n" +
" UNIFORM highp float uDelta;\n" +
"};\n" +
"\n" +
"void main()\n" +
"{\n" +
" vec4 vertexPosition = vec4(mix(aPositionCircle, aPositionQuad, uDelta), 0.0, 1.0);\n" +
" vertexPosition.xyz *= uSize;\n" +
" gl_Position = uMvpMatrix * vertexPosition;\n" +
"}\n";

private static readonly string FRAGMENT_SHADER =
"//@name ClippedImage.frag\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n" +
"void main()\n" +
"{\n" +
Expand Down
48 changes: 34 additions & 14 deletions test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DisposeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ struct TexturedQuadVertex
}

static readonly string VERTEX_SHADER =
"attribute mediump vec3 aPosition;\n" +
"attribute mediump vec3 aNormal;\n" +
"attribute mediump vec2 aTexCoord;\n" +
"uniform mediump mat4 uMvpMatrix;\n" +
"uniform mediump mat3 uNormalMatrix;\n" +
"uniform mediump vec3 uSize;\n" +
"varying mediump vec3 vNormal;\n" +
"varying mediump vec2 vTexCoord;\n" +
"varying mediump vec3 vPosition;\n" +
"//@name DisposeTest.vert\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n"+
"INPUT highp vec3 aPosition;\n" +
"INPUT highp vec3 aNormal;\n" +
"INPUT highp vec2 aTexCoord;\n" +
"\n" +
"OUTPUT highp vec3 vNormal;\n" +
"OUTPUT highp vec2 vTexCoord;\n" +
"OUTPUT highp vec3 vPosition;\n" +
"\n" +
"UNIFORM_BLOCK VertBlock\n" +
"{\n" +
" UNIFORM highp mat4 uMvpMatrix;\n" +
" UNIFORM highp mat3 uNormalMatrix;\n" +
" UNIFORM highp vec3 uSize;\n" +
"};\n" +
"void main()\n" +
"{\n" +
" vec4 pos = vec4(aPosition, 1.0)*vec4(uSize,1.0);\n"+
Expand All @@ -76,11 +86,21 @@ struct TexturedQuadVertex
"}\n";

static readonly string FRAGMENT_SHADER =
"uniform lowp vec4 uColor;\n" +
"uniform sampler2D sTexture;\n" +
"varying mediump vec3 vNormal;\n" +
"varying mediump vec2 vTexCoord;\n" +
"varying mediump vec3 vPosition;\n" +
"//@name DisposeTest.frag\n" +
"\n" +
"//@version 100\n" +
"\n" +
"precision mediump float;\n"+
"INPUT highp vec3 vNormal;\n" +
"INPUT highp vec2 vTexCoord;\n" +
"INPUT highp vec3 vPosition;\n" +
"\n" +
"UNIFORM_BLOCK FragBlock\n" +
"{\n" +
" UNIFORM lowp vec4 uColor;\n" +
"};\n" +
"UNIFORM sampler2D sTexture;\n" +
"\n" +
"mediump vec3 uLightDir = vec3(2.0, 0.5, 1.0);\n" + // constant light dir
"mediump vec3 uViewDir = vec3(0.0, 0.0, 1.0);\n" + // constant view dir.
"mediump vec3 uAmbientColor = vec3(0.2, 0.2, 0.2);\n" +
Expand Down

0 comments on commit fe2abe0

Please sign in to comment.