Views: 1,610,082 | Main | Rules/FAQ | Memberlist | Active users | Last posts | Calendar | Stats | Online users | Search | 11-23-24 08:05 AM |
Guest: |
0 users reading PICA fragment lighting | 1 bot |
Main - Reverse-engineering - PICA fragment lighting | Hide post layouts | New reply |
StapleButter |
| ||
Member blarg Level: 30 Posts: 43/184 EXP: 151395 Next: 14474 Since: 10-27-14 From: France Last post: 2650 days ago Last view: 2560 days ago |
So here's what we found so far.
Enabling lighting is done by writing 1 to 0x008F and 0 to 0x01C6 from what I have seen. Register 0x01C3 // bit 0-3?: 'lighting mode'
// bit 2-3: 'fresnel selector' // bit 4-7: ??? cleared when enabling lighting?? // bit 8-15: ??? unused??? // bit 16: enable primary shadow // bit 17: enable secondary shadow // bit 18: invert shadow // bit 19: enable shadow alpha // bit 22-23: 'bump selector' -- texture unit for bumpmapping // bit 24-25: 'shadow selector' -- texture unit for shadow mapping // bit 27: clamp highlights // bit 28-30: 'bump mode' -- 1 enables bumpmapping // bit 30: disable 'bump renorm' -- affects bumpmapping Register 0x01C4 // bit 0-7: disable shadows for lights 0-7
// bit 8-15: disable spot for lights 0-7 // bit 16: D0 (Diffuse 0) LUT disable // bit 17: D1 (Diffuse 1) LUT disable // bit 18: presumably SP (Specular) LUT disable (not exposed in Nintendo GL) // bit 19: presumably FR (Fresnel) LUT disable (not exposed in Nintendo GL) // bit 20-22: reflection LUT disable (presumably individual bits for R/G/B) // bit 23: ??? // bit 24-31: disable distance attenuation for lights 0-7 Not that I managed to enable anything that would give visual results, though. Maybe it needs the VS/GS to output normals to work? ____________________ blargSNES -- SNES emu for 3DS More cool stuff |
neobrain |
| ||
Member Normal user Level: 10 Posts: 5/17 EXP: 4240 Next: 174 Since: 11-15-14 Last post: 3315 days ago Last view: 2804 days ago |
Nice findings so far
If you haven't already, you should definitely read the publications "A Real-Time Configurable Shader Based on Lookup Tables" (Ohbuchi & Unno) and "Shading by Quaternion Interpolation" (Hast). Those two papers basically give away the whole algorithm used in hardware, and will give you a hint of what to look for. |
StapleButter |
| ||
Member blarg Level: 30 Posts: 45/184 EXP: 151395 Next: 14474 Since: 10-27-14 From: France Last post: 2650 days ago Last view: 2560 days ago |
Oh, thanks for the tip. Will probably explain why I didn't get results, I guess. ____________________ blargSNES -- SNES emu for 3DS More cool stuff |
StapleButter |
| ||
Member blarg Level: 30 Posts: 46/184 EXP: 151395 Next: 14474 Since: 10-27-14 From: France Last post: 2650 days ago Last view: 2560 days ago |
Oh also, I documented more of it over at 3dbrew. ____________________ blargSNES -- SNES emu for 3DS More cool stuff |
StapleButter |
| ||
Member blarg Level: 30 Posts: 48/184 EXP: 151395 Next: 14474 Since: 10-27-14 From: France Last post: 2650 days ago Last view: 2560 days ago |
0x01C5 -- LUT INDEXES
(this is mostly guessed, take with a grain of salt) X = offset within LUT 0x00XX -> Diffuse 0 0x01XX -> Diffuse 1 0x02XX -> ??? 0x03XX -> Fresnel 0x04XX -> Reflection Red? Blue? 0x05XX -> Reflection Green 0x06XX -> Reflection Blue? Red? 0x07XX -> ??? 0x08XX -> Light 0 specular 0x09XX -> Light 1 specular 0x0AXX -> Light 2 specular 0x0BXX -> Light 3 specular 0x0CXX -> Light 4 specular 0x0DXX -> Light 5 specular 0x0EXX -> Light 6 specular 0x0FXX -> Light 7 specular 0x10XX -> Light 0 distance attenuation 0x11XX -> Light 1 distance attenuation 0x12XX -> Light 2 distance attenuation 0x13XX -> Light 3 distance attenuation 0x14XX -> Light 4 distance attenuation 0x15XX -> Light 5 distance attenuation 0x16XX -> Light 6 distance attenuation 0x17XX -> Light 7 distance attenuation Distance attenuation LUTs confirmed. Data type seems to be signed 24bit int. 'specular' naming above is based off the 'SP' in NintendoGL uniform names. TODO: investigate (might also be 'spot') ____________________ blargSNES -- SNES emu for 3DS More cool stuff |
StapleButter |
| ||
Member blarg Level: 30 Posts: 49/184 EXP: 151395 Next: 14474 Since: 10-27-14 From: France Last post: 2650 days ago Last view: 2560 days ago |
Couldn't get no specular component to show up.
Any help is appreciated. More particularly, I have trouble grasping all of the more mathy and theoric shit. ____________________ blargSNES -- SNES emu for 3DS More cool stuff |
neobrain |
| ||
Member Normal user Level: 10 Posts: 10/17 EXP: 4240 Next: 174 Since: 11-15-14 Last post: 3315 days ago Last view: 2804 days ago |
Normmatt found some more info and uploaded it to https://gist.github.com/Normmatt/9893b46b1bca86af3fd4#file-pica_fragment_light . In particular, this section looks interesting:
Posted by that link This seems to confirm your findings in your post about LUTs. According to DMP's research papers, SP models a spotlight if the proper lookup function (namely -L*P) is used, so it should probably be renamed to "spotlight" indeed. Some further information on the LUTs: They take a one-dimensional index, which is user-configurable. The index is calculated from the set (N*H, V*H, L*N, -L*P, cos Phi), with P the spotlight direction, Phi "the angle between the projection of H onto the tangent plane and the tangent vector T". I suppose the LUT index is set up by PICA_REG_FRAG_LIGHT_LUTINPUT, i.e. GPU register 0x1D1 (this is pure speculation based on that register's name, though). Some of the vectors in these formulas are likely configured via GPU registers, while others are vertex shader outputs. In particular, the view vector V is given by the "view" output vertex attribute semantic, while the normal vector N and tangent vector T are calculated from the "quaternion" output vertex attribute semantic. H should simply be something like (V+N)/2 (or its normalization). The precise calculation of N and T happens by using the quaternion to transform the surface-local space into eyespace (which is really just a simple rotation, and hence can indeed be encoded in a unit quaternion). In surface-local space, N and T always take fixed values (e.g. N=(0,0,1) and T=(0,1,0)). Hence all required information about the eye-space values really is encoded in the quaternion. Side note: Quaternion-vector multiplication is a linear operation, hence to get per-fragment values of N and T it should be sufficient to linearly interpolate the quaternion. |
Main - Reverse-engineering - PICA fragment lighting | Hide post layouts | New reply |
Page rendered in 0.024 seconds. (2048KB of memory used) MySQL - queries: 28, rows: 77/77, time: 0.006 seconds. Acmlmboard 2.064 (2018-07-20) © 2005-2008 Acmlm, Xkeeper, blackhole89 et al. |