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

Commit c397873

Browse files
author
Lucas Crane
authored
Rename texture variables (#78)
* rename texture names with consistent rules * fix comment
1 parent 4102937 commit c397873

13 files changed

+93
-93
lines changed

src/renderer/RayTracePass.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { bvhAccel, flattenBvh } from './bvhAccel';
22
import { generateEnvMapFromSceneComponents, generateBackgroundMapFromSceneBackground } from './envMapCreation';
3-
import { envmapDistribution } from './envmapDistribution';
3+
import { envMapDistribution } from './envMapDistribution';
44
import fragment from './glsl/rayTrace.frag';
55
import { makeRenderPass } from './RenderPass';
66
import { makeStratifiedSamplerCombined } from './StratifiedSamplerCombined';
@@ -42,7 +42,7 @@ export function makeRayTracePass(gl, {
4242

4343
// noiseImage is a 32-bit PNG image
4444
function setNoise(noiseImage) {
45-
renderPass.setTexture('noise', makeTexture(gl, {
45+
renderPass.setTexture('noiseTex', makeTexture(gl, {
4646
data: noiseImage,
4747
wrapS: gl.REPEAT,
4848
wrapT: gl.REPEAT,
@@ -152,13 +152,13 @@ function makeRenderPassFromScene({
152152
renderPass.setTexture('normalMap', materialBuffer.textures.normalMap);
153153
renderPass.setTexture('pbrMap', materialBuffer.textures.pbrMap);
154154

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

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

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

161-
renderPass.setTexture('bvh', makeDataTexture(gl, flattenedBvh.buffer, 4));
161+
renderPass.setTexture('bvhBuffer', makeDataTexture(gl, flattenedBvh.buffer, 4));
162162

163163
const envImage = generateEnvMapFromSceneComponents(directionalLights, ambientLights, environmentLights);
164164
const envImageTextureObject = makeTexture(gl, {
@@ -170,7 +170,7 @@ function makeRenderPassFromScene({
170170
height: envImage.height,
171171
});
172172

173-
renderPass.setTexture('envmap', envImageTextureObject);
173+
renderPass.setTexture('envMap', envImageTextureObject);
174174

175175
let backgroundImageTextureObject;
176176
if (background) {
@@ -189,9 +189,9 @@ function makeRenderPassFromScene({
189189

190190
renderPass.setTexture('backgroundMap', backgroundImageTextureObject);
191191

192-
const distribution = envmapDistribution(envImage);
192+
const distribution = envMapDistribution(envImage);
193193

194-
renderPass.setTexture('envmapDistribution', makeTexture(gl, {
194+
renderPass.setTexture('envMapDistribution', makeTexture(gl, {
195195
data: distribution.data,
196196
storage: 'halfFloat',
197197
width: distribution.width,

src/renderer/ReprojectPass.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export function makeReprojectPass(gl, params) {
4343
renderPass.setUniform('lightScale', lightScale.x, lightScale.y);
4444
renderPass.setUniform('previousLightScale', previousLightScale.x, previousLightScale.y);
4545

46-
renderPass.setTexture('light', light);
47-
renderPass.setTexture('position', position);
48-
renderPass.setTexture('previousLight', previousLight);
49-
renderPass.setTexture('previousPosition', previousPosition);
46+
renderPass.setTexture('lightTex', light);
47+
renderPass.setTexture('positionTex', position);
48+
renderPass.setTexture('previousLightTex', previousLight);
49+
renderPass.setTexture('previousPositionTex', previousPosition);
5050

5151
renderPass.useProgram();
5252
fullscreenQuad.draw();

src/renderer/ToneMapPass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export function makeToneMapPass(gl, params) {
4646
renderPassNative;
4747

4848
renderPass.setUniform('lightScale', lightScale.x, lightScale.y);
49-
renderPass.setTexture('light', light);
50-
renderPass.setTexture('position', position);
49+
renderPass.setTexture('lightTex', light);
50+
renderPass.setTexture('positionTex', position);
5151

5252
renderPass.useProgram();
5353
fullscreenQuad.draw();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Create a piecewise 2D cumulative distribution function of light intensity from an envmap
1+
// Create a piecewise 2D cumulative distribution function of light intensity from an env map
22
// http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#Piecewise-Constant2DDistributions
33

4-
export function envmapDistribution(image) {
4+
export function envMapDistribution(image) {
55
const data = image.data;
66

77
const cdfImage = {
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
export default `
55

6-
uniform sampler2D envmap;
7-
uniform sampler2D envmapDistribution;
6+
uniform sampler2D envMap;
7+
uniform sampler2D envMapDistribution;
88
uniform sampler2D backgroundMap;
99

1010
vec2 cartesianToEquirect(vec3 pointOnSphere) {
@@ -14,13 +14,13 @@ vec2 cartesianToEquirect(vec3 pointOnSphere) {
1414
}
1515

1616
float getEnvmapV(float u, out int vOffset, out float pdf) {
17-
ivec2 size = textureSize(envmap, 0);
17+
ivec2 size = textureSize(envMap, 0);
1818

1919
int left = 0;
20-
int right = size.y + 1; // cdf length is the length of the envmap + 1
20+
int right = size.y + 1; // cdf length is the length of the env map + 1
2121
while (left < right) {
2222
int mid = (left + right) >> 1;
23-
float s = texelFetch(envmapDistribution, ivec2(0, mid), 0).x;
23+
float s = texelFetch(envMapDistribution, ivec2(0, mid), 0).x;
2424
if (s <= u) {
2525
left = mid + 1;
2626
} else {
@@ -29,24 +29,24 @@ float getEnvmapV(float u, out int vOffset, out float pdf) {
2929
}
3030
vOffset = left - 1;
3131

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

3737
pdf = s0.y;
3838

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

4242
float getEnvmapU(float u, int vOffset, out float pdf) {
43-
ivec2 size = textureSize(envmap, 0);
43+
ivec2 size = textureSize(envMap, 0);
4444

4545
int left = 0;
46-
int right = size.x + 1; // cdf length is the length of the envmap + 1
46+
int right = size.x + 1; // cdf length is the length of the env map + 1
4747
while (left < right) {
4848
int mid = (left + right) >> 1;
49-
float s = texelFetch(envmapDistribution, ivec2(1 + mid, vOffset), 0).x;
49+
float s = texelFetch(envMapDistribution, ivec2(1 + mid, vOffset), 0).x;
5050
if (s <= u) {
5151
left = mid + 1;
5252
} else {
@@ -55,10 +55,10 @@ float getEnvmapU(float u, int vOffset, out float pdf) {
5555
}
5656
int uOffset = left - 1;
5757

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

6363
pdf = s0.y;
6464

@@ -87,22 +87,22 @@ vec3 sampleEnvmap(vec2 random, out vec2 uv, out float pdf) {
8787
return dir;
8888
}
8989

90-
float envmapPdf(vec2 uv) {
91-
vec2 size = vec2(textureSize(envmap, 0));
90+
float envMapPdf(vec2 uv) {
91+
vec2 size = vec2(textureSize(envMap, 0));
9292

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

9595
uv *= size;
9696

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

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

103103
vec3 sampleEnvmapFromDirection(vec3 d) {
104104
vec2 uv = cartesianToEquirect(d);
105-
return textureLinear(envmap, uv).rgb;
105+
return textureLinear(envMap, uv).rgb;
106106
}
107107

108108
vec3 sampleBackgroundFromDirection(vec3 d) {

src/renderer/glsl/chunks/intersect.glsl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export default `
22

3-
uniform sampler2D positions;
4-
uniform sampler2D normals;
5-
uniform sampler2D uvs;
6-
uniform sampler2D bvh;
3+
uniform sampler2D positionBuffer;
4+
uniform sampler2D normalBuffer;
5+
uniform sampler2D uvBuffer;
6+
uniform sampler2D bvhBuffer;
77

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

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

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

173-
vec4 r1 = fetchData(bvh, i, BVH_COLUMNS);
174-
vec4 r2 = fetchData(bvh, i + 1, BVH_COLUMNS);
173+
vec4 r1 = fetchData(bvhBuffer, i, BVH_COLUMNS);
174+
vec4 r2 = fetchData(bvhBuffer, i + 1, BVH_COLUMNS);
175175

176176
int splitAxisOrNumPrimitives = floatBitsToInt(r1.w);
177177

@@ -194,9 +194,9 @@ void intersectScene(inout Ray ray, inout SurfaceInteraction si) {
194194
} else {
195195
ivec3 index = floatBitsToInt(r1.xyz);
196196
Triangle tri = Triangle(
197-
fetchData(positions, index.x, VERTEX_COLUMNS).xyz,
198-
fetchData(positions, index.y, VERTEX_COLUMNS).xyz,
199-
fetchData(positions, index.z, VERTEX_COLUMNS).xyz
197+
fetchData(positionBuffer, index.x, VERTEX_COLUMNS).xyz,
198+
fetchData(positionBuffer, index.y, VERTEX_COLUMNS).xyz,
199+
fetchData(positionBuffer, index.z, VERTEX_COLUMNS).xyz
200200
);
201201
TriangleIntersect hit = intersectTriangle(ray, tri, maxDim, shear);
202202

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

239-
vec4 r1 = fetchData(bvh, i, BVH_COLUMNS);
240-
vec4 r2 = fetchData(bvh, i + 1, BVH_COLUMNS);
239+
vec4 r1 = fetchData(bvhBuffer, i, BVH_COLUMNS);
240+
vec4 r2 = fetchData(bvhBuffer, i + 1, BVH_COLUMNS);
241241

242242
int splitAxisOrNumPrimitives = floatBitsToInt(r1.w);
243243

@@ -258,9 +258,9 @@ bool intersectSceneShadow(inout Ray ray) {
258258
} else {
259259
ivec3 index = floatBitsToInt(r1.xyz);
260260
Triangle tri = Triangle(
261-
fetchData(positions, index.x, VERTEX_COLUMNS).xyz,
262-
fetchData(positions, index.y, VERTEX_COLUMNS).xyz,
263-
fetchData(positions, index.z, VERTEX_COLUMNS).xyz
261+
fetchData(positionBuffer, index.x, VERTEX_COLUMNS).xyz,
262+
fetchData(positionBuffer, index.y, VERTEX_COLUMNS).xyz,
263+
fetchData(positionBuffer, index.z, VERTEX_COLUMNS).xyz
264264
);
265265

266266
if (intersectTriangle(ray, tri, maxDim, shear).t > 0.0) {

src/renderer/glsl/chunks/random.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default `
22

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

77
uniform float stratifiedSamples[SAMPLING_DIMENSIONS];
88
uniform float strataSize;
@@ -15,10 +15,10 @@ int sampleIndex = 0;
1515
float pixelSeed;
1616

1717
void initRandom() {
18-
vec2 noiseSize = vec2(textureSize(noise, 0));
18+
vec2 noiseSize = vec2(textureSize(noiseTex, 0));
1919

2020
// tile the small noise texture across the entire screen
21-
pixelSeed = texture(noise, vCoord / (pixelSize * noiseSize)).r;
21+
pixelSeed = texture(noiseTex, vCoord / (pixelSize * noiseSize)).r;
2222
}
2323

2424
float randomSample() {

src/renderer/glsl/chunks/sampleGlassMicrofacet.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ vec3 glassImportanceSampleLight(SurfaceInteraction si, vec3 viewDir, bool lightR
8888
return li;
8989
}
9090

91-
vec3 irr = textureLinear(envmap, uv).xyz;
91+
vec3 irr = textureLinear(envMap, uv).xyz;
9292

9393
float scatteringPdf;
9494
vec3 brdf = lightRefract ?
@@ -119,9 +119,9 @@ vec3 glassImportanceSampleMaterial(SurfaceInteraction si, vec3 viewDir, bool lig
119119
}
120120

121121
vec2 uv = cartesianToEquirect(lightDir);
122-
float lightPdf = envmapPdf(uv);
122+
float lightPdf = envMapPdf(uv);
123123

124-
vec3 irr = textureLinear(envmap, vec2(phi, theta)).rgb;
124+
vec3 irr = textureLinear(envMap, vec2(phi, theta)).rgb;
125125

126126
float scatteringPdf;
127127
vec3 brdf = lightRefract ?

src/renderer/glsl/chunks/sampleMaterial.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void sampleMaterial(SurfaceInteraction si, int bounce, inout Path path) {
3030
lightDirSpecular(si.faceNormal, viewDir, basis, si.roughness, lightDirSample);
3131

3232
uv = cartesianToEquirect(lightDir);
33-
lightPdf = envmapPdf(uv);
33+
lightPdf = envMapPdf(uv);
3434
brdfSample = true;
3535
} else {
3636
lightDir = sampleEnvmap(lightDirSample, uv, lightPdf);
@@ -57,7 +57,7 @@ void sampleMaterial(SurfaceInteraction si, int bounce, inout Path path) {
5757
}
5858
}
5959

60-
vec3 irr = textureLinear(envmap, uv).rgb;
60+
vec3 irr = textureLinear(envMap, uv).rgb;
6161

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

9797
uv = cartesianToEquirect(lightDir);
98-
lightPdf = envmapPdf(uv);
98+
lightPdf = envMapPdf(uv);
9999

100100
path.misWeight = powerHeuristic(scatteringPdf, lightPdf);
101101

src/renderer/glsl/chunks/sampleShadowCatcher.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void sampleShadowCatcher(SurfaceInteraction si, int bounce, inout Path path) {
2626
lightDirDiffuse(si.faceNormal, viewDir, basis, lightDirSample) :
2727
lightDirSpecular(si.faceNormal, viewDir, basis, si.roughness, lightDirSample);
2828
uv = cartesianToEquirect(lightDir);
29-
lightPdf = envmapPdf(uv);
29+
lightPdf = envMapPdf(uv);
3030
brdfSample = true;
3131
} else {
3232
lightDir = sampleEnvmap(lightDirSample, uv, lightPdf);
@@ -47,7 +47,7 @@ void sampleShadowCatcher(SurfaceInteraction si, int bounce, inout Path path) {
4747
occluded = 0.0;
4848
}
4949

50-
float irr = dot(luminance, textureLinear(envmap, uv).rgb);
50+
float irr = dot(luminance, textureLinear(envMap, uv).rgb);
5151

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

8686
uv = cartesianToEquirect(lightDir);
87-
lightPdf = envmapPdf(uv);
87+
lightPdf = envMapPdf(uv);
8888

8989
path.misWeight = 0.0;
9090

0 commit comments

Comments
 (0)