Skip to content

Commit

Permalink
Hackily add ppv to sceneNodes
Browse files Browse the repository at this point in the history
Now they can be previewed in the world viewer again.
  • Loading branch information
Purrspctiv committed May 25, 2024
1 parent 9528a6d commit d6856ca
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
21 changes: 19 additions & 2 deletions GUI/Types/Renderer/ScenePostProcessVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ public TonemapSettings()
ToeDenom = 0.3f;
WhitePoint = 4.0f;
}
public static TonemapSettings Linear()
{
return new TonemapSettings()
{
ExposureBias = 0.0f,
ShoulderStrength = 0.0f,
LinearStrength = 0.0f,
LinearAngle = 0.0f,
ToeStrength = 1.0f,
ToeNum = 1.0f,
ToeDenom = 1.0f,
WhitePoint = 2.83f,
};
}
public TonemapSettings(KVObject tonemapParams)
{
// no "Unchecked" equivalent for KVObject
Expand Down Expand Up @@ -127,15 +141,18 @@ public SceneTonemapController(Scene scene) : base(scene)

public override void Render(Scene.RenderContext context)
{
// what to do here? probably add to renderable mesh collection?
}

public override void Update(Scene.UpdateContext context)
{
}
}
class ScenePostProcessVolume : SceneNode
// make a parent TriggerSceneNode class?
class ScenePostProcessVolume : SceneNode//, IRenderableMeshCollection
{
//public List<RenderableMesh> RenderableMeshes { get; } = new(1);


public float FadeTime;
public bool UseExposure;

Expand Down
2 changes: 1 addition & 1 deletion GUI/Types/Renderer/Shaders/post_processing.frag
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void main()
vColor.rgb = ApplyColorCorrection(vColor.rgb);
}

// Not present in CS2, replaced by a Film Grain setting
// Not present in CS2, done in msaa_resolve_ps instead
//vColor.rgb = DitherColor(vColor.rgb);

outputColor = vColor;
Expand Down
82 changes: 51 additions & 31 deletions GUI/Types/Renderer/WorldLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,35 @@ static bool IsCamera(string cls)
}
}

if (IsCamera(classname))
{
var cameraName = entity.GetProperty<string>("cameraname") ?? entity.GetProperty<string>("targetname") ?? classname;
CameraNames.Add(cameraName);
CameraMatrices.Add(transformationMatrix);
}
else if (classname == "env_global_light")
{
//
}

var rendercolor = entity.GetProperty("rendercolor");
var renderamt = entity.GetProperty("renderamt")?.Data switch
{
float f => f,
_ => 1.0f,
};

var tint = rendercolor?.Data switch
{
byte[] col32 when rendercolor.Type == EntityFieldType.Color32 => new Vector4(col32[0], col32[1], col32[2], col32[3]) / 255.0f,
Vector3 vec3 => new Vector4(vec3 / 255.0f, renderamt),
_ => Vector4.One,
};

tint.X = MathF.Pow(tint.X, 2.2f);
tint.Y = MathF.Pow(tint.Y, 2.2f);
tint.Z = MathF.Pow(tint.Z, 2.2f);

if (classname == "post_processing_volume")
{
var exposureSpeedUp = entity.GetPropertyUnchecked<float>("exposurespeedup");
Expand Down Expand Up @@ -760,6 +789,8 @@ static bool IsCamera(string cls)
}
}

var postProcessHasModel = false;

if (model != null)
{
var postProcessModel = guiContext.LoadFileCompiled(model);
Expand All @@ -769,6 +800,19 @@ static bool IsCamera(string cls)
var ppModelResource = (Model)postProcessModel.DataBlock;

postProcess.ModelVolume = ppModelResource;

var ppModelNode = new ModelSceneNode(scene, ppModelResource, skin, optimizeForMapLoad: true)
{
Transform = transformationMatrix,
Tint = tint,
LayerName = layerName,
Name = model,
EntityData = entity,
};

postProcessHasModel = true; // for collision we'd need to collect phys data within the class

scene.Add(ppModelNode, false);
}
else
{
Expand All @@ -778,14 +822,19 @@ static bool IsCamera(string cls)
}

scene.PostProcessInfo.AddPostProcessVolume(postProcess);
continue;

// If the post process model exists, we hackily let it add the model to the scene nodes
if (!postProcessHasModel)
{
continue;
}
}
else if (classname == "env_tonemap_controller")
{
var minExposureTC = entity.GetPropertyUnchecked<float>("minexposure");
var maxExposureTC = entity.GetPropertyUnchecked<float>("minexposure");
var exposureRate = entity.GetPropertyUnchecked<float>("rate");
var isMasterTC = entity.GetPropertyUnchecked<bool>("master"); // master actually doesn't do anything
//var isMasterTC = entity.GetPropertyUnchecked<bool>("master"); // master actually doesn't do anything

var exposureSettings = new ExposureSettings()
{
Expand All @@ -807,35 +856,6 @@ static bool IsCamera(string cls)
}
}

if (IsCamera(classname))
{
var cameraName = entity.GetProperty<string>("cameraname") ?? entity.GetProperty<string>("targetname") ?? classname;
CameraNames.Add(cameraName);
CameraMatrices.Add(transformationMatrix);
}
else if (classname == "env_global_light")
{
//
}

var rendercolor = entity.GetProperty("rendercolor");
var renderamt = entity.GetProperty("renderamt")?.Data switch
{
float f => f,
_ => 1.0f,
};

var tint = rendercolor?.Data switch
{
byte[] col32 when rendercolor.Type == EntityFieldType.Color32 => new Vector4(col32[0], col32[1], col32[2], col32[3]) / 255.0f,
Vector3 vec3 => new Vector4(vec3 / 255.0f, renderamt),
_ => Vector4.One,
};

tint.X = MathF.Pow(tint.X, 2.2f);
tint.Y = MathF.Pow(tint.Y, 2.2f);
tint.Z = MathF.Pow(tint.Z, 2.2f);

if (model == null)
{
CreateDefaultEntity(entity, classname, transformationMatrix);
Expand Down

0 comments on commit d6856ca

Please sign in to comment.