4dsdev
Views: 1,609,285 Main | Rules/FAQ | Memberlist | Active users | Last posts | Calendar | Stats | Online users | Search 11-21-24 01:04 PM
Guest:

0 users reading PICA fragment lighting | 1 bot

Main - Reverse-engineering - PICA fragment lighting Hide post layouts | New reply


StapleButter
Posted on 12-21-14 10:55 PM (rev. 4 of 01-15-15 11:49 PM) Link | #69
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
Posted on 12-21-14 11:05 PM Link | #70
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
Posted on 12-21-14 11:15 PM Link | #72
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
Posted on 12-22-14 03:06 AM Link | #73
Oh also, I documented more of it over at 3dbrew.

____________________
blargSNES -- SNES emu for 3DS
More cool stuff

StapleButter
Posted on 01-16-15 12:20 AM (rev. 2 of 01-16-15 01:21 PM) Link | #80
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
Posted on 02-09-15 12:15 AM Link | #83
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
Posted on 05-17-15 01:47 PM (rev. 3 of 05-17-15 01:57 PM) Link | #128
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
0x002b8977: DW_TAG_enumerator [26]
0x002b8978: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_D0")
0x002b898d: DW_AT_const_value [DW_FORM_indirect] (0x00)

0x002b898f: DW_TAG_enumerator [26]
0x002b8990: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_D1")
0x002b89a5: DW_AT_const_value [DW_FORM_indirect] (0x01)

0x002b89a7: DW_TAG_enumerator [26]
0x002b89a8: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_FR")
0x002b89bd: DW_AT_const_value [DW_FORM_indirect] (0x03)

0x002b89bf: DW_TAG_enumerator [26]
0x002b89c0: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_RB")
0x002b89d5: DW_AT_const_value [DW_FORM_indirect] (0x04)

0x002b89d7: DW_TAG_enumerator [26]
0x002b89d8: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_RG")
0x002b89ed: DW_AT_const_value [DW_FORM_indirect] (0x05)

0x002b89ef: DW_TAG_enumerator [26]
0x002b89f0: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_RR")
0x002b8a05: DW_AT_const_value [DW_FORM_indirect] (0x06)

0x002b8a07: DW_TAG_enumerator [26]
0x002b8a08: DW_AT_name [DW_FORM_string] ("PICA_DATA_SAMPLER_SP")
0x002b8a1d: DW_AT_const_value [DW_FORM_indirect] (0x08)

0x002b8a1f: DW_TAG_enumerator [26]
0x002b8a20: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT0_SAMPLER_SP")
0x002b8a41: DW_AT_const_value [DW_FORM_indirect] (0x08)

0x002b8a43: DW_TAG_enumerator [26]
0x002b8a44: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT1_SAMPLER_SP")
0x002b8a65: DW_AT_const_value [DW_FORM_indirect] (0x09)

0x002b8a67: DW_TAG_enumerator [26]
0x002b8a68: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT2_SAMPLER_SP")
0x002b8a89: DW_AT_const_value [DW_FORM_indirect] (0x0a)

0x002b8a8b: DW_TAG_enumerator [26]
0x002b8a8c: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT3_SAMPLER_SP")
0x002b8aad: DW_AT_const_value [DW_FORM_indirect] (0x0b)

0x002b8aaf: DW_TAG_enumerator [26]
0x002b8ab0: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT4_SAMPLER_SP")
0x002b8ad1: DW_AT_const_value [DW_FORM_indirect] (0x0c)

0x002b8ad3: DW_TAG_enumerator [26]
0x002b8ad4: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT5_SAMPLER_SP")
0x002b8af5: DW_AT_const_value [DW_FORM_indirect] (0x0d)

0x002b8af7: DW_TAG_enumerator [26]
0x002b8af8: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT6_SAMPLER_SP")
0x002b8b19: DW_AT_const_value [DW_FORM_indirect] (0x0e)

0x002b8b1b: DW_TAG_enumerator [26]
0x002b8b1c: DW_AT_name [DW_FORM_string] ("PICA_DATA_FRAG_LIGHT7_SAMPLER_SP")
0x002b8b3d: DW_AT_const_value [DW_FORM_indirect] (0x0f)


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.027 seconds. (2048KB of memory used)
MySQL - queries: 28, rows: 77/77, time: 0.007 seconds.
[powered by Acmlm] Acmlmboard 2.064 (2018-07-20)
© 2005-2008 Acmlm, Xkeeper, blackhole89 et al.