mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-11-03 16:39:01 -06:00 
			
		
		
		
	gl_rasterizer/lighting: implement lut input 5 (CP)
This commit is contained in:
		@@ -84,7 +84,7 @@ struct LightingRegs {
 | 
				
			|||||||
        NV = 2, // Cosine of the angle between the normal and the view vector
 | 
					        NV = 2, // Cosine of the angle between the normal and the view vector
 | 
				
			||||||
        LN = 3, // Cosine of the angle between the light and the normal vectors
 | 
					        LN = 3, // Cosine of the angle between the light and the normal vectors
 | 
				
			||||||
        SP = 4, // Cosine of the angle between the light and the inverse spotlight vectors
 | 
					        SP = 4, // Cosine of the angle between the light and the inverse spotlight vectors
 | 
				
			||||||
        CP = 5, // TODO: document and implement
 | 
					        CP = 5, // Cosine of the angle between the tangent and projection of half-angle vectors
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    enum class LightingBumpMode : u32 {
 | 
					    enum class LightingBumpMode : u32 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -534,18 +534,24 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
 | 
				
			|||||||
                "(1.0 - (surface_normal.x*surface_normal.x + surface_normal.y*surface_normal.y))";
 | 
					                "(1.0 - (surface_normal.x*surface_normal.x + surface_normal.y*surface_normal.y))";
 | 
				
			||||||
            out += "surface_normal.z = sqrt(max(" + val + ", 0.0));\n";
 | 
					            out += "surface_normal.z = sqrt(max(" + val + ", 0.0));\n";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // The tangent vector is not perturbed by the normal map and is just a unit vector.
 | 
				
			||||||
 | 
					        out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
 | 
				
			||||||
    } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
 | 
					    } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
 | 
				
			||||||
        // Bump mapping is enabled using a tangent map
 | 
					        // Bump mapping is enabled using a tangent map
 | 
				
			||||||
        LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)");
 | 
					        LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)");
 | 
				
			||||||
        UNIMPLEMENTED();
 | 
					        UNIMPLEMENTED();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        // No bump mapping - surface local normal is just a unit normal
 | 
					        // No bump mapping - surface local normal and tangent are just unit vectors
 | 
				
			||||||
        out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n";
 | 
					        out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n";
 | 
				
			||||||
 | 
					        out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Rotate the surface-local normal by the interpolated normal quaternion to convert it to
 | 
					    // Rotate the surface-local normal by the interpolated normal quaternion to convert it to
 | 
				
			||||||
    // eyespace.
 | 
					    // eyespace.
 | 
				
			||||||
    out += "vec3 normal = quaternion_rotate(normalize(normquat), surface_normal);\n";
 | 
					    out += "vec4 normalized_normquat = normalize(normquat);\n";
 | 
				
			||||||
 | 
					    out += "vec3 normal = quaternion_rotate(normalized_normquat, surface_normal);\n";
 | 
				
			||||||
 | 
					    out += "vec3 tangent = quaternion_rotate(normalized_normquat, surface_tangent);\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Gets the index into the specified lookup table for specular lighting
 | 
					    // Gets the index into the specified lookup table for specular lighting
 | 
				
			||||||
    auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input,
 | 
					    auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input,
 | 
				
			||||||
@@ -573,6 +579,23 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
 | 
				
			|||||||
            index = std::string("dot(light_vector, spot_dir)");
 | 
					            index = std::string("dot(light_vector, spot_dir)");
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        case LightingRegs::LightingLutInput::CP:
 | 
				
			||||||
 | 
					            // CP input is only available with configuration 7
 | 
				
			||||||
 | 
					            if (lighting.config == LightingRegs::LightingConfig::Config7) {
 | 
				
			||||||
 | 
					                // Note: even if the normal vector is modified by normal map, which is not the
 | 
				
			||||||
 | 
					                // normal of the tangent plane anymore, the half angle vector is still projected
 | 
				
			||||||
 | 
					                // using the modified normal vector.
 | 
				
			||||||
 | 
					                std::string half_angle_proj = half_angle +
 | 
				
			||||||
 | 
					                                              " - normal / dot(normal, normal) * dot(normal, " +
 | 
				
			||||||
 | 
					                                              half_angle + ")";
 | 
				
			||||||
 | 
					                // Note: the half angle vector projection is confirmed not normalized before the dot
 | 
				
			||||||
 | 
					                // product. The result is in fact not cos(phi) as the name suggested.
 | 
				
			||||||
 | 
					                index = "dot(" + half_angle_proj + ", tangent)";
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                index = "0.0";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input);
 | 
					            LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input);
 | 
				
			||||||
            UNIMPLEMENTED();
 | 
					            UNIMPLEMENTED();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user