Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@
[submodule "vendor/grammars/ionide-fsgrammar"]
path = vendor/grammars/ionide-fsgrammar
url = https://github.com/ionide/ionide-fsgrammar
[submodule "vendor/grammars/ispc.syntax"]
path = vendor/grammars/ispc.syntax
url = https://github.com/ispc/ispc.syntax.git
[submodule "vendor/grammars/jade-tmbundle"]
path = vendor/grammars/jade-tmbundle
url = https://github.com/davidrios/jade-tmbundle
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ vendor/grammars/ionide-fsgrammar:
- source.fsharp.fsx
- source.paket.dependencies
- source.paket.lock
vendor/grammars/ispc.syntax:
- source.ispc
vendor/grammars/jade-tmbundle:
- source.pyjade
- text.jade
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,16 @@ IRC log:
codemirror_mode: mirc
codemirror_mime_type: text/mirc
language_id: 164
ISPC:
type: programming
color: "#2D68B1"
extensions:
- ".ispc"
tm_scope: source.ispc
ace_mode: c_cpp
codemirror_mode: clike
codemirror_mime_type: text/x-csrc
language_id: 327071
Idris:
type: programming
color: "#b30000"
Expand Down
88 changes: 88 additions & 0 deletions samples/ISPC/VideoFunctions.ispc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
export struct VideoData {
uint16 width;
uint16 height;
uint16 buffer_width;
uint16 buffer_height;
int16 yoffset;
int16 xoffset;
int16 ytail;
int16 xtail;
bool transparentBlack;
int16 transparentBlackLevel;
int16 image_width;
int16 image_height;
int32 startx;
int32 starty;
int32 sampleSpacing;

int8 ch;
uint8* image;
void* bufferData;
};

export void VideoEffectProcess(const uniform VideoData &data,
uniform int startIdx, uniform int endIdx,
uniform uint8<4> result[])
{
uniform int ch = data.ch;


foreach (index = startIdx...endIdx) {
float fidx = index;
float y = (floor)(fidx / data.buffer_width);
float x = fidx - (y * data.buffer_width);
int newIndex = x + data.startx + ((y + data.starty) * data.buffer_width);

uint8* ptr = data.image + (data.image_height - 1 - y - data.yoffset) * (data.image_width * ch) + (data.xoffset * ch) + (x * ch);
uint8<4> c;
c.x = *(ptr);
c.y = *(ptr + 1);
c.z = *(ptr + 2);
c.w = ch == 3 ? 255 : *(ptr + 3);
uint16 level = (uint16)c[0] + (uint16)c[1] + (uint16)c[2];
if (data.transparentBlack) {
if (level > data.transparentBlackLevel) {
result[newIndex] = c;
}
} else {
result[newIndex] = c;
}
}
}

export void VideoEffectProcessSample(const uniform VideoData &data,
uniform int startIdx, uniform int endIdx,
uniform uint8<4> result[]) {
uniform float width = data.width;
uniform float rszw = 1.0 / width;
uniform float height = data.height;
uniform int ch = data.ch;

foreach (index = startIdx ... endIdx) {
float fidx = index;
float y = (floor)(fidx * rszw + 0.00001);
float x = fidx - (y * width);
float newIndex = (y * width) + x;

int curx = data.startx + x * data.sampleSpacing;
int cury = data.starty + y * data.sampleSpacing;

if (curx >= 0 && curx < data.image_width && cury >= 0 && cury < data.image_height) {

uint8* ptr = data.image + (data.image_height - 1 - cury) * data.image_width * ch + curx * ch;
uint8<4> c;
c.x = *(ptr);
c.y = *(ptr + 1);
c.z = *(ptr + 2);
c.w = ch == 3 ? 255 : *(ptr + 3);
if (data.transparentBlack) {
uint16 level = (uint16)c[0] + (uint16)c[1] + (uint16)c[2];
if (level > data.transparentBlackLevel) {
result[newIndex] = c;
}
} else {
result[newIndex] = c;
}
}
}
}
182 changes: 182 additions & 0 deletions samples/ISPC/program_city.ispc
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// https://www.shadertoy.com/view/XlsyWB

const float streetDistance = 0.6;
const vec3 streetColor = { 4.0, 8.0, 10.0 };

const float fogDensity = 0.5;
const float fogDistance = 4.0;
const vec3 fogColor = { 0.34, 0.37, 0.4 };

const float windowSize = 0.1;
const float windowDivergence = 0.2;
const vec3 windowColor = { 0.1, 0.2, 0.5 };

const float beaconProb = 0.0003;
const float beaconFreq = 0.6;
const vec3 beaconColor = { 1.5, 0.2, 0.0 };


const float tau = 6.283185;

float hash1(vec2 p2) {
p2 = fract(p2 * vec2(5.3983, 5.4427));
p2 += dot(p2.yx, p2.xy + vec2(21.5351, 14.3137));
return fract(p2.x * p2.y * 95.4337);
}

float hash1(vec2 p2, float p) {
vec3 p3 = fract(vec3(5.3983 * p2.x, 5.4427 * p2.y, 6.9371 * p));
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}

vec2 hash2(vec2 p2) {
vec3 p3 = fract(vec3(5.3983 * p2.x, 5.4427 * p2.y, 6.9371 * p2.x));
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.xx + p3.yz) * p3.zy);
}

vec2 hash2(vec2 p2, float p) {
vec3 p3 = fract(vec3(5.3983 * p2.x, 5.4427 * p2.y, 6.9371 * p));
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.xx + p3.yz) * p3.zy);
}

vec3 hash3(vec2 p2) {
vec3 p3 = fract(vec3(p2.xyx) * vec3(5.3983, 5.4427, 6.9371));
p3 += dot(p3, p3.yxz + 19.19);
return fract((p3.xxy + p3.yzz) * p3.zyx);
}

float noise1(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(hash1(i + vec2(0.0, 0.0)),
hash1(i + vec2(1.0, 0.0)), u.x),
mix(hash1(i + vec2(0.0, 1.0)),
hash1(i + vec2(1.0, 1.0)), u.x), u.y);
}

vec4 castRay(vec3 eye, vec3 ray) {
vec2 block = floor(eye.xy);
vec3 ri = 1.0 / ray;
vec3 rs = sign(ray);
vec3 side = 0.5 + 0.5 * rs;
vec2 ris = ri.xy * rs.xy;
vec2 dis = (block - eye.xy + 0.5 + rs.xy * 0.5) * ri.xy;

float beacon = 0.0;

for (int i = 0; i < 200; ++i) {
vec2 lo0 = vec2(block + 0.01);
vec2 loX = vec2(0.3, 0.3);
vec2 hi0 = vec2(block + 0.69);
vec2 hiX = vec2(0.3, 0.3);
float height = (0.5 + hash1(block)) * (2.0 + 4.0 * pow(noise1(0.1 * block), 2.5));

float dist = 500.0;
float face = 0.0;
for (int j = 0; j < 3; ++j) {
float top = height * (1.0 - 0.1 * float(j));
vec3 lo = vec3(lo0 + loX * hash2(block, float(j)), 0.0);
vec3 hi = vec3(hi0 + hiX * hash2(block, float(j) + 0.5), top);

vec3 wall = mix(hi, lo, side);
vec3 t = (wall - eye) * ri;

vec3 dim = step(t.zxy, t) * step(t.yzx, t);
float maxT = dot(dim, t);
float maxFace = 1.0 - dim.z;

vec3 p = eye + maxT * ray;
dim += step(lo, p) * step(p, hi);
if (dim.x * dim.y * dim.z > 0.5 && maxT < dist) {
dist = maxT;
face = maxFace;
}
}

float prob = beaconProb * pow(height, 3.0);
vec2 h = hash2(block);
if (h.x < prob) {
vec3 center = vec3(block + 0.5, height + 0.2);
float t = dot(center - eye, ray);
if (t < dist) {
vec3 p = eye + t * ray;
float fog = (exp(-p.z / fogDistance) - exp(-eye.z / fogDistance)) / ray.z;
fog = exp(fogDensity * fog);

t = distance(center, p);
fog *= smoothstep(1.0, 0.5, cos(tau * (beaconFreq * iTime + h.y)));
beacon += fog * pow(clamp(1.0 - 2.0 * t, 0.0, 1.0), 4.0);
}
}

if (dist < 400.0) {
return vec4(dist, beacon, face, 1.0);
}

float t = eye.z * ri.z;
vec3 p = eye - t * ray;
vec2 g = p.xy - block;
if (g.x > 0.0 && g.x < 1.0 && g.y > 0.0 && g.y < 1.0) {
return vec4(-t, beacon, 0.0, 1.0);
}

vec2 dim = step(dis.xy, dis.yx);
dis += dim * ris;
block += dim * rs.xy;
}

if (ray.z < 0.0) {
return vec4(-eye.z * ri.z, beacon, 0.0, 1.0);
}

return vec4(0.0, beacon, 0.0, 0.0);
}

inline void mainImage(vec4& fragColor, vec2 fragCoord)
{
vec2 m = vec2(0.03 * iTime, 0.8);
if (iMouse.z > 0.0)
m = iMouse.xy / iResolution.xy;
m *= tau * vec2(1.0, 0.25);

vec3 center = vec3(6.0 * iTime, 0.5, 3.0);
float dist = 20.0;
vec3 eye = center + vec3(dist * sin(m.x) * sin(m.y), dist * cos(m.x) * sin(m.y), dist * cos(m.y));
float zoom = 3.0;

vec3 forward = normalize(center - eye);
vec3 right = normalize(cross(forward, vec3(0.0, 0.0, 1.0)));
vec3 up = cross(right, forward);
vec2 xy = 2.0 * fragCoord - iResolution.xy;
zoom *= iResolution.y;
vec3 ray = normalize(xy.x * right + xy.y * up + zoom * forward);

vec4 res = castRay(eye, ray);
vec3 p = eye + res.x * ray;

vec2 block = floor(p.xy);
vec3 window = floor(p / windowSize);
float x = hash1(block, window.x);
float y = hash1(block, window.y);
float z = hash1(block, window.z);
vec3 color = windowColor + windowDivergence * (hash3(block) - 0.5);
color *= smoothstep(0.1, 0.9, fract(2.5 * (x * y * z)));

vec3 streetLevel = streetColor * exp(-p.z / streetDistance);
color += streetLevel;
color = clamp(mix(0.25 * streetLevel, color, res.z), 0.0, 1.0);

float fog = (exp(-p.z / fogDistance) - exp(-eye.z / fogDistance)) / ray.z;
fog = exp(fogDensity * fog);
color = mix(fogColor, color, fog);

color = mix(fogColor, color, res.w);
color += res.y * beaconColor;
color += pow(res.y, 2.0);

fragColor = vec4(color, 1.0);
}
Loading