So, I am working on using Environment Mapping for Reflections using 3D Textures in my game engine.
My code is based on the effect written by nVidia, accelerated using the DC's fast math functions:
http://http.developer.nvidia.com/CgTuto ... ter07.html
This nVidia function uses a fragment shader to look up the color of each texel within each primitive.
This is not possible using the DC's PVR, so my approach is to use a vertex "shader" to look up a 3D texture coordinate, so the hardware can interpolate the pixels of each texture per-vertex.
For my first implementation on DC, things actually look quite nice:
But things get strange at the boundaries between each texture in the reflected map:
I have 2 questions, maybe someone here can help.
1.) The Cube Map is currently using the Sky Box Textures.
____The Textures should actually be generated by using 6x Render-To-Texture to generate the Cube Map;
____This is not possible due to VRAM limitations.
____We need to downsample the Render-To-Texture from 1028x512 to something like 256x128.
____How do we read the Render-To-Texture from VRAM back into main RAM?
2.) The PVR is reported to support Environment Mapping.
____Can this be used to accelerate things here?
Environment Mapping - 3D Texturing on DC
- PH3NOM
- DC Developer
- Posts: 576
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
- BlueCrab
- The Crabby Overlord
- Posts: 5665
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Environment Mapping - 3D Texturing on DC
The pvr_ptr_t that you have for the texture you rendered to is a just a void*. You can use memcpy or whatever else to copy it back into main ram. Heck, you could just cast it to a more appropriate type (like uint16_t*) and use it directly, but you're probably better off copying it to main RAM if you're doing anything complex with it.
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: Environment Mapping - 3D Texturing on DC
Thanks BlueCrab, that really what I have figured. Any idea on how "Environment Mapping" is supposed to be supported by the PVR hardware?
Per-Vertex Reflections are expensive on the SH4 CPU, especially when compounding that on top of BSP Geometry, Model Geometry, Light Mapping, Shadow Mapping, Z-Clipping, Animations, SFX, etc.
In my engine, this map now hits ~15-20 FPS with all of the Graphic Options turned On with 2 Players and 4 Zombies on screen :
Per-Vertex Reflections are expensive on the SH4 CPU, especially when compounding that on top of BSP Geometry, Model Geometry, Light Mapping, Shadow Mapping, Z-Clipping, Animations, SFX, etc.
In my engine, this map now hits ~15-20 FPS with all of the Graphic Options turned On with 2 Players and 4 Zombies on screen :
- BlueCrab
- The Crabby Overlord
- Posts: 5665
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Environment Mapping - 3D Texturing on DC
I'm not aware of any sort of acceleration on the PVR for environment-mapping related calculations. I've seen no documentation to suggest there's any hardware there to do that at all.
I think any reports of the hardware supporting environment mapping are simply wrong beyond the ability to render to a texture or are incorrect extrapolations based on newer PowerVR hardware.
I think any reports of the hardware supporting environment mapping are simply wrong beyond the ability to render to a texture or are incorrect extrapolations based on newer PowerVR hardware.
Re: Environment Mapping - 3D Texturing on DC
Have you considered using spherical harmonics/irradiance maps for lambertian reflections instead?
Basically you compute a matrix M, so that you can get the color by multiplying n^T * M * n. The matrix M will be smaller than a whole cube map. This is done by approximating the cube map by spherical basis functions and turning this into a problem of solving the laplace equation instead. You can vary the quality of the reflection by varying the amount of basis functions. At 9 basis functions (coefficients for the matrix M) you will get 99% quality for diffuse reflections, you will also be able to interpolate over vertices instead of fragments. This won't work well for specular reflections (water), but if you have a low resolution cube map it will look terrible anyway..
Basically you compute a matrix M, so that you can get the color by multiplying n^T * M * n. The matrix M will be smaller than a whole cube map. This is done by approximating the cube map by spherical basis functions and turning this into a problem of solving the laplace equation instead. You can vary the quality of the reflection by varying the amount of basis functions. At 9 basis functions (coefficients for the matrix M) you will get 99% quality for diffuse reflections, you will also be able to interpolate over vertices instead of fragments. This won't work well for specular reflections (water), but if you have a low resolution cube map it will look terrible anyway..
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: Environment Mapping - 3D Texturing on DC
LOLz. Very interesting idea!
I never thought I would hear "spherical harmonics" and "Dreamcast" in the same sentence
I have believed that spherical harmonics is the understanding of how light bounces off of surfaces, thus indirectly lighting reflected surfaces.
Or am I confusing that with "Global Illumination" https://developer.nvidia.com/vxgi
And if I understand, your suggested method computes vertex color, not texture coordinate? That would look very rough indeed...
I never thought I would hear "spherical harmonics" and "Dreamcast" in the same sentence
I have believed that spherical harmonics is the understanding of how light bounces off of surfaces, thus indirectly lighting reflected surfaces.
Or am I confusing that with "Global Illumination" https://developer.nvidia.com/vxgi
And if I understand, your suggested method computes vertex color, not texture coordinate? That would look very rough indeed...
Re: Environment Mapping - 3D Texturing on DC
Explanations and comparison pictures here http://graphics.stanford.edu/papers/envmap/
This is basically a form of compression where the high frequency bits are left out, because it turns out they're not important in such a reflection, which is an integral that gathers brightness from various directions. And yeah, reflections are global illumination
This is basically a form of compression where the high frequency bits are left out, because it turns out they're not important in such a reflection, which is an integral that gathers brightness from various directions. And yeah, reflections are global illumination
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream