Skip to content

Commit afbc3aa

Browse files
committed
Reapply "revert mipmap generation in envbaking"
This reverts commit c39e790.
1 parent 6c85c38 commit afbc3aa

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

jme3-core/src/main/java/com/jme3/environment/baker/GenericEnvBaker.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import com.jme3.texture.Texture.WrapMode;
5858
import com.jme3.texture.TextureCubeMap;
5959
import com.jme3.texture.image.ColorSpace;
60-
import com.jme3.util.BufferUtils;
6160

6261
/**
6362
* Render the environment into a cubemap
@@ -116,12 +115,9 @@ protected GenericEnvBaker(RenderManager rm, AssetManager am, Format colorFormat,
116115

117116
envMap = new TextureCubeMap(env_size, env_size, colorFormat);
118117
envMap.setMagFilter(MagFilter.Bilinear);
119-
// Specular prefiltering samples the captured environment with explicit
120-
// source LODs, so the capture texture must keep a mip chain available.
121-
envMap.setMinFilter(MinFilter.Trilinear);
118+
envMap.setMinFilter(MinFilter.BilinearNoMipMaps);
122119
envMap.setWrap(WrapMode.EdgeClamp);
123120
envMap.getImage().setColorSpace(ColorSpace.Linear);
124-
initializeCubemapFacesToBlack(envMap);
125121
}
126122

127123
@Override
@@ -177,7 +173,6 @@ public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear,
177173
envbakers[i].setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
178174
envbakers[i].setSrgb(false);
179175
envbakers[i].addColorTarget(FrameBufferTarget.newTarget(envMap).face(TextureCubeMap.Face.values()[i]));
180-
envbakers[i].setMipMapsGenerationHint(i == 5);
181176
}
182177

183178
if (isTexturePulling()) {
@@ -294,13 +289,4 @@ protected int limitMips(int nbMipMaps, int baseW, int baseH, RenderManager rm) {
294289
return nbMipMaps;
295290
}
296291

297-
private void initializeCubemapFacesToBlack(TextureCubeMap cubemap) {
298-
int bytesPerPixel = cubemap.getImage().getFormat().getBitsPerPixel() / 8;
299-
int faceSize = cubemap.getImage().getWidth() * cubemap.getImage().getHeight() * bytesPerPixel;
300-
for (int i = 0; i < 6; i++) {
301-
cubemap.getImage().setData(i, BufferUtils.createByteBuffer(faceSize));
302-
}
303-
cubemap.getImage().setUpdateNeeded();
304-
}
305-
306292
}

jme3-core/src/main/resources/Common/IBL/IBLKernels.frag

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ void prefilteredEnvKernel(){
7878

7979
float roughness = clamp(m_Roughness, 0.0, 1.0);
8080
float alpha = roughness * roughness;
81-
float envMapResolution = float(textureSize(m_EnvMap, 0).x);
82-
float texelSolidAngle = (4.0 * PI) / max(6.0 * envMapResolution * envMapResolution, 1.0);
83-
float maxSourceLod = max(log2(envMapResolution), 0.0);
84-
85-
// The GGX distribution becomes singular for an ideal mirror. For mip 0,
86-
// skip the importance-sampled integration and keep the sharp source env.
87-
if (roughness <= 0.0) {
88-
outFragColor = vec4(textureLod(m_EnvMap, R, 0.0).rgb, 1.0);
89-
return;
90-
}
9181

9282
const uint SAMPLE_COUNT = 1024u;
9383
float totalWeight = 0.0;
@@ -99,14 +89,7 @@ void prefilteredEnvKernel(){
9989
vec3 L = normalize(2.0 * VoH * H - V);
10090
float NdotL = max(dot(N, L), 0.0);
10191
if(NdotL > 0.0) {
102-
float NdotH = max(dot(N, H), 0.0);
103-
float pdf = ImportanceSampleGGXPdf(NdotH, VoH, alpha);
104-
float sampleSolidAngle = 1.0 / max(float(SAMPLE_COUNT) * pdf, 1e-4);
105-
// Approximate each cubemap texel as equal-area and select a source mip
106-
// from the ratio between the GGX sample cone and a texel footprint.
107-
float sourceLod = roughness <= 0.0 ? 0.0 : 0.5 * log2(sampleSolidAngle / texelSolidAngle);
108-
sourceLod = clamp(sourceLod, 0.0, maxSourceLod);
109-
vec3 sampleColor = textureLod(m_EnvMap, L, sourceLod).rgb;
92+
vec3 sampleColor = texture(m_EnvMap, L).rgb;
11093
prefilteredColor += sampleColor * NdotL;
11194
totalWeight += NdotL;
11295
}

0 commit comments

Comments
 (0)