All Projects → appspell → ShaderView

appspell / ShaderView

Licence: MIT license
ShaderView is an Android View that makes it easy to use GLSL shaders for your app. It's the modern way to use shaders for Android instead of RenderScript.

Programming Languages

kotlin
9241 projects
GLSL
2045 projects

Projects that are alternatives of or similar to ShaderView

30-days-of-shade
30 days of shaders in GLSL using GLSLCanvas
Stars: ✭ 134 (+152.83%)
Mutual labels:  shaders, glsl, glsl-shaders
kotlin-glsl
Write your GLSL shaders in Kotlin.
Stars: ✭ 30 (-43.4%)
Mutual labels:  shaders, glsl, glsl-shaders
deffx
A collection of useful shader effects made ready to be used with the Defold game engine
Stars: ✭ 33 (-37.74%)
Mutual labels:  shaders, glsl, glsl-shaders
Radiance
Radiance is video art software for VJs. It supports beat detection, animated GIFs, YouTube video, OpenGL shader effects. It is designed for live performance and runs on Linux and MacOS.
Stars: ✭ 109 (+105.66%)
Mutual labels:  glsl, video-processing, glsl-shaders
React Regl
React Fiber Reconciler Renderer for Regl WebGL
Stars: ✭ 171 (+222.64%)
Mutual labels:  shaders, glsl, glsl-shaders
Webgl Fundamentals
WebGL lessons that start with the basics
Stars: ✭ 3,315 (+6154.72%)
Mutual labels:  shaders, glsl, glsl-shaders
YALCT
Yet Another Live Coding Tool - Powered by Veldrid and elbow grease
Stars: ✭ 25 (-52.83%)
Mutual labels:  shaders, glsl, glsl-shaders
ModularMusicVisualizer
Project in Hiatus, unmaintained, being rewritten privately. Will Open Source when stuff is ready. Project will be Renamed.
Stars: ✭ 81 (+52.83%)
Mutual labels:  shaders, glsl, glsl-shaders
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+21971.7%)
Mutual labels:  shaders, glsl, glsl-shaders
Thebookofshaders
Step-by-step guide through the abstract and complex universe of Fragment Shaders.
Stars: ✭ 4,070 (+7579.25%)
Mutual labels:  shaders, glsl, glsl-shaders
glNoise
A collection of GLSL noise functions for use with WebGL with an easy to use API.
Stars: ✭ 185 (+249.06%)
Mutual labels:  shaders, glsl, glsl-shaders
FNode
Tool based in nodes to build GLSL shaders without any programming knowledge written in C using OpenGL and GLFW.
Stars: ✭ 81 (+52.83%)
Mutual labels:  shaders, glsl, glsl-shaders
andromeda
GLSL-targetting embedded compiler, and OpenGL rendering engine.
Stars: ✭ 75 (+41.51%)
Mutual labels:  shaders, glsl-shaders
Messier87
A realtime raytracing blackhole renderer
Stars: ✭ 53 (+0%)
Mutual labels:  shaders, glsl
glsl-cos-palette
glsl function for making cosine palettes
Stars: ✭ 26 (-50.94%)
Mutual labels:  shaders, glsl
3D interactive graphics rendering engine
Develop a 3D interactive graphics rendering engine
Stars: ✭ 31 (-41.51%)
Mutual labels:  glsl, glsl-shaders
ShaderBoy
Simple text editor that lets you write Shadertoy shaders more comfortably, anytime, anywhere.
Stars: ✭ 133 (+150.94%)
Mutual labels:  glsl, glsl-shaders
ShaderToy-Chrome-Plugin
Web extension for shadertoy.com
Stars: ✭ 159 (+200%)
Mutual labels:  shaders, glsl-shaders
cellular-automata-explorer
(WIP) An interactive web app for exploring cellular automata.
Stars: ✭ 18 (-66.04%)
Mutual labels:  shaders, glsl
sparksl-noise
minimum proof of concept about procedural noise generation in SparkAR's shader language (SparkSL).
Stars: ✭ 16 (-69.81%)
Mutual labels:  shaders, glsl

ShaderView

This library is the easiest way to use OpenGL shaders as an Android View. You just simply need to add ShaderView in your layout and set up shaders. The advantage of this library that you can use ShaderView in your hierarchy as a regular View.

Use cases:

  • Shaders for video
  • Advanced UI components (blur, shadow, lighting, etc.)
  • UI effects and animation
  • Realtime image animation
  • Shaders for a camera

Table of content

How to use it

Add dependency to the project

Gradle

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
implementation 'com.github.appspell:ShaderView:[last-version]'

Add ShaderView to XML layout

  1. Add ShaderView to the XML layout
    <com.appspell.shaderview.ShaderView
        android:id="@+id/shaderView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:fragment_shader_raw_res_id="@raw/fragment_shader" />
  1. Set your fragment and vertex (if needed) shaders using the following attributes:

app:fragment_shader_raw_res_id - reference to the fragment shader file in RAW resource solder example

app:vertex_shader_raw_res_id - reference to the vertex shader file in RAW resource solder example

Add ShaderView programmatically (or configure programmatically)

val shaderView = ShaderView(this)

with(shaderView) {
   fragmentShaderRawResId = R.raw.color_frag
   shaderParams = ShaderParams.Builder()
                .addColor("diffuseColor", R.color.teal_200, resources)
                .build()
}

The full list of ShaderView properties:

fragmentShaderRawResId - reference to the vertex shader file in RAW resource solder [example]

vertexShaderRawResId - reference to the fragment shader file in RAW resource solder [example]

shaderParams - custom parameters that we're going to send to the shader (uniform)

onViewReadyListener - called when the view is created and ready to create a shader

onDrawFrameListener - called each frame

updateContinuously - should we render the view each frame (default is "false")

debugMode - enable or disable debug logs

How to send custom data to the shader

Pass ShaderParams to the ShaderView if you need to set up some uniform attributes.

shaderView.shaderParams = ShaderParamsBuilder()
                    .addTexture2D(
                        "uNormalTexture", // name of `sampler2D` in the fragment shader
                        R.drawable.normal_button, // drawable that we use for such texture
                        GLES30.GL_TEXTURE0 // texture slot
                    )
                    .addColor("uColor", R.color.grey, resources) // send color as `uniform vec4`
                    .addVec4f("uColor2", floatArrayOf(0.5f, 0.5f, 0.5f, 1f))
                    .addVec3f("uVaryingColor", floatArrayOf(0.5f, 0.5f, 0.5f))
                    .addFloat("uTime", 1.0f)
                    .build()

During execution, you may update this param:

shaderParams.updateValue("time", System.currentTimeMillis())

If you need to update uniform each frame, you may use onDrawFrameListener.

shaderView.onDrawFrameListener = { shaderParams ->
                    shaderParams.updateValue("time", System.currentTimeMillis())
                }

The full list of supported uniform types: float, int, bool, vec2f, vec3f, vec4f, vec2i, vec3i, vec4i, mat3, mat4, mat3x4, sampler2D, samplerExternalOES

How to add custom fragment shader using build-in vector shader

  1. Set up version
  2. Configure input and output. By default vertex shader sends texture coordinates using this field in vec2 textureCoord
  3. add main() function and return the result color to fragColor
#version 300 es
precision mediump float;

in vec2 textureCoord;
out vec4 fragColor;

void main() {
    fragColor = vec4(textureCoord.x, textureCoord.y, textureCoord.y, 1.0);
}

How to add shaders for video playback

Full code of example using ExoPlayer you may find here and here

  1. Setup OES texture in fragment shader:
#version 300 es
#extension GL_OES_EGL_image_external_essl3 : require

uniform samplerExternalOES uVideoTexture;
  1. Define it for ShaderParams
shaderParams = ShaderParamsBuilder()
                .addTextureOES("uVideoTexture") // video texture input/output
                .build()
  1. When ShaderView is ready, send Surface to the video player
shaderView.onViewReadyListener = { shader ->
                // get surface from shader params
                val surface = shader.params.getTexture2dOESSurface("uVideoTexture")

                // initialize video player with this surface
                initVideoPlayer(surface)
            }

Example of shaders

In Android Demo Project code you may found it in ViewHolders here

Additional information

Why we use TextureView instead of SurfaceView you can read here.

To be able to use OpenGL rendering for Android TextureView, we've created GLTextureView.kt

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].