Skip to content

Commit a43a423

Browse files
committed
Bit o' cleaning plus added a deffault toon shader
1 parent 0839688 commit a43a423

3 files changed

Lines changed: 14 additions & 32 deletions

File tree

Blobtory/Scripts/game/SceneBuilder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from direct.interval.LerpInterval import LerpPosInterval
1+
from direct.interval.LerpInterval import LerpPosInterval, Shader
22
from direct.interval.MetaInterval import Sequence
33
from panda3d.core import AmbientLight, DirectionalLight, PTAFloat
44

@@ -20,6 +20,12 @@ def SetupScene(self):
2020
sphere = self.base.loader.loadModel("assets/models/icosphere")
2121
sphere.reparentTo(self.base.render)
2222
sphere.setScale(100)
23+
24+
sphere.setShader(Shader.load(Shader.SL_GLSL,
25+
vertex="assets/shaders/defaults/default.vert",
26+
fragment="assets/shaders/defaults/default.frag"))
27+
sphere.setTexture(self.base.loader.loadTexture("assets/textures/ramps/rampToonLight.png"))
28+
2329
startInterval = LerpPosInterval(sphere, 1, (0, -200, 600), (0, 200, 600), blendType='easeInOut')
2430
endInterval = LerpPosInterval(sphere, 1, (0, 200, 600), (0, -200, 600), blendType='easeInOut')
2531
Sequence(startInterval, endInterval).loop()

assets/shaders/defaults/default.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ void main() {
2121
if (p3d_LightSource[0].position.w != 0) lightDir -= viewspacePos;
2222
lightDir = normalize(-lightDir);
2323

24-
float lambertian = max(dot(lightDir, normal), 0.0);
24+
float lambertian = (dot(lightDir, normal)+1)*0.5;
2525
lambertian = texture(p3d_Texture0, vec2(lambertian, 0.5)).x;
2626

27-
outputColor = vec4(lambertian)*vec4(1, 0.5, 0.5, 1);
27+
outputColor = vec4(lambertian)*vec4(1, 0.5, 0.5, 1)+vec4(0.1,0.05,0.05,1);
2828
}

assets/shaders/planets/planet.frag

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,15 @@ float textureProjSoft(sampler2DShadow tex, vec4 uv, float bias, float blur) {
4949
return result/13.0;
5050
}
5151

52-
//float shadowCoef(vec4 vPos, sampler2DShadow shadowMap, mat4 shadowViewMatrix) {
53-
// int index = 3;
54-
// // find the appropriate depth map to look up in
55-
// // based on the depth of this fragment
56-
// if(gl_FragCoord.z < far_d.x) index = 0;
57-
// else if(gl_FragCoord.z < far_d.y) index = 1;
58-
// else if(gl_FragCoord.z < far_d.z) index = 2;
59-
//
60-
// // transform this fragment's position from view space to
61-
// // scaled light clip space such that the xy coordinates
62-
// // lie in [0;1]. Note that there is no need to divide by w
63-
// // for othogonal light sources
64-
// vec4 shadow_coord = shadowViewMatrix*vPos;
65-
// // set the current depth to compare with
66-
// shadow_coord.w = shadow_coord.z;
67-
//
68-
// // tell glsl in which layer to do the look up
69-
// shadow_coord.z = float(index);
70-
//
71-
// // let the hardware do the comparison for us
72-
// return shadow2DArray(shadowMap, shadow_coord).x;
73-
//}
52+
7453

7554
void main() {
7655
vec3 illumLightSum = vec3(0);
7756
vec3 normal = normalize(primNormal);
7857

79-
//diffuseColor = p3d_Material.diffuse.xyz;
80-
//specStrength = p3d_Material.specular.x;
81-
8258
for (int i = 0; i < p3d_LightSource.length(); i++) {
8359
float shadowScale = 1;
84-
//shadowScale = textureProj(p3d_LightSource[i].shadowMap, shadow_uv[i]);
60+
shadowScale = textureProj(p3d_LightSource[i].shadowMap, shadow_uv[i]);
8561
//shadowScale = textureProjSoft(p3d_LightSource[i].shadowMap, shadow_uv[i], 0.0001, 0.001);
8662
vec3 lightDir = p3d_LightSource[i].position.xyz;
8763
if (p3d_LightSource[i].position.w != 0) {
@@ -93,7 +69,7 @@ void main() {
9369
lightDir = normalize(-lightDir);
9470

9571
float lambertian = max(dot(lightDir, normal), 0.0);
96-
//lambertian = texture(p3d_Texture1, vec2(lambertian, 0.5)).x;
72+
//lambertian = texture(p3d_Texture1, vec2(lambertian, 0.5)).x; // --Adds diffuse toon shading
9773

9874
float specular = 0.0;
9975

@@ -104,15 +80,15 @@ void main() {
10480
vec3 halfDir = normalize(lightDir + viewDir);
10581
float specAngle = max(dot(halfDir, normal), 0.0);
10682
specular = pow(specAngle, p3d_Material.shininess);
107-
//specular = texture(p3d_Texture1, vec2(specular, 0.5)).x;
83+
//specular = texture(p3d_Texture1, vec2(specular, 0.5)).x; // --Adds specular toon shading
10884
}
10985
vec3 illumDiffuse = diffuseColor * lambertian * p3d_LightSource[i].color.xyz / (distance);
11086
vec3 illumSpecular = diffuseColor * specStrength * specular * p3d_LightSource[i].color.xyz / (distance);
11187
illumLightSum += (illumDiffuse+illumSpecular)*shadowScale;
11288
}
11389

11490
vec3 colorGammaCorrected = pow(p3d_LightModel.ambient.xyz*diffuseColor+illumLightSum, vec3(0.49504950495));
115-
//colorGammaCorrected = texture(p3d_Texture1, vec2(length(colorGammaCorrected.xyz), 0.5), 0).x*colorGammaCorrected;
91+
//colorGammaCorrected = texture(p3d_Texture1, vec2(length(colorGammaCorrected.xyz), 0.5), 0).x*colorGammaCorrected; // - Adds brightness toon shading
11692

11793
// use the gamma corrected color in the fragment0
11894
outputColor = vec4(colorGammaCorrected, 1);

0 commit comments

Comments
 (0)