Skip to content

Instantly share code, notes, and snippets.

View CedricGuillemet's full-sized avatar

Cedric Guillemet CedricGuillemet

View GitHub Profile
python -m SimpleHTTPServer
interface NavMesh {
void NavMesh();
void destroy();
void build([Const] float[] positions, [Const] long positionCount, [Const] long[] indices, [Const] long indexCount, [Const, Ref] rcConfig config);
[Value] DebugNavMesh getDebugNavMesh();
[Value] Vec3 getClosestPoint([Const, Ref] Vec3 position);
[Value] Vec3 getRandomPointAround([Const, Ref] Vec3 position, float maxRadius);
[Value] Vec3 moveAlong([Const, Ref] Vec3 position, [Const, Ref] Vec3 destination);
dtNavMesh getNavMesh();
[Value] NavPath computePath([Const, Ref] Vec3 start, [Const, Ref] Vec3 end);
void main(void) {
gl_FragColor = vec4(1.0,0.0,1.0,1.0);
}
void main(void) {
vec3 rayDir = normalize(vPosition - vEyePosition);
gl_FragColor = vec4(rayDir,1.0);
}
float sphereDistance(vec3 point, vec3 sphereOrigin, float sphereRadius) {
return length(point - sphereOrigin) - sphereRadius;
}
void main(void) {
vec3 rayDir = normalize(vPosition - vEyePosition);
if (sphereDistance(vPosition, vec3(0,1,0), 1.1) > 0.)
discard;
gl_FragColor = vec4(rayDir, 1.0);
}
void main(void) {
vec3 rayDir = normalize(vPosition - vEyePosition);
float distanceFromSurface = 0.0;
for (int i = 0; i < 100; i++) {
vec3 currentPosition = vPosition + distanceFromSurface * rayDir;
if (sphereDistance(currentPosition, vec3(0,1,0), 1.0) < 0.){
gl_FragColor = vec4(rayDir, 1.0);
return;
}
if (sphereDistance(currentPosition, sphereCenter, 1.0) < 0.) {
vec3 normal = (currentPosition - sphereCenter);
float dotLight = dot(normal, ligthDirection) * 0.5 + 0.5;
gl_FragColor = vec4(vec3(1.0, 0.5, 0.2) * dotLight, 1.0);
return;
}
if (sphereDistance(currentPosition, sphereCenter, 1.0) < 0.) {
vec3 normal = (currentPosition - sphereCenter);
float dotLight = dot(normal, ligthDirection) * 0.5 + 0.5;
float noiseTexture = simplex3d(currentPosition * 4.0) * 0.5 + 0.5;
gl_FragColor = vec4(vec3(1.0, 0.5, 0.2) * dotLight * noiseTexture, 1.0);
return;
}
float distanceFromSurface = 0.0;
float step = 0.03;
vec3 previousPosition = vPosition;
float previousDistance = 0.;
for (int i = 0; i < 100; i++) {
vec3 currentPosition = vPosition + distanceFromSurface * rayDir;
float distance = sphereDistance(currentPosition, sphereCenter, 1.0);
if (distance < 0.) {
vec3 hitPosition = mix(previousPosition, currentPosition, previousDistance / (previousDistance - distance));
arcana::make_task(arcana::threadpool_scheduler, m_cancelSource,
[this, dataSpan, generateMips, invertY, onErrorRef = Napi::Persistent(onError)]() {
try
{
bimg::ImageContainer* image = bimg::imageParse(&m_allocator, dataSpan.data(), static_cast<uint32_t>(dataSpan.size()));
// todo: bimg::imageParse will return nullptr when trying to load a texture with an url that is not a valid texture
// Like a 404 html page.
if (invertY)
{
FlipY(image);