Skip to content

Instantly share code, notes, and snippets.

View galek's full-sized avatar
🧭
I'm ready for new discoveries

Nikolay Galko galek

🧭
I'm ready for new discoveries
View GitHub Profile
@galek
galek / gist:c22962bc30d702eb6ffa03d841c10aac
Created May 7, 2016 22:08 — forked from Novum/gist:1200562
Fast SSE pow for range [0, 1]
// Fast SSE pow for range [0, 1]
// Adapted from C. Schlick with one more iteration each for exp(x) and ln(x)
// 8 muls, 5 adds, 1 rcp
inline __m128 _mm_fastpow_0_1_ps(__m128 x, __m128 y)
{
static const __m128 fourOne = _mm_set1_ps(1.0f);
static const __m128 fourHalf = _mm_set1_ps(0.5f);
__m128 a = _mm_sub_ps(fourOne, y);
__m128 b = _mm_sub_ps(x, fourOne);
@galek
galek / gist:7bac754ccf2ce3a2b595b18be6e30937
Created May 30, 2016 00:58
Compute frag pos in view space
// Compute frag pos in view space
vec3 fragPos;
{
float depth = gl_FragCoord.z;
fragPos.z = u_lightingUniforms.projectionParams.z
/ (u_lightingUniforms.projectionParams.w + depth);
vec2 screenSize = 1.0 / RENDERER_SIZE;
vec2 ndc = gl_FragCoord.xy * screenSize * 2.0 - 1.0;
ViewDir = normalize(vCameraPos.xyz - vWorldPos.xyz);
@galek
galek / Reconstructing Position From Depth Buffer
Created May 30, 2016 04:11
Reconstructing Position From Depth Buffer
float3 vFrustumCornersWS[8] =
{
float3(-1.0, 1.0, 0.0), // near top left
float3( 1.0, 1.0, 0.0), // near top right
float3(-1.0, -1.0, 0.0), // near bottom left
float3( 1.0, -1.0, 0.0), // near bottom right
float3(-1.0, 1.0, 1.0), // far top left
float3( 1.0, 1.0, 1.0), // far top right
float3(-1.0, -1.0, 1.0), // far bottom left
float3( 1.0, -1.0, 1.0) // far bottom right
[GLSL_VERTEX_SHADER]
#include "shared/glslversion.h"
#include "glslcommon.inc"
#include "uniforms.inc"
layout(location = 0) in vec4 vposition;
layout(location = 5) in vec2 vtexcoord;
out vec2 ftexcoord;
@galek
galek / depth_to_position.glsl
Created November 22, 2016 07:41 — forked from jimmiebergmann/depth_to_position.glsl
PS3 GLSL Depth to position
//Convert to 24bit
const float3 depthFactor = float3(65536.0f/16777215.0f, 256.0f/16777215.0f, 1.0f/16777215.0f );
float GetDepth( float4 raw_depth )
{
return dot( round( raw_depth.xyz * 255.0f.xxx ), depthFactor.xyz);
}
float2 texcoord = in.vpos/g_Resolution;
pos.xy = in.vpo;
pos.z = GetDepth( tex2D(g_Depthmap,texcoord).rgba );
@galek
galek / 26.cs
Created January 17, 2017 00:23
using System;
namespace Rextester
{
public class ArrayHelper
{
int[] _result;
public int[] result
{
#include "shared/glslversion.h"
#include "glslcommon.inc"
#include "uniforms.inc"
in
#include "VertexData.h"
#include "LightData.h"
layout(location = 0) out vec4 my_FragColor0;
@galek
galek / q.glsl
Created January 26, 2017 21:48
#ifndef PHONG_LIGHTING_INC
#define PHONG_LIGHTING_INC 1
#define USE_OPTIMIZATION 1
#include "BRDF.h"
float GetAngleAttenuation(vec3 _l, vec3 _lightDir, float _angleScale, float _angleOffset)
{
float cosa = -dot(_l, _lightDir);
@galek
galek / BitwiseOperations.glsl
Created February 21, 2017 03:39 — forked from mattatz/BitwiseOperations.glsl
Bitwise operations without operators for glsl.
// BitwiseOperations.glsl
const int BIT_COUNT = 8;
int modi(int x, int y) {
return x - y * (x / y);
}
int or(int a, int b) {
int result = 0;