gdkchan / SPICA

Experimental H3D tool
The Unlicense
95 stars 46 forks source link

Shader Issue #7

Closed Xanatus closed 6 years ago

Xanatus commented 7 years ago

Some Pokemon seem to have a problem with shading of some alpha blended textures. (mostly eyes on eg. Venusaur ...)

I debugged the Shader (pre latest update) and figured the problem comes from Stage.Combiner.ColorCombiner == (1)Modulate

In your shader, if you replace

switch (Combiners[Stage].ColorCombine) case 1: Output.rgb = ColorArgs[0].rgb * ColorArgs[1].rgb; break;

with:

case 1: Output.rgb = ColorArgs[0].rgb; break;

Or just enforce Stage.Combiner.ColorCombiner to never be Modulate but Replace instead.

This way the problem is fixed for all Pokemon, but may cause problems with other games that I haven't checked. Just wanted to let you know. Maybe you have a better fix for this.

[Edit] Just noticed I was testing without lighting. Seems with lights it breaks your cell shading, so this is not a good fix :/ A proper fix would possibly be to only adjust ColorCombiner when certain alpha blend conditions are met.

gdkchan commented 7 years ago

A regression on UV transforms was fixed on commit c7e24e8 (and it affects texture mapping on some 'mons). Can you retest please?

Xanatus commented 7 years ago

capture

Still not fixed. I doubt this has anything to do with the transforms. And lights also do not affect this problem. It seems more like an issue with how textures / colors are getting combined.

Also there is a new bug in the latest version that prevents you from loading a new model after you already loaded one.

I have another question for you: do you have any idea how the visibility animations are supposed to work? It seems visibility nodes get stored as bones in model.Skeleton but in no particular order. Model submeshes have no links to these bones/nodes. How are you supposed to link those nodes to the corresponding submeshes for the animation?

gdkchan commented 7 years ago

Issue should be fixed now, please retest if possible.

Also, you need to enable object space normal maps to make shadows show up correctly on the model, to do this go to Options > Renderer > Normal map and click on Object space.

I don't have problems opening more models after opening a model, you can open a separate issue for this if you want, with steps to reproduce and affected file.

I don't know exactly how visibility animations works on Pokémon Sun/Moon because I didn't implemented it yet, but I guess that it references mesh names to show or hide then (at least its how it used to be on BCH).

Meshes references to the skeleton are inside the vertex buffer, it's the bone index and bone weight attributes (the bone index referencing the bone indices list inside the SubMesh, and each entry on the bone indices list references a bone on the Skeleton). It's done this way 'cause each submesh can only have a limited num of bones (20) because they are sent to the shader as uniforms and the amount of uniforms you have is pretty limited. So the bones referenced by the bone indices list are sent to the gpu, and the bone index attribute references the entries on the bone indices list. And bone indices references bones on the skeleton, in pratice what is sent is the transformation matrix for the bone itself.

Example:

Skeleton: [0] - Root [1] - Waist [2] -UpperBody [3] - Head ... - A lot of other bones (max here is "unlimited")

Bone indices list: [0] - 1 (reference to bone Waist) [1] - 2 (reference to bone UppderBody) ... (max here is 20)

Random bone index attribute on the vertex buffer: [0] - 1 (references index 1 on Bone list, which is UpperBody) ... (max here is 4, or 1 if you use rigid skinning)

Xanatus commented 7 years ago

You fixed it for venusaur, but the way you fixed it broke many other pokemon. Namely all with effects like flames (eg. chamander) and stuff that uses multiple colors so better revert this commit.

The problem with opening files still exists. I am not able to load any new model after I loaded any pokemon into Spica. Merging works, though.

How to reproduce:

  1. Load Pokemon (eg. bulbasaur). Doesn't matter if you load it with textures/animations or without.
  2. Try to load another pokemon (eg. Bulbasaur again, or pikachu or whatever)
  3. Empty screen :-(

About visibility animations:

All the pokemon i tried with (eg. Decidueye, Index: 1035 uses a lot of visible animations during attack animation) do not map with the bone indicies.

Visibility Bones are always at the end of the Skeleton list and parented to the root bone: They share name syntax like this: [rootbonename][unknownid - maybe alt form?][BoneName]

Eg.:

Bone Index 122: pm0843_00_HeadSkin Bone Index 123: pm0843_00_ArrowSkin Bone Index 124: pm0843_00_BeakSkin

Nowhere in the bone indices of the submeshes of this pokemon will anything reference these bones. If it was like that before than it appears to have changed with sun and moon.

If you have any other idea, any help would be appreciated because i try to get this to work for some time now :P

gdkchan commented 7 years ago

Broken flame effects were already broken before I commited the fix, it's not related. in fact it's broken since I started to implement the shader generator I believe. This effect relies on stencil testing to draw the flames and requires the meshes to be draw in the correct order to work, the order the meshes are stored on the file is not the order it is supposed to be drawn (idk why), I added a hack to make it work before but after I started to change parts of the rendering logic I broke it. It's easy to fix but I'm looking into a "real" fix. I can already draw it more or less correctly with OR/AS BCHs by rendering on the meshes layer order (0, 1, 2, 3) but not on Sun/Moon before I commit it.

About the "Skin" bones yea, they are not referenced, I don't know what they are supposed to do on the models, but they are probably related to the visibility anims, I'll need to check those anims again later.

I tried reproducing the issue you had trying to open more files and I still can't reproduce it, I tried with different settings but all the times it worked fine. Maybe you can track down the exact commit the regression happened so I can have a clue of what broke it?

gdkchan commented 7 years ago

Broken effects (Pokémon flames) should be fixed now on Sun/Moon and OR/AS.

Xanatus commented 7 years ago

The problem with reloading model still persists. It's really weired. I think it started happening with shader generator impl pt 1. It's weired that you can't reproduce it. I have this problem every time no matter what model I'm using. I tried but it's hard to debug, too. Looks like everything gets disposed and reloaded fine. Rendering loop is getting called, too. All the data is there... Grid and gizmo renders fine, Mesh is invisible for no obvious reason :/

It's most likely a shader/material problem but I can't figure it out.

Here is another bug for you:

Some pokemon use TexUnitID of 5 while you only handle 0 - 4. (they still did render fine pre shader generator)

Now with shader gen, they throw a shader compile exception. (Although I don't really know if the crash is related to the TexUnitID > 4 problem)

Anyway, an example of such a pokemon is SuMo Gengar (Mega), Model Index: 0140, if you wanna have a look at this.

Xanatus commented 7 years ago

Alright I found a fix for my problem. Reinitilizing the render engine fixed it for me. On Open:

                    if (!MergeMode)
                    {
                        SceneData = null;
                        Renderer.DeleteAll();
                        Renderer.Dispose();
                        Renderer = new RenderEngine(Viewport.Width, Viewport.Height);
                    }
Xanatus commented 7 years ago

Here are some more problem. The texture color issue seems to be fixed in almost all case, but there are still pokemon with problems. eg. Exeggutor (Index: 0150).

capture

Also your render order fix does not work in all cases. Eg. Haunter (Index: 0138) has both Iris and Eye on layer 1.

capture2

Sorry for bringing up all this issues. You're probably annoyed already but I'm just trying to help. ;-)

gdkchan commented 7 years ago

I fixed the compilation error on Mega Gengar, through I think it still isn't displayed correct. Also "fixed" something else thay may fix your problem of the model don't showing up the 2nd time you open something (I guess it won't, but it's worth a try anyway). Will start looking the other issues now.

gdkchan commented 7 years ago

Reopening since the original eye issue is still present.

Xanatus commented 7 years ago

Just tried your new version. You fixed my reloading issue. Awesome find :-)

Xanatus commented 7 years ago

And yes. Mega Gengar is kinda broke. Looked better in the old SPICA version pre shader generator. But yeah, he is kinda special, too. His red bottom is supposed to be animated with some weired smoke effects and his model has a weired cube geometry underneith him with a "megagengar_Mask" material that I have no idea what it's purpose could be. And all his sub meshes usees TexUnitSource of 5 for second texture. whats that? maybe a 3d texture?

gdkchan commented 7 years ago

New commit should fix some issues.

About the Pokémon you mentioned:

Also I don't know what those indexes you mentioned means. For example you said that haunter is index "0138", but his Pokédex number is 0093 and the file is 01234. It's easier if you just add the file number imo.

Only Pokémon that are know to have issues now are the ones that uses billboards.

gdkchan commented 6 years ago

The last know issue (Pokémon billboard) was fixed with support for shader translation to glsl (you need to import the original game shader from the bch for it to work).