Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Rename texture variables (#78)
Browse files Browse the repository at this point in the history
* rename texture names with consistent rules

* fix comment
  • Loading branch information
Lucas Crane authored Mar 23, 2020
1 parent 4102937 commit c397873
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 93 deletions.
18 changes: 9 additions & 9 deletions src/renderer/RayTracePass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bvhAccel, flattenBvh } from './bvhAccel';
import { generateEnvMapFromSceneComponents, generateBackgroundMapFromSceneBackground } from './envMapCreation';
import { envmapDistribution } from './envmapDistribution';
import { envMapDistribution } from './envMapDistribution';
import fragment from './glsl/rayTrace.frag';
import { makeRenderPass } from './RenderPass';
import { makeStratifiedSamplerCombined } from './StratifiedSamplerCombined';
Expand Down Expand Up @@ -42,7 +42,7 @@ export function makeRayTracePass(gl, {

// noiseImage is a 32-bit PNG image
function setNoise(noiseImage) {
renderPass.setTexture('noise', makeTexture(gl, {
renderPass.setTexture('noiseTex', makeTexture(gl, {
data: noiseImage,
wrapS: gl.REPEAT,
wrapT: gl.REPEAT,
Expand Down Expand Up @@ -152,13 +152,13 @@ function makeRenderPassFromScene({
renderPass.setTexture('normalMap', materialBuffer.textures.normalMap);
renderPass.setTexture('pbrMap', materialBuffer.textures.pbrMap);

renderPass.setTexture('positions', makeDataTexture(gl, geometry.getAttribute('position').array, 3));
renderPass.setTexture('positionBuffer', makeDataTexture(gl, geometry.getAttribute('position').array, 3));

renderPass.setTexture('normals', makeDataTexture(gl, geometry.getAttribute('normal').array, 3));
renderPass.setTexture('normalBuffer', makeDataTexture(gl, geometry.getAttribute('normal').array, 3));

renderPass.setTexture('uvs', makeDataTexture(gl, geometry.getAttribute('uv').array, 2));
renderPass.setTexture('uvBuffer', makeDataTexture(gl, geometry.getAttribute('uv').array, 2));

renderPass.setTexture('bvh', makeDataTexture(gl, flattenedBvh.buffer, 4));
renderPass.setTexture('bvhBuffer', makeDataTexture(gl, flattenedBvh.buffer, 4));

const envImage = generateEnvMapFromSceneComponents(directionalLights, ambientLights, environmentLights);
const envImageTextureObject = makeTexture(gl, {
Expand All @@ -170,7 +170,7 @@ function makeRenderPassFromScene({
height: envImage.height,
});

renderPass.setTexture('envmap', envImageTextureObject);
renderPass.setTexture('envMap', envImageTextureObject);

let backgroundImageTextureObject;
if (background) {
Expand All @@ -189,9 +189,9 @@ function makeRenderPassFromScene({

renderPass.setTexture('backgroundMap', backgroundImageTextureObject);

const distribution = envmapDistribution(envImage);
const distribution = envMapDistribution(envImage);

renderPass.setTexture('envmapDistribution', makeTexture(gl, {
renderPass.setTexture('envMapDistribution', makeTexture(gl, {
data: distribution.data,
storage: 'halfFloat',
width: distribution.width,
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/ReprojectPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export function makeReprojectPass(gl, params) {
renderPass.setUniform('lightScale', lightScale.x, lightScale.y);
renderPass.setUniform('previousLightScale', previousLightScale.x, previousLightScale.y);

renderPass.setTexture('light', light);
renderPass.setTexture('position', position);
renderPass.setTexture('previousLight', previousLight);
renderPass.setTexture('previousPosition', previousPosition);
renderPass.setTexture('lightTex', light);
renderPass.setTexture('positionTex', position);
renderPass.setTexture('previousLightTex', previousLight);
renderPass.setTexture('previousPositionTex', previousPosition);

renderPass.useProgram();
fullscreenQuad.draw();
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/ToneMapPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export function makeToneMapPass(gl, params) {
renderPassNative;

renderPass.setUniform('lightScale', lightScale.x, lightScale.y);
renderPass.setTexture('light', light);
renderPass.setTexture('position', position);
renderPass.setTexture('lightTex', light);
renderPass.setTexture('positionTex', position);

renderPass.useProgram();
fullscreenQuad.draw();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Create a piecewise 2D cumulative distribution function of light intensity from an envmap
// Create a piecewise 2D cumulative distribution function of light intensity from an env map
// http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#Piecewise-Constant2DDistributions

export function envmapDistribution(image) {
export function envMapDistribution(image) {
const data = image.data;

const cdfImage = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

export default `

uniform sampler2D envmap;
uniform sampler2D envmapDistribution;
uniform sampler2D envMap;
uniform sampler2D envMapDistribution;
uniform sampler2D backgroundMap;

vec2 cartesianToEquirect(vec3 pointOnSphere) {
Expand All @@ -14,13 +14,13 @@ vec2 cartesianToEquirect(vec3 pointOnSphere) {
}

float getEnvmapV(float u, out int vOffset, out float pdf) {
ivec2 size = textureSize(envmap, 0);
ivec2 size = textureSize(envMap, 0);

int left = 0;
int right = size.y + 1; // cdf length is the length of the envmap + 1
int right = size.y + 1; // cdf length is the length of the env map + 1
while (left < right) {
int mid = (left + right) >> 1;
float s = texelFetch(envmapDistribution, ivec2(0, mid), 0).x;
float s = texelFetch(envMapDistribution, ivec2(0, mid), 0).x;
if (s <= u) {
left = mid + 1;
} else {
Expand All @@ -29,24 +29,24 @@ float getEnvmapV(float u, out int vOffset, out float pdf) {
}
vOffset = left - 1;

// x channel is cumulative distribution of envmap luminance
// y channel is partial probability density of envmap luminance
vec2 s0 = texelFetch(envmapDistribution, ivec2(0, vOffset), 0).xy;
vec2 s1 = texelFetch(envmapDistribution, ivec2(0, vOffset + 1), 0).xy;
// x channel is cumulative distribution of env map luminance
// y channel is partial probability density of env map luminance
vec2 s0 = texelFetch(envMapDistribution, ivec2(0, vOffset), 0).xy;
vec2 s1 = texelFetch(envMapDistribution, ivec2(0, vOffset + 1), 0).xy;

pdf = s0.y;

return (float(vOffset) + (u - s0.x) / (s1.x - s0.x)) / float(size.y);
}

float getEnvmapU(float u, int vOffset, out float pdf) {
ivec2 size = textureSize(envmap, 0);
ivec2 size = textureSize(envMap, 0);

int left = 0;
int right = size.x + 1; // cdf length is the length of the envmap + 1
int right = size.x + 1; // cdf length is the length of the env map + 1
while (left < right) {
int mid = (left + right) >> 1;
float s = texelFetch(envmapDistribution, ivec2(1 + mid, vOffset), 0).x;
float s = texelFetch(envMapDistribution, ivec2(1 + mid, vOffset), 0).x;
if (s <= u) {
left = mid + 1;
} else {
Expand All @@ -55,10 +55,10 @@ float getEnvmapU(float u, int vOffset, out float pdf) {
}
int uOffset = left - 1;

// x channel is cumulative distribution of envmap luminance
// y channel is partial probability density of envmap luminance
vec2 s0 = texelFetch(envmapDistribution, ivec2(1 + uOffset, vOffset), 0).xy;
vec2 s1 = texelFetch(envmapDistribution, ivec2(1 + uOffset + 1, vOffset), 0).xy;
// x channel is cumulative distribution of env map luminance
// y channel is partial probability density of env map luminance
vec2 s0 = texelFetch(envMapDistribution, ivec2(1 + uOffset, vOffset), 0).xy;
vec2 s1 = texelFetch(envMapDistribution, ivec2(1 + uOffset + 1, vOffset), 0).xy;

pdf = s0.y;

Expand Down Expand Up @@ -87,22 +87,22 @@ vec3 sampleEnvmap(vec2 random, out vec2 uv, out float pdf) {
return dir;
}

float envmapPdf(vec2 uv) {
vec2 size = vec2(textureSize(envmap, 0));
float envMapPdf(vec2 uv) {
vec2 size = vec2(textureSize(envMap, 0));

float sinTheta = sin(uv.y * PI);

uv *= size;

float partialX = texelFetch(envmapDistribution, ivec2(1.0 + uv.x, uv.y), 0).y;
float partialY = texelFetch(envmapDistribution, ivec2(0, uv.y), 0).y;
float partialX = texelFetch(envMapDistribution, ivec2(1.0 + uv.x, uv.y), 0).y;
float partialY = texelFetch(envMapDistribution, ivec2(0, uv.y), 0).y;

return partialX * partialY * INVPI2 / (2.0 * sinTheta);
}

vec3 sampleEnvmapFromDirection(vec3 d) {
vec2 uv = cartesianToEquirect(d);
return textureLinear(envmap, uv).rgb;
return textureLinear(envMap, uv).rgb;
}

vec3 sampleBackgroundFromDirection(vec3 d) {
Expand Down
40 changes: 20 additions & 20 deletions src/renderer/glsl/chunks/intersect.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default `

uniform sampler2D positions;
uniform sampler2D normals;
uniform sampler2D uvs;
uniform sampler2D bvh;
uniform sampler2D positionBuffer;
uniform sampler2D normalBuffer;
uniform sampler2D uvBuffer;
uniform sampler2D bvhBuffer;

struct Triangle {
vec3 p0;
Expand All @@ -19,15 +19,15 @@ void surfaceInteractionFromBVH(inout SurfaceInteraction si, Triangle tri, vec3 b
ivec2 i1 = unpackTexel(index.y, VERTEX_COLUMNS);
ivec2 i2 = unpackTexel(index.z, VERTEX_COLUMNS);

vec3 n0 = texelFetch(normals, i0, 0).xyz;
vec3 n1 = texelFetch(normals, i1, 0).xyz;
vec3 n2 = texelFetch(normals, i2, 0).xyz;
vec3 n0 = texelFetch(normalBuffer, i0, 0).xyz;
vec3 n1 = texelFetch(normalBuffer, i1, 0).xyz;
vec3 n2 = texelFetch(normalBuffer, i2, 0).xyz;
vec3 normal = normalize(barycentric.x * n0 + barycentric.y * n1 + barycentric.z * n2);

#if defined(NUM_DIFFUSE_MAPS) || defined(NUM_NORMAL_MAPS) || defined(NUM_PBR_MAPS)
vec2 uv0 = texelFetch(uvs, i0, 0).xy;
vec2 uv1 = texelFetch(uvs, i1, 0).xy;
vec2 uv2 = texelFetch(uvs, i2, 0).xy;
vec2 uv0 = texelFetch(uvBuffer, i0, 0).xy;
vec2 uv1 = texelFetch(uvBuffer, i1, 0).xy;
vec2 uv2 = texelFetch(uvBuffer, i2, 0).xy;
vec2 uv = fract(barycentric.x * uv0 + barycentric.y * uv1 + barycentric.z * uv2);
#else
vec2 uv = vec2(0.0);
Expand Down Expand Up @@ -170,8 +170,8 @@ void intersectScene(inout Ray ray, inout SurfaceInteraction si) {
while(stack >= 0) {
int i = nodesToVisit[stack--];

vec4 r1 = fetchData(bvh, i, BVH_COLUMNS);
vec4 r2 = fetchData(bvh, i + 1, BVH_COLUMNS);
vec4 r1 = fetchData(bvhBuffer, i, BVH_COLUMNS);
vec4 r2 = fetchData(bvhBuffer, i + 1, BVH_COLUMNS);

int splitAxisOrNumPrimitives = floatBitsToInt(r1.w);

Expand All @@ -194,9 +194,9 @@ void intersectScene(inout Ray ray, inout SurfaceInteraction si) {
} else {
ivec3 index = floatBitsToInt(r1.xyz);
Triangle tri = Triangle(
fetchData(positions, index.x, VERTEX_COLUMNS).xyz,
fetchData(positions, index.y, VERTEX_COLUMNS).xyz,
fetchData(positions, index.z, VERTEX_COLUMNS).xyz
fetchData(positionBuffer, index.x, VERTEX_COLUMNS).xyz,
fetchData(positionBuffer, index.y, VERTEX_COLUMNS).xyz,
fetchData(positionBuffer, index.z, VERTEX_COLUMNS).xyz
);
TriangleIntersect hit = intersectTriangle(ray, tri, maxDim, shear);

Expand Down Expand Up @@ -236,8 +236,8 @@ bool intersectSceneShadow(inout Ray ray) {
while(stack >= 0) {
int i = nodesToVisit[stack--];

vec4 r1 = fetchData(bvh, i, BVH_COLUMNS);
vec4 r2 = fetchData(bvh, i + 1, BVH_COLUMNS);
vec4 r1 = fetchData(bvhBuffer, i, BVH_COLUMNS);
vec4 r2 = fetchData(bvhBuffer, i + 1, BVH_COLUMNS);

int splitAxisOrNumPrimitives = floatBitsToInt(r1.w);

Expand All @@ -258,9 +258,9 @@ bool intersectSceneShadow(inout Ray ray) {
} else {
ivec3 index = floatBitsToInt(r1.xyz);
Triangle tri = Triangle(
fetchData(positions, index.x, VERTEX_COLUMNS).xyz,
fetchData(positions, index.y, VERTEX_COLUMNS).xyz,
fetchData(positions, index.z, VERTEX_COLUMNS).xyz
fetchData(positionBuffer, index.x, VERTEX_COLUMNS).xyz,
fetchData(positionBuffer, index.y, VERTEX_COLUMNS).xyz,
fetchData(positionBuffer, index.z, VERTEX_COLUMNS).xyz
);

if (intersectTriangle(ray, tri, maxDim, shear).t > 0.0) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/glsl/chunks/random.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default `

// Noise texture used to generate a different random number for each pixel.
// We use blue noise in particular, but any type of noise will work.
uniform sampler2D noise;
uniform sampler2D noiseTex;

uniform float stratifiedSamples[SAMPLING_DIMENSIONS];
uniform float strataSize;
Expand All @@ -15,10 +15,10 @@ int sampleIndex = 0;
float pixelSeed;

void initRandom() {
vec2 noiseSize = vec2(textureSize(noise, 0));
vec2 noiseSize = vec2(textureSize(noiseTex, 0));

// tile the small noise texture across the entire screen
pixelSeed = texture(noise, vCoord / (pixelSize * noiseSize)).r;
pixelSeed = texture(noiseTex, vCoord / (pixelSize * noiseSize)).r;
}

float randomSample() {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/glsl/chunks/sampleGlassMicrofacet.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ vec3 glassImportanceSampleLight(SurfaceInteraction si, vec3 viewDir, bool lightR
return li;
}

vec3 irr = textureLinear(envmap, uv).xyz;
vec3 irr = textureLinear(envMap, uv).xyz;

float scatteringPdf;
vec3 brdf = lightRefract ?
Expand Down Expand Up @@ -119,9 +119,9 @@ vec3 glassImportanceSampleMaterial(SurfaceInteraction si, vec3 viewDir, bool lig
}

vec2 uv = cartesianToEquirect(lightDir);
float lightPdf = envmapPdf(uv);
float lightPdf = envMapPdf(uv);

vec3 irr = textureLinear(envmap, vec2(phi, theta)).rgb;
vec3 irr = textureLinear(envMap, vec2(phi, theta)).rgb;

float scatteringPdf;
vec3 brdf = lightRefract ?
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/glsl/chunks/sampleMaterial.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void sampleMaterial(SurfaceInteraction si, int bounce, inout Path path) {
lightDirSpecular(si.faceNormal, viewDir, basis, si.roughness, lightDirSample);

uv = cartesianToEquirect(lightDir);
lightPdf = envmapPdf(uv);
lightPdf = envMapPdf(uv);
brdfSample = true;
} else {
lightDir = sampleEnvmap(lightDirSample, uv, lightPdf);
Expand All @@ -57,7 +57,7 @@ void sampleMaterial(SurfaceInteraction si, int bounce, inout Path path) {
}
}

vec3 irr = textureLinear(envmap, uv).rgb;
vec3 irr = textureLinear(envMap, uv).rgb;

float scatteringPdf;
vec3 brdf = materialBrdf(si, viewDir, lightDir, cosThetaL, diffuseWeight, scatteringPdf);
Expand Down Expand Up @@ -95,7 +95,7 @@ void sampleMaterial(SurfaceInteraction si, int bounce, inout Path path) {
brdf = materialBrdf(si, viewDir, lightDir, cosThetaL, 1.0, scatteringPdf);

uv = cartesianToEquirect(lightDir);
lightPdf = envmapPdf(uv);
lightPdf = envMapPdf(uv);

path.misWeight = powerHeuristic(scatteringPdf, lightPdf);

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/glsl/chunks/sampleShadowCatcher.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void sampleShadowCatcher(SurfaceInteraction si, int bounce, inout Path path) {
lightDirDiffuse(si.faceNormal, viewDir, basis, lightDirSample) :
lightDirSpecular(si.faceNormal, viewDir, basis, si.roughness, lightDirSample);
uv = cartesianToEquirect(lightDir);
lightPdf = envmapPdf(uv);
lightPdf = envMapPdf(uv);
brdfSample = true;
} else {
lightDir = sampleEnvmap(lightDirSample, uv, lightPdf);
Expand All @@ -47,7 +47,7 @@ void sampleShadowCatcher(SurfaceInteraction si, int bounce, inout Path path) {
occluded = 0.0;
}

float irr = dot(luminance, textureLinear(envmap, uv).rgb);
float irr = dot(luminance, textureLinear(envMap, uv).rgb);

float scatteringPdf;
vec3 brdf = materialBrdf(si, viewDir, lightDir, cosThetaL, 1.0, scatteringPdf);
Expand Down Expand Up @@ -84,7 +84,7 @@ void sampleShadowCatcher(SurfaceInteraction si, int bounce, inout Path path) {
brdf = materialBrdf(si, viewDir, lightDir, cosThetaL, 1.0, scatteringPdf);

uv = cartesianToEquirect(lightDir);
lightPdf = envmapPdf(uv);
lightPdf = envMapPdf(uv);

path.misWeight = 0.0;

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/glsl/rayTrace.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import materialBuffer from './chunks/materialBuffer.glsl';
import intersect from './chunks/intersect.glsl';
import surfaceInteractionDirect from './chunks/surfaceInteractionDirect.glsl';
import random from './chunks/random.glsl';
import envmap from './chunks/envmap.glsl';
import envMap from './chunks/envMap.glsl';
import bsdf from './chunks/bsdf.glsl';
import sample from './chunks/sample.glsl';
import sampleMaterial from './chunks/sampleMaterial.glsl';
Expand All @@ -22,7 +22,7 @@ includes: [
intersect,
surfaceInteractionDirect,
random,
envmap,
envMap,
bsdf,
sample,
sampleMaterial,
Expand Down
Loading

0 comments on commit c397873

Please sign in to comment.