Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local kernel = {
category = "generator",
name = "stars",
isTimeDependent = false
}
kernel.vertexData = {
{
name = 'resolutionX',
default = display.pixelWidth,
index = 0
},
{
name = 'resolutionY',
default = display.pixelHeight,
index = 1
},
{
name = 'seed',
default = 234203212011.0,
index = 2
}
}
kernel.fragment =
[[
#ifdef GL_ES
precision P_NORMAL float;
#endif
// based off http://glslsandbox.com/e#32816.0
float rand(vec2 co)
{
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 437.585453);
}
vec4 FragmentKernel( P_UV vec2 texCoord ){
vec2 resolution = vec2(15);
//if you want 'twinkle' effect, turn on isTimeDependent for kernel, and set
//seed to be CoronaTotalTime
float seed = CoronaVertexUserData.z;
float prob = 0.998;
float color = 0.0;
if (rand(texCoord.xy / resolution.xy) > prob)
{
float r = rand(texCoord.xy);
color = r * (0.85 * sin(seed * (r * 5.0) + 720.0 * r) + 0.95);
}
P_COLOR vec4 ret = vec4(vec3(color), 1.0);
return CoronaColorScale(ret);
}
]]
graphics.defineEffect(kernel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.