Skip to content

Commit

Permalink
2.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Oct 14, 2023
1 parent e193b97 commit e7fda29
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "gg.generations"
version = "2.4.2-SNAPSHOT"
version = "2.4.3-SNAPSHOT"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public MaterialReference deserialize(JsonElement json, Type typeOfT, JsonDeseria
var cull = jsonObject.has("cull") ? CullType.from(jsonObject.getAsJsonPrimitive("cull").getAsString()) : CullType.Forward;
return new CullMaterialReference(texture, cull);
}
case "unlit" -> {
return new UnlitMaterialReference(texture);
}
default -> throw new JsonParseException("Material type %s invalid".formatted(type));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gg.generations.rarecandy.pokeutils;

public class UnlitMaterialReference extends DiffuseMaterialReference {
@Override
public String shader() {
return "unlit";
}

public UnlitMaterialReference(String texture) {
super(texture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ private AnimationNode[] fillAnimationNodesGfb(gg.generations.rarecandy.pokeutils
trueIndex++;

nodeIdMap.put(Objects.requireNonNull(boneAnim.name()).replace(".trmdl", ""), trueIndex);
System.out.println(trueIndex);

var node = animationNodes[trueIndex] = new AnimationNode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public static <T extends MeshObject> void create2(MultiRenderObject<T> objects,
var name = entry.getKey();
var buffer = ByteBuffer.wrap(entry.getValue());
var gfbAnim = gg.generations.rarecandy.pokeutils.tranm.Animation.getRootAsAnimation(buffer);

if(gfbAnim.anim() == null) continue;

animations.put(name, new Animation(name, gfbAnim, new Skeleton(skeleton)));
}

Expand Down Expand Up @@ -528,8 +531,12 @@ private Map<String, byte[]> readGfbAnimations(PixelAsset asset) {
.collect(Collectors.toMap(this::cleanAnimName, Map.Entry::getValue));
}

private String cleanAnimName(Map.Entry<String, byte[]> entry) {
public String cleanAnimName(Map.Entry<String, byte[]> entry) {
var str = entry.getKey();
return cleanAnimName(str);
}

public String cleanAnimName(String str) {
var substringEnd = str.lastIndexOf(".") == -1 ? str.length() : str.lastIndexOf(".");
var substringStart = str.lastIndexOf("/") == -1 ? 0 : str.lastIndexOf("/");
return str.substring(substringStart, substringEnd);
Expand Down
18 changes: 18 additions & 0 deletions src/library/resources/shaders/animated/solid.fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 450 core
#define ambientLight 0.6f

in vec2 texCoord0;

out vec4 outColor;

uniform sampler2D diffuse;

uniform float lightLevel;

void main() {
vec4 color = texture2D(diffuse, texCoord0);

if (color.a < 0.01) discard;

outColor = vec4(lightLevel, lightLevel, lightLevel, 1.0f) * color;
}
34 changes: 2 additions & 32 deletions src/library/resources/shaders/animated/transparent.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,16 @@
#define ambientLight 0.6f

in vec2 texCoord0;
in vec3 normal;
in vec3 toLightVector;
in vec3 toCameraVector;

out vec4 outColor;

uniform sampler2D diffuse;

uniform int intColor;
uniform float shineDamper;
uniform float reflectivity;
uniform float diffuseColorMix;
uniform float alpha;

vec3 intToColor() {
return vec3((intColor >> 16 & 255) / 255.0, (intColor >> 8 & 255) / 255.0, (intColor & 255) / 255.0);
}
uniform float lightLevel;

void main() {
vec4 color = texture2D(diffuse, texCoord0);

vec3 lightColor = intToColor();
vec3 pixelmonColor = mix(lightColor, vec3(1.0, 1.0, 1.0), diffuseColorMix);
vec3 unitNormal = normalize(normal);
vec3 unitLightVector = normalize(toLightVector);
vec3 lightDir = -unitLightVector;
vec3 unitToCameraVector = normalize(toCameraVector);

// Diffuse Lighting
float rawDiffuse = dot(unitNormal, unitLightVector);
float diffuse = max(rawDiffuse, ambientLight);
vec3 coloredDiffuse = diffuse * pixelmonColor;

// Specular Lighting
vec3 reflectedLightDir = reflect(lightDir, unitNormal);
float rawSpecularFactor = dot(reflectedLightDir, unitToCameraVector);
float specularFactor = max(rawSpecularFactor, 0.0f);
float dampedFactor = pow(specularFactor, shineDamper);
vec3 finalSpecular = dampedFactor * reflectivity * lightColor;

outColor = vec4(coloredDiffuse, 1.0f) * color + vec4(finalSpecular, 1.0f);
outColor = vec4(lightLevel, lightLevel, lightLevel, 1.0f) * color;
outColor.a = color.a;
}
47 changes: 47 additions & 0 deletions src/library/resources/shaders/animated/transparent_pbr.fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#version 450 core
#define ambientLight 0.6f

in vec2 texCoord0;
in vec3 normal;
in vec3 toLightVector;
in vec3 toCameraVector;

out vec4 outColor;

uniform sampler2D diffuse;

uniform int intColor;
uniform float shineDamper;
uniform float reflectivity;
uniform float diffuseColorMix;
uniform float alpha;

vec3 intToColor() {
return vec3((intColor >> 16 & 255) / 255.0, (intColor >> 8 & 255) / 255.0, (intColor & 255) / 255.0);
}

void main() {
vec4 color = texture2D(diffuse, texCoord0);

vec3 lightColor = intToColor();
vec3 pixelmonColor = mix(lightColor, vec3(1.0, 1.0, 1.0), diffuseColorMix);
vec3 unitNormal = normalize(normal);
vec3 unitLightVector = normalize(toLightVector);
vec3 lightDir = -unitLightVector;
vec3 unitToCameraVector = normalize(toCameraVector);

// Diffuse Lighting
float rawDiffuse = dot(unitNormal, unitLightVector);
float diffuse = max(rawDiffuse, ambientLight);
vec3 coloredDiffuse = diffuse * pixelmonColor;

// Specular Lighting
vec3 reflectedLightDir = reflect(lightDir, unitNormal);
float rawSpecularFactor = dot(reflectedLightDir, unitToCameraVector);
float specularFactor = max(rawSpecularFactor, 0.0f);
float dampedFactor = pow(specularFactor, shineDamper);
vec3 finalSpecular = dampedFactor * reflectivity * lightColor;

outColor = vec4(coloredDiffuse, 1.0f) * color + vec4(finalSpecular, 1.0f);
outColor.a = color.a;
}
13 changes: 13 additions & 0 deletions src/library/resources/shaders/animated/unlit.fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 450 core
#define ambientLight 0.6f

in vec2 texCoord0;

out vec4 outColor;

uniform sampler2D diffuse;

void main() {
vec4 color = texture2D(diffuse, texCoord0);
outColor = color;
}
30 changes: 20 additions & 10 deletions src/main/java/gg/generations/rarecandy/tools/gui/GuiPipelines.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ public class GuiPipelines {
.supplyUniform("viewMatrix", ctx -> ctx.uniform().uploadMat4f(ctx.instance().viewMatrix()))
.supplyUniform("modelMatrix", ctx -> ctx.uniform().uploadMat4f(ctx.instance().transformationMatrix()))
.supplyUniform("projectionMatrix", (ctx) -> ctx.uniform().uploadMat4f(projectionMatrix))
.supplyUniform("lightPosition", ctx -> ctx.uniform().uploadVec3f(new Vector3f(0, 2, 0)))
.supplyUniform("reflectivity", ctx -> ctx.uniform().uploadFloat(0.3f))
.supplyUniform("shineDamper", ctx -> ctx.uniform().uploadFloat(0.3f))
.supplyUniform("intColor", ctx -> ctx.uniform().uploadInt(0xFFFFFF))
.supplyUniform("diffuseColorMix", ctx -> ctx.uniform().uploadFloat(0.7f))
.supplyUniform("boneTransforms", ctx -> ctx.uniform().uploadMat4fs(ctx.instance() instanceof AnimatedObjectInstance instance ? instance.getTransforms() : AnimationController.NO_ANIMATION))
.supplyUniform("boneTransforms", ctx -> ctx.uniform().uploadMat4fs(ctx.instance() instanceof AnimatedObjectInstance instance ? instance.getTransforms() != null ? instance.getTransforms() : AnimationController.NO_ANIMATION : AnimationController.NO_ANIMATION))
.supplyUniform("diffuse", ctx -> {
ctx.object().getVariant(ctx.instance().variant()).getDiffuseTexture().bind(0);
ctx.uniform().uploadInt(0);
Expand All @@ -32,20 +27,35 @@ public class GuiPipelines {
material.blendType().disable();
});

private static final Pipeline.Builder PBR = new Pipeline.Builder(BASE)
.supplyUniform("lightPosition", ctx -> ctx.uniform().uploadVec3f(new Vector3f(0, 2, 0)))
.supplyUniform("reflectivity", ctx -> ctx.uniform().uploadFloat(0.3f))
.supplyUniform("shineDamper", ctx -> ctx.uniform().uploadFloat(0.3f))
.supplyUniform("intColor", ctx -> ctx.uniform().uploadInt(0xFFFFFF))
.supplyUniform("diffuseColorMix", ctx -> ctx.uniform().uploadFloat(0.7f));

public static final Pipeline STATIC = new Pipeline.Builder(BASE)
.shader(builtin("static/static.vs.glsl"), builtin("static/static.fs.glsl"))
.build();

public static final Pipeline ANIMATED = new Pipeline.Builder(BASE)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/animated.fs.glsl"))
public static final Pipeline.Builder LIGHT = new Pipeline.Builder(BASE)
.supplyUniform("lightLevel", ctx -> ctx.uniform().uploadFloat(RareCandyCanvas.getLightLevel()));

public static final Pipeline SOLID = new Pipeline.Builder(LIGHT)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/solid.fs.glsl"))
.build();

public static final Pipeline TRANSPARENT = new Pipeline.Builder(BASE)
public static final Pipeline TRANSPARENT = new Pipeline.Builder(LIGHT)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/transparent.fs.glsl"))
.build();

public static final Pipeline UNLIT = new Pipeline.Builder(BASE)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/unlit.fs.glsl"))
.build();


public static final Pipeline POKEMON_EYES = new Pipeline.Builder(BASE)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/animated.fs.glsl"))
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/animated_pbr.fs.glsl"))
.supplyUniform("boneTransforms", ctx -> ctx.uniform().uploadMat4fs(ctx.instance() instanceof AnimatedObjectInstance instance ? instance.getTransforms() : AnimationController.NO_ANIMATION))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void mouseReleased(MouseEvent e) {
}
else if (path.getParentPath() != null)
if (path.getParentPath().getLastPathComponent().toString().equals("animations")) {
PixelAssetTree.this.gui.handler.getCanvas().setAnimation(path.getLastPathComponent().toString().replace(".tranm", ""));
PixelAssetTree.this.gui.handler.getCanvas().setAnimation(path.getLastPathComponent().toString().replace(".tranm", "").replace(".gfbanm", ""));
} else if (path.getParentPath().getLastPathComponent().toString().equals("variants")) {
PixelAssetTree.this.gui.handler.getCanvas().setVariant(path.getLastPathComponent().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.github.weisj.darklaf.LafManager;
import gg.generations.rarecandy.renderer.model.material.PipelineRegistry;
import gg.generations.rarecandy.renderer.pipeline.Pipeline;
import org.lwjgl.opengl.awt.AWTGLCanvas;

import javax.swing.*;
import java.awt.*;
import java.util.function.Function;

public class PokeUtilsGui extends JPanel {

Expand Down Expand Up @@ -49,7 +47,11 @@ public PokeUtilsGui() {
}
});

PipelineRegistry.setFunction(s-> s.equals("transparent") ? GuiPipelines.TRANSPARENT : GuiPipelines.ANIMATED);
PipelineRegistry.setFunction(s-> switch(s) {
case "transparent"-> GuiPipelines.TRANSPARENT;
case "unlit" -> GuiPipelines.UNLIT;
default -> GuiPipelines.SOLID;
});

var renderLoop = new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

public class RareCandyCanvas extends AWTGLCanvas {
public static Matrix4f projectionMatrix;

private static float lightLevel = 0.6f;

public final Matrix4f viewMatrix = new Matrix4f();
public final List<AnimatedObjectInstance> instances = new ArrayList<>();
private final int scaleModifier = 0;
Expand All @@ -40,7 +43,16 @@ public class RareCandyCanvas extends AWTGLCanvas {

private MultiRenderObject<AnimatedMeshObject> loadedModel;
private AnimatedObjectInstance loadedModelInstance;
private static float previousLightLevel;

public static void setLightLevel(float lightLevel) {
previousLightLevel = RareCandyCanvas.lightLevel;
RareCandyCanvas.lightLevel = lightLevel;
}

static float getLightLevel() {
return lightLevel;
}

public RareCandyCanvas() {
super(defaultData());
Expand Down Expand Up @@ -88,7 +100,7 @@ public void initGL() {
GuiPipelines.onInitialize();
this.renderer = new RareCandy();

GL11C.glClearColor(60 / 255f, 63 / 255f, 65 / 255f, 1);
GL11C.glClearColor(lightLevel, lightLevel, lightLevel, 1);
GL11C.glEnable(GL11C.GL_DEPTH_TEST);

try (var is = Pipeline.class.getResourceAsStream("/models/grid.glb")) {
Expand All @@ -108,6 +120,9 @@ public void paintGL() {
if (loadedModelInstance != null) {
loadedModelInstance.transformationMatrix().identity().scale(loadedModel.scale);
}

if(lightLevel != previousLightLevel)

renderer.render(false, (System.currentTimeMillis() - startTime) / 16000);
swapBuffers();

Expand Down Expand Up @@ -154,7 +169,7 @@ private Pipeline getPokemonPipeline(String materialName) {
if (materialName.equals("transparent")) {
return GuiPipelines.TRANSPARENT;
} else {
return GuiPipelines.ANIMATED;
return GuiPipelines.SOLID;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Pipelines(Matrix4f projectionMatrix) {
});

this.animated = new Pipeline.Builder(base)
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/animated.fs.glsl"))
.shader(builtin("animated/animated.vs.glsl"), builtin("animated/animated_pbr.fs.glsl"))
.supplyUniform("boneTransforms", ctx -> ctx.uniform().uploadMat4fs(((AnimatedObjectInstance) ctx.instance()).getTransforms()))
.build();
}
Expand Down

0 comments on commit e7fda29

Please sign in to comment.