Skip to content

Commit c14700a

Browse files
1 parent f97553a commit c14700a

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

Assets/Shaders/VoxelShader.hlsl

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,73 @@ PSInput VS(VSInput input)
3737

3838
float4 PS(PSInput input) : SV_TARGET
3939
{
40-
float4 col = texture0.Sample(sampler0, input.uv);
41-
float3 diffuse = dot(normalize(input.normal), -normalize(float3(0, -1, 0)));
40+
// Sample the base color texture
41+
float4 baseColor = texture0.Sample(sampler0, input.uv);
4242

43-
diffuse = max(diffuse, float3(0.255, 0.295, 0.3255));
43+
// Normalize the normal vector
44+
float3 normal = normalize(input.normal);
4445

45-
return col * float4(diffuse, 1);
46-
}
46+
// Define light direction (from above)
47+
float3 lightDirection = normalize(float3(0.0f, -1.0f, 0.0f));
48+
49+
// Calculate the dot product between normal and light direction
50+
float NdotL = saturate(dot(normal, -lightDirection));
51+
52+
// Toon shading: quantize the lighting to create discrete steps
53+
const int toonLevels = 3; // Number of shading levels
54+
float quantized = floor(NdotL * toonLevels) / (toonLevels - 1);
55+
56+
// Ensure quantized value is within [0, 1]
57+
quantized = saturate(quantized);
58+
59+
// Apply the quantized lighting to the base color
60+
float3 finalColor = baseColor.rgb * quantized;
61+
62+
// Increase saturation by blending with the base color
63+
float saturationAmount = 1.5f; // Adjust for more or less saturation
64+
finalColor = lerp(finalColor, baseColor.rgb, (saturationAmount - 1.0f) / saturationAmount);
65+
66+
// Return the final color with the original alpha
67+
return float4(finalColor, baseColor.a);
68+
}
69+
//float4 PS(PSInput input) : SV_TARGET
70+
//{
71+
// // Sample the base color texture
72+
// float4 baseColor = texture0.Sample(sampler0, input.uv);
73+
74+
// // Normalize the interpolated normal
75+
// float3 normal = normalize(input.normal);
76+
77+
// // Calculate view direction
78+
// float3 viewDir = normalize(Camera - input.worldpos);
79+
80+
// // Define light properties
81+
// float3 lightDirection = normalize(float3(0.5f, -1.0f, -0.5f)); // Directional light coming from above
82+
// float3 lightColor = float3(1.0f, 1.0f, 1.0f);
83+
// float ambientStrength = 0.2f;
84+
// float3 ambientColor = float3(1.0f, 1.0f, 1.0f);
85+
86+
// // Ambient lighting
87+
// float3 ambient = ambientStrength * ambientColor;
88+
89+
// // Diffuse lighting
90+
// float diffuseIntensity = saturate(dot(normal, -lightDirection));
91+
// float3 diffuse = diffuseIntensity * lightColor;
92+
93+
// // Specular lighting
94+
// float3 reflectDir = reflect(lightDirection, normal);
95+
// float specularStrength = 0.5f;
96+
// float shininess = 32.0f;
97+
// float spec = pow(saturate(dot(viewDir, reflectDir)), shininess);
98+
// float3 specular = specularStrength * spec * lightColor;
99+
100+
// // Rim lighting
101+
// float rimFactor = 1.0f - saturate(dot(normal, viewDir));
102+
// rimFactor = pow(rimFactor, 4.0f);
103+
// float3 rimColor = float3(0.5f, 0.5f, 1.0f) * rimFactor;
104+
105+
// // Combine all lighting components
106+
// float3 finalColor = (ambient + diffuse + specular) * baseColor.rgb + rimColor;
107+
108+
// return float4(finalColor, baseColor.a);
109+
//}

0 commit comments

Comments
 (0)