mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Start of 3d renderer integration
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
cbuffer SceneConstants
|
||||
{
|
||||
float4x4 ViewProjection = float4x4(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
cbuffer ObjectConstants
|
||||
{
|
||||
float4x4 Transform;
|
||||
}
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float4 BaseColor = float4(1, 0, 1, 1);
|
||||
//float3 LightDir = float3(0, 1, 0);
|
||||
}
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float3 Position : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
};
|
||||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float3 WorldPosition : TEXCOORD0;
|
||||
float3 Normal : NORMAL;
|
||||
};
|
||||
|
||||
PS_IN VS(VS_IN input)
|
||||
{
|
||||
PS_IN output;
|
||||
|
||||
float4 worldPosition = mul(Transform, float4(input.Position, 1));
|
||||
|
||||
output.Position = mul(ViewProjection, worldPosition);
|
||||
output.WorldPosition = worldPosition.xyz / worldPosition.w;
|
||||
output.Normal = mul((float3x3)Transform, input.Normal);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
struct PS_OUT
|
||||
{
|
||||
float4 Color : SV_TARGET0;
|
||||
float4 Normal : SV_TARGET1;
|
||||
float4 Position : SV_TARGET2;
|
||||
};
|
||||
|
||||
PS_OUT PS(PS_IN input)
|
||||
{
|
||||
input.Normal = normalize(input.Normal);
|
||||
|
||||
float f = distance(input.Normal, input.Normal);
|
||||
|
||||
//float shading = dot(LightDir, input.Normal);
|
||||
//float shading = dot(LightDir, LightDir) + 1;
|
||||
//shading = clamp(shading, 0.0f, 1.0f);
|
||||
|
||||
//return float4(BaseColor.rgb * shading, 1.0f);
|
||||
|
||||
PS_OUT output = (PS_OUT)0;
|
||||
output.Color = BaseColor;
|
||||
output.Normal = float4(input.Normal, 1);
|
||||
output.Position = float4(input.WorldPosition, 1);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
#effect[VS=VS,PS=PS]
|
||||
@@ -0,0 +1,46 @@
|
||||
Texture2D Colors : register(t0);
|
||||
Texture2D<float3> Normals : register(t1);
|
||||
Texture2D Positions : register(t2);
|
||||
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float3 LightDir = float3(0, 1, 0);
|
||||
}
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float2 TexCoord : TEXCOORD;
|
||||
};
|
||||
|
||||
PS_IN VS(VS_IN input)
|
||||
{
|
||||
PS_IN output;
|
||||
|
||||
output.Position = float4(input.Position, 0, 1);
|
||||
output.TexCoord = input.TexCoord;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_IN input) : SV_TARGET
|
||||
{
|
||||
float4 color = Colors.Sample(Sampler, input.TexCoord);
|
||||
float3 normal = Normals.Sample(Sampler, input.TexCoord);
|
||||
|
||||
//float shading = dot(LightDir, normal) + 100;
|
||||
float shading = dot(float3(0, 1, 0), normal);
|
||||
shading = clamp(shading, 0.0f, 1.0f);
|
||||
|
||||
return float4(color.rgb * shading, 1);
|
||||
}
|
||||
|
||||
#effect[VS=VS,PS=PS]
|
||||
@@ -0,0 +1,52 @@
|
||||
Texture2D Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
|
||||
float ColorOffset = 0.5f;
|
||||
float AlphaOffset = 0.0f;
|
||||
float ColorScale = 0.5f;
|
||||
float AlphaScale = 1.0f;
|
||||
|
||||
float2 TextureSizeInPixels;
|
||||
}
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Transform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct PS_Input
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4 Color : COLOR;
|
||||
};
|
||||
|
||||
PS_Input VS(VS_Input input)
|
||||
{
|
||||
PS_Input output;
|
||||
|
||||
output.Position = mul(ViewProjection, mul(input.Transform, float4(input.Position, 0.0f, 1.0f)));
|
||||
output.Texcoord = input.UVTransform.xy + input.UVTransform.zw * input.Texcoord;
|
||||
output.Color = input.Color;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
float4 color = Texture.Sample(Sampler, input.Texcoord);
|
||||
|
||||
float4 final = float4(ColorOffset.xxx, AlphaOffset) + color * float4(ColorScale.xxx, AlphaScale);
|
||||
|
||||
return final;
|
||||
}
|
||||
|
||||
#effect[VS=VS, PS=PS]
|
||||
Reference in New Issue
Block a user