Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozuchowskiPS committed May 17, 2020
1 parent 160ef35 commit 5c1dd46
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea/
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# ss-shaders
# ss-shaders

Custom Star Sonata 2 ship shaders which makes all ships to be illuminated from the top, which gives them "C1" / sprite feeling.

#Installation
Download [mod package](/amorek/name/releases/latest/download/spritelike-shaders-1-0.zip) into Star Sonata 2 "Content" directory.

#Known Issues
* Lion ship does not use ship shader (game bug)
* Some stations appear to be black (base model has faces pointing to it's inside)


#Screenshots
!(/images/Screenshot_1.png)
!(/images/Screenshot_2.png)
!(/images/Screenshot_3.png)
!(/images/Screenshot_4.png)
Binary file added images/Screenshot_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Screenshot_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Screenshot_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Screenshot_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added releases/spritelike-shaders-1-0.zip
Binary file not shown.
67 changes: 67 additions & 0 deletions src/shaders/ShipMaterialP2.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#define EFFECT_MAX_LIGHT_COUNT 8

sampler2D ColoredTextureSampler : register(s0);
sampler2D NormalMapSampler : register(s1);
sampler2D EnvMapSampler : register(s2);

float3 LightPositions[EFFECT_MAX_LIGHT_COUNT];
float LightAtts[EFFECT_MAX_LIGHT_COUNT];
float3 LightColors[EFFECT_MAX_LIGHT_COUNT];
float3 SpecularColors[EFFECT_MAX_LIGHT_COUNT];
float3 AmbientColor;
float4 DiffuseTint;
float SpecularExponent, LCount, DoSphereMapping;
bool UseNormalMap;

static const float3 lDir = float3(0,0,1);


float3 getLightContribution(float3 Normal)
{
float diffuse = saturate(dot(Normal, lDir));
float3 Reflect = normalize(4.0 * diffuse * Normal - lDir);
float specFac = clamp(dot(Reflect, lDir),0, 0.97);
float specular = pow(specFac, SpecularExponent);

return (diffuse + specular);
}

float4 pixelMain
(
float2 TexCoords : TEXCOORD0,
float3 View : TEXCOORD1,
float3 Normal : TEXCOORD2,
float3 Tangent : TEXCOORD3,
float3 Binormal : TEXCOORD4,
float3 WPos : TEXCOORD5,
float4 Misc : TEXCOORD6,
float4 Misc2 : TEXCOORD7
)
: COLOR0
{
if (UseNormalMap) {
float4 sample = tex2D(NormalMapSampler, TexCoords);
float3 peturbation = sample.xyz - float3(0.5, 0.5, 0.5);
Normal = float3(
peturbation.x * Tangent -
peturbation.y * Binormal +
peturbation.z * Normal);
}
/* Interpolated vertex normals might not be normalized. */
Normal = normalize(Normal);

float4 albedoColor = tex2D(ColoredTextureSampler, TexCoords) * DiffuseTint;

if(DoSphereMapping > 0.5)
{
float2 refCoords = reflect(View, Normal).xy * 0.5;
albedoColor = lerp(albedoColor, tex2D(EnvMapSampler, refCoords), 0.5);
}

float3 finalLightColor = getLightContribution(Normal);

float4 finalColor = saturate(albedoColor * float4(finalLightColor.xyz, 1.0));
finalColor.a = saturate(DiffuseTint.a);

return finalColor;
}
67 changes: 67 additions & 0 deletions src/shaders/ShipMaterialP3.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#define EFFECT_MAX_LIGHT_COUNT 8

sampler2D ColoredTextureSampler : register(s0);
sampler2D NormalMapSampler : register(s1);
sampler2D EnvMapSampler : register(s2);

float3 LightPositions[EFFECT_MAX_LIGHT_COUNT];
float LightAtts[EFFECT_MAX_LIGHT_COUNT];
float3 LightColors[EFFECT_MAX_LIGHT_COUNT];
float3 SpecularColors[EFFECT_MAX_LIGHT_COUNT];
float3 AmbientColor;
float4 DiffuseTint;
float SpecularExponent, LCount, DoSphereMapping;
bool UseNormalMap;

static const float3 lDir = float3(0,0,1);


float3 getLightContribution(float3 Normal)
{
float diffuse = saturate(dot(Normal, lDir));
float3 Reflect = normalize(4.0 * diffuse * Normal - lDir);
float specFac = clamp(dot(Reflect, lDir),0, 0.97);
float specular = pow(specFac, SpecularExponent);

return (diffuse + specular);
}

float4 pixelMain
(
float2 TexCoords : TEXCOORD0,
float3 View : TEXCOORD1,
float3 Normal : TEXCOORD2,
float3 Tangent : TEXCOORD3,
float3 Binormal : TEXCOORD4,
float3 WPos : TEXCOORD5,
float4 Misc : TEXCOORD6,
float4 Misc2 : TEXCOORD7
)
: COLOR0
{
if (UseNormalMap) {
float4 sample = tex2D(NormalMapSampler, TexCoords);
float3 peturbation = sample.xyz - float3(0.5, 0.5, 0.5);
Normal = float3(
peturbation.x * Tangent -
peturbation.y * Binormal +
peturbation.z * Normal);
}
/* Interpolated vertex normals might not be normalized. */
Normal = normalize(Normal);

float4 albedoColor = tex2D(ColoredTextureSampler, TexCoords) * DiffuseTint;

if(DoSphereMapping > 0.5)
{
float2 refCoords = reflect(View, Normal).xy * 0.5;
albedoColor = lerp(albedoColor, tex2D(EnvMapSampler, refCoords), 0.5);
}

float3 finalLightColor = getLightContribution(Normal);

float4 finalColor = saturate(albedoColor * float4(finalLightColor.xyz, 1.0));
finalColor.a = saturate(DiffuseTint.a);

return finalColor;
}

0 comments on commit 5c1dd46

Please sign in to comment.