-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New iOS SDL3 + GLES 3.0 Angle Metal backend #2775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
de8f4a8
40ada42
97b02da
2802158
689194a
506a434
d27429a
258700c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,6 @@ in vec3 LocalPos; | |
|
|
||
|
|
||
| uniform samplerCube m_Texture; | ||
| #ifdef SH_COEF | ||
| uniform sampler2D m_ShCoef; | ||
| #endif | ||
| uniform vec2 m_Resolution; | ||
| uniform int m_FaceId; | ||
|
|
||
| const float sqrtPi = sqrt(PI); | ||
| const float sqrt3Pi = sqrt(3. / PI); | ||
|
|
@@ -30,80 +25,6 @@ const float sqrt15Pi = sqrt(15. / PI); | |
| uniform float m_RemapMaxValue; | ||
| #endif | ||
|
|
||
|
|
||
| vec3 getVectorFromCubemapFaceTexCoord(float x, float y, float mapSize, int face) { | ||
| float u; | ||
| float v; | ||
|
|
||
| /* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)] | ||
| * (+ 0.5f is for texel center addressing) */ | ||
| u = (2.0 * (x + 0.5) / mapSize) - 1.0; | ||
| v = (2.0 * (y + 0.5) / mapSize) - 1.0; | ||
|
|
||
|
|
||
| // Warp texel centers in the proximity of the edges. | ||
| float warpDenom = max(mapSize - 1.0, 1.0); | ||
| float a = (mapSize * mapSize) / (warpDenom * warpDenom * warpDenom); | ||
|
|
||
| u = a * u * u * u + u; | ||
| v = a * v * v * v + v; | ||
| //compute vector depending on the face | ||
| // Code from Nvtt : https://github.com/castano/nvidia-texture-tools/blob/master/src/nvtt/CubeSurface.cpp#L101 | ||
| vec3 o =vec3(0); | ||
| switch(face) { | ||
| case 0: | ||
| o= normalize(vec3(1., -v, -u)); | ||
| break; | ||
| case 1: | ||
| o= normalize(vec3(-1., -v, u)); | ||
| break; | ||
| case 2: | ||
| o= normalize(vec3(u, 1., v)); | ||
| break; | ||
| case 3: | ||
| o= normalize(vec3(u, -1., -v)); | ||
| break; | ||
| case 4: | ||
| o= normalize(vec3(u, -v, 1.)); | ||
| break; | ||
| case 5: | ||
| o= normalize(vec3(-u, -v, -1.)); | ||
| break; | ||
| } | ||
|
|
||
| return o; | ||
| } | ||
|
|
||
| float atan2(in float y, in float x) { | ||
| bool s = (abs(x) > abs(y)); | ||
| return mix(PI / 2.0 - atan(x, y), atan(y, x), s); | ||
| } | ||
|
|
||
| float areaElement(float x, float y) { | ||
| return atan2(x * y, sqrt(x * x + y * y + 1.)); | ||
| } | ||
|
|
||
| float getSolidAngleAndVector(float x, float y, float mapSize, int face, out vec3 store) { | ||
| /* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)] | ||
| (+ 0.5f is for texel center addressing) */ | ||
| float u = (2.0 * (x + 0.5) / mapSize) - 1.0; | ||
| float v = (2.0 * (y + 0.5) / mapSize) - 1.0; | ||
|
|
||
| store = getVectorFromCubemapFaceTexCoord(x, y, mapSize, face); | ||
|
|
||
| /* Solid angle weight approximation : | ||
| * U and V are the -1..1 texture coordinate on the current face. | ||
| * Get projected area for this texel */ | ||
| float x0, y0, x1, y1; | ||
| float invRes = 1.0 / mapSize; | ||
| x0 = u - invRes; | ||
| y0 = v - invRes; | ||
| x1 = u + invRes; | ||
| y1 = v + invRes; | ||
|
|
||
| return areaElement(x0, y0) - areaElement(x0, y1) - areaElement(x1, y0) + areaElement(x1, y1); | ||
| } | ||
|
|
||
| void evalShBasis(vec3 texelVect, int i, out float shDir) { | ||
| float xV = texelVect.x; | ||
| float yV = texelVect.y; | ||
|
|
@@ -124,56 +45,29 @@ void evalShBasis(vec3 texelVect, int i, out float shDir) { | |
| else shDir = sqrt15Pi * (x2 - y2) / 4.; | ||
| } | ||
|
|
||
| vec3 pixelFaceToV(int faceId, float pixelX, float pixelY, float cubeMapSize) { | ||
| vec2 normalizedCoords = vec2((2.0 * pixelX + 1.0) / cubeMapSize, (2.0 * pixelY + 1.0) / cubeMapSize); | ||
|
|
||
| vec3 direction; | ||
| if(faceId == 0) { | ||
| direction = vec3(1.0, -normalizedCoords.y, -normalizedCoords.x); | ||
| } else if(faceId == 1) { | ||
| direction = vec3(-1.0, -normalizedCoords.y, normalizedCoords.x); | ||
| } else if(faceId == 2) { | ||
| direction = vec3(normalizedCoords.x, 1.0, normalizedCoords.y); | ||
| } else if(faceId == 3) { | ||
| direction = vec3(normalizedCoords.x, -1.0, -normalizedCoords.y); | ||
| } else if(faceId == 4) { | ||
| direction = vec3(normalizedCoords.x, -normalizedCoords.y, 1.0); | ||
| } else if(faceId == 5) { | ||
| direction = vec3(-normalizedCoords.x, -normalizedCoords.y, -1.0); | ||
| } | ||
|
|
||
| return normalize(direction); | ||
| } | ||
|
|
||
| void sphKernel() { | ||
| int width = int(m_Resolution.x); | ||
| int height = int(m_Resolution.y); | ||
| vec3 texelVect=vec3(0); | ||
| float shDir=0.; | ||
| float weight=0.; | ||
| vec4 color=vec4(0); | ||
|
|
||
| int i=int(gl_FragCoord.x); | ||
|
|
||
| #ifdef SH_COEF | ||
| vec4 r=texelFetch(m_ShCoef, ivec2(i, 0), 0); | ||
| vec3 shCoef=r.rgb; | ||
| float weightAccum = r.a; | ||
| #else | ||
| vec3 shCoef=vec3(0.0); | ||
| float weightAccum = 0.0; | ||
| #endif | ||
|
|
||
| for(int y = 0; y < height; y++) { | ||
| for(int x = 0; x < width; x++) { | ||
| weight = getSolidAngleAndVector(float(x), float(y), float(width), m_FaceId, texelVect); | ||
| evalShBasis(texelVect, i, shDir); | ||
| color = texture(m_Texture, texelVect); | ||
| shCoef.x = (shCoef.x + color.r * shDir * weight); | ||
| shCoef.y = (shCoef.y + color.g * shDir * weight); | ||
| shCoef.z = (shCoef.z + color.b * shDir * weight); | ||
| weightAccum += weight; | ||
| } | ||
| vec3 shCoef=vec3(0.0); | ||
| float weightAccum = 0.0; | ||
|
|
||
| const uint SAMPLE_COUNT = 4096u; | ||
| for(uint sampleIndex = 0u; sampleIndex < SAMPLE_COUNT; sampleIndex++) { | ||
| vec4 xi = Hammersley(sampleIndex, SAMPLE_COUNT); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function |
||
| float z = 1.0 - 2.0 * xi.x; | ||
| float r = sqrt(max(0.0, 1.0 - z * z)); | ||
| float phi = 2.0 * PI * xi.y; | ||
| texelVect = vec3(r * cos(phi), z, r * sin(phi)); | ||
| evalShBasis(texelVect, i, shDir); | ||
| color = texture(m_Texture, texelVect); | ||
| shCoef.x = (shCoef.x + color.r * shDir); | ||
| shCoef.y = (shCoef.y + color.g * shDir); | ||
| shCoef.z = (shCoef.z + color.b * shDir); | ||
| weightAccum += 1.0; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -189,4 +83,4 @@ void sphKernel() { | |
|
|
||
| void main() { | ||
| sphKernel(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
shCoefTxtexture is created here but is never disposed. Since this baking process can be triggered multiple times, this will lead to a leak of GPU resources. You should callshCoefTx.getImage().dispose()at the end of the method.