Skip to content

Commit e85f013

Browse files
committed
Not cleaned but now it may work on AMD
1 parent efa79ee commit e85f013

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

Blobtory/Scripts/Main.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from direct.interval.LerpInterval import LerpPosInterval
2-
from panda3d.core import loadPrcFile, loadPrcFileData, LPoint3f
2+
from panda3d.core import loadPrcFile, loadPrcFileData, LPoint3f, PointLight, Spotlight, PerspectiveLens
33
from direct.showbase.ShowBase import ShowBase, PTAFloat, AmbientLight, DirectionalLight, Shader, Texture, TextureStage, \
44
SamplerState, FrameBufferProperties, WindowProperties, GraphicsPipe, GraphicsOutput, NodePath
55

@@ -31,7 +31,7 @@ def __init__(self):
3131
myShader: Shader = Shader.load(Shader.SL_GLSL,
3232
vertex="assets/shaders/defaults/default.vert",
3333
fragment="assets/shaders/defaults/default.frag")
34-
sphere.setShader(myShader, 1)
34+
#sphere.setShader(myShader, 1)
3535
sphere.setScale(100)
3636
sphere.setPos((0,50,600))
3737

@@ -68,19 +68,25 @@ def __init__(self):
6868
alnp = self.render.attachNewNode(alight)
6969
self.render.setLight(alnp)
7070

71-
dlight1 = DirectionalLight('my dlight1')
72-
dlight1.setShadowCaster(True, 512, 512)
73-
#dlight1.show_frustum()
74-
dlnp1 = self.render.attachNewNode(dlight1)
75-
dlnp1.setPos(0,0,512)
76-
dlnp1.setHpr(0, 270, 0)
77-
self.render.setLight(dlnp1)
78-
79-
bmin, bmax = self.render.get_tight_bounds(dlnp1)
80-
size=128
71+
sun = DirectionalLight('TheSun')
72+
sun.setShadowCaster(True, 1024, 1024)
73+
#lens = PerspectiveLens()
74+
#lens.setFov(40)
75+
#sun.setLens(lens)
76+
#sun.attenuation = (0.0000000000000000001, 0., 0.)
77+
78+
sun.show_frustum()
79+
sun.set_color((1, 1, 1, 1))
80+
sunNodePath = self.render.attachNewNode(sun)
81+
sunNodePath.setPos(0, 200, 600)
82+
sunNodePath.lookAt(0,0,0)
83+
self.render.setLight(sunNodePath)
84+
85+
bmin, bmax = self.render.get_tight_bounds(sunNodePath)
86+
size=512
8187
bmin, bmax = LPoint3f(-size,0, -size), LPoint3f(size, size,size)
8288
print(bmin,bmax)
83-
lens = dlight1.get_lens(0)
89+
lens = sun.get_lens(0)
8490
lens.set_film_offset((bmin.xz + bmax.xz) * 0.5)
8591
lens.set_film_size(bmax.xz - bmin.xz)
8692
lens.set_near_far(bmin.y, bmax.y)
@@ -90,12 +96,12 @@ def __init__(self):
9096
(0,-100,600),(0,100,600))
9197
i.loop()
9298

93-
dlight2 = DirectionalLight('my dlight2')
94-
dlight2.setColor((0.05, 0.05, 0.05, 1))
95-
dlight2.setShadowCaster(True, 512, 512)
96-
dlnp2 = self.render.attachNewNode(dlight2)
97-
dlnp2.setHpr(0, 180, 0)
98-
self.render.setLight(dlnp2)
99+
# dlight2 = DirectionalLight('my dlight2')
100+
# dlight2.setColor((0.05, 0.05, 0.05, 1))
101+
# dlight2.setShadowCaster(True, 512, 512)
102+
# dlnp2 = self.render.attachNewNode(dlight2)
103+
# dlnp2.setHpr(0, 180, 0)
104+
# self.render.setLight(dlnp2)
99105

100106

101107
loadPrcFileData('', 'framebuffer-multisample 1')

assets/shaders/planets/planet.frag

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void main() {
8080
//diffuseColor = p3d_Material.diffuse.xyz;
8181
//specStrength = p3d_Material.specular.x;
8282

83-
for (int i = 0; i < p3d_LightSource.length; i++) {
83+
for (int i = 0; i < p3d_LightSource.length(); i++) {
8484
vec3 lightDir = p3d_LightSource[i].position.xyz;
8585
if (p3d_LightSource[i].position.w != 0) lightDir -= viewspacePos;
8686

@@ -102,10 +102,10 @@ void main() {
102102
specular = pow(specAngle, p3d_Material.shininess);
103103
specular = texture(p3d_Texture1, vec2(specular, 0.5)).x;
104104
}
105-
vec3 illumDiffuse = diffuseColor * lambertian * p3d_LightSource[i].color.xyz * 1 / distance;
106-
vec3 illumSpecular = diffuseColor * specStrength * specular * p3d_LightSource[i].color.xyz * 1 / distance;
107-
//illumLightSum += (illumDiffuse+illumSpecular)*textureProjSoft(p3d_LightSource[i].shadowMap, shadow_uv[i], 0.0001, 0.2);
108-
illumLightSum += (illumDiffuse+illumSpecular)*textureProj(p3d_LightSource[i].shadowMap, shadow_uv[i]);
105+
vec3 illumDiffuse = diffuseColor * lambertian * p3d_LightSource[i].color.xyz / (distance);
106+
vec3 illumSpecular = diffuseColor * specStrength * specular * p3d_LightSource[i].color.xyz / (distance);
107+
illumLightSum += (illumDiffuse+illumSpecular)*textureProjSoft(p3d_LightSource[i].shadowMap, shadow_uv[i], 0.0001, 0.01);
108+
//illumLightSum += (illumDiffuse+illumSpecular)*textureProj(p3d_LightSource[i].shadowMap, shadow_uv[i]);
109109
}
110110

111111
vec3 colorGammaCorrected = pow(p3d_LightModel.ambient.xyz*diffuseColor+illumLightSum, vec3(0.49504950495));

assets/shaders/planets/planet.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void main() {
5959
cam_pos = p3d_ViewMatrixInverse[3].xyz;
6060
cam_dir = -p3d_ViewMatrixInverse[2].xyz;
6161

62-
for (int i = 0; i < p3d_LightSource.length; i++) {
62+
for (int i = 0; i < p3d_LightSource.length(); i++) {
6363
shadow_uv[i] = p3d_LightSource[i].shadowViewMatrix * (p3d_ModelViewMatrix * vertex);
6464
}
6565
}

0 commit comments

Comments
 (0)