Skip to content

Commit 0338b0c

Browse files
committed
Did a tiny bit of cleaning, still not done tho
1 parent 48798d6 commit 0338b0c

6 files changed

Lines changed: 66 additions & 83 deletions

File tree

Blobtory/Scripts/Main.py

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from direct.interval.LerpInterval import LerpPosInterval
2-
from panda3d.core import loadPrcFile, loadPrcFileData, LPoint3f, PointLight, Spotlight, PerspectiveLens
3-
from direct.showbase.ShowBase import ShowBase, PTAFloat, AmbientLight, DirectionalLight, Shader, Texture, TextureStage, \
4-
SamplerState, FrameBufferProperties, WindowProperties, GraphicsPipe, GraphicsOutput, NodePath
1+
from panda3d.core import loadPrcFile, loadPrcFileData
2+
from direct.showbase.ShowBase import ShowBase
53

64
from Blobtory.Scripts.Pipeline.WindowCreator import WindowCreator
5+
from Blobtory.Scripts.game.SceneBuilder import SceneBuilder
76

87
# Description:
98
# This is the main program, and should thus be kept clean,
@@ -14,87 +13,13 @@
1413
#
1514
# Copyright (c) 2020 Daniel Kierkegaard Andersen. All rights reserved.
1615
# https://github.com/Daxode/ComplexSoftwareProject
17-
from Blobtory.Scripts.planet_former.PlanetGenerator import PlanetGenerator
1816

1917

2018
class Main(ShowBase):
2119
def __init__(self):
2220
super().__init__()
2321
self.winCreator = WindowCreator(self, enableRP=False, isFullscreen=False)
24-
25-
self.planetGen: PlanetGenerator = PlanetGenerator(self.winCreator, 128, 500)
26-
self.planetGen.cubeformer.mouseTime.setData(PTAFloat([10, 0, 0, 1]))
27-
self.accept("a", self.planetGen.RegenPlanet)
28-
29-
sphere = self.loader.loadModel("assets/models/icosphere")
30-
sphere.reparentTo(self.render)
31-
myShader: Shader = Shader.load(Shader.SL_GLSL,
32-
vertex="assets/shaders/defaults/default.vert",
33-
fragment="assets/shaders/defaults/default.frag")
34-
#sphere.setShader(myShader, 1)
35-
sphere.setScale(100)
36-
sphere.setPos((0,50,600))
37-
38-
myToonLightTex = self.winCreator.base.loader.loadTexture(
39-
"assets/textures/ramps/rampToonLight.png")
40-
myToonLightTex.setWrapU(Texture.WM_clamp)
41-
myToonLightTex.setWrapV(Texture.WM_clamp)
42-
myToonLightTex.setMagfilter(SamplerState.FT_nearest)
43-
myToonLightTex.setMinfilter(SamplerState.FT_nearest)
44-
45-
stageToonLight = TextureStage("ToonLight")
46-
stageToonLight.setSort(1)
47-
sphere.setTexture(stageToonLight, myToonLightTex)
48-
49-
# winprops = WindowProperties(size=(512, 512))
50-
# props = FrameBufferProperties()
51-
# props.setRgbColor(1)
52-
# props.setAlphaBits(1)
53-
# props.setDepthBits(1)
54-
# LBuffer = self.graphicsEngine.makeOutput(
55-
# self.pipe, "offscreen buffer", -2,
56-
# props, winprops,
57-
# GraphicsPipe.BFRefuseWindow,
58-
# self.win.getGsg(), self.win)
59-
#
60-
# Ldepthmap = Texture()
61-
# LBuffer.addRenderTexture(Ldepthmap, GraphicsOutput.RTMBindOrCopy,
62-
# GraphicsOutput.RTPDepthStencil)
63-
64-
self.accept("v", self.bufferViewer.toggleEnable)
65-
66-
alight = AmbientLight('alight')
67-
alight.setColor((0.1, 0.1, 0.1, 1))
68-
alnp = self.render.attachNewNode(alight)
69-
self.render.setLight(alnp)
70-
71-
sun = DirectionalLight('TheSun')
72-
sun.setShadowCaster(True, 2048, 2048)
73-
74-
#sun.show_frustum()
75-
sun.set_color((1, 1, 1, 1))
76-
sunNodePath = self.render.attachNewNode(sun)
77-
sunNodePath.setPos(0, 200, 600)
78-
sunNodePath.lookAt(0,0,0)
79-
self.render.setLight(sunNodePath)
80-
81-
size=512
82-
bmin, bmax = LPoint3f(-size,0, -size), LPoint3f(size, 10*size,size)
83-
print(bmin,bmax)
84-
lens = sun.get_lens(0)
85-
lens.set_film_offset((bmin.xz + bmax.xz) * 0.5)
86-
lens.set_film_size(bmax.xz - bmin.xz)
87-
lens.set_near_far(bmin.y, bmax.y)
88-
89-
# i = LerpPosInterval(sphere, 2, (0,-100,600),(0,100,600))
90-
# i.loop()
91-
92-
dlight2 = DirectionalLight('my dlight2')
93-
dlight2.setColor((0.05, 0.05, 0.05, 1))
94-
dlnp2 = self.render.attachNewNode(dlight2)
95-
dlnp2.setPos(0, -200, -600)
96-
dlnp2.lookAt(0, 0, 0)
97-
self.render.setLight(dlnp2)
22+
self.scene: SceneBuilder = SceneBuilder(self.winCreator)
9823

9924

10025
loadPrcFileData('', 'framebuffer-multisample 0')
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from direct.interval.LerpInterval import LerpPosInterval
2+
from direct.interval.MetaInterval import Sequence
3+
from panda3d.core import AmbientLight, DirectionalLight, PTAFloat
4+
5+
from Blobtory.Scripts.Pipeline.WindowCreator import WindowCreator
6+
from Blobtory.Scripts.planet_former.PlanetGenerator import PlanetGenerator
7+
8+
9+
class SceneBuilder:
10+
def __init__(self, winCreator: WindowCreator):
11+
self.winCreator = winCreator
12+
self.base = winCreator.base
13+
self.SetupScene()
14+
15+
def SetupScene(self):
16+
self.SetupLighting()
17+
self.SetupPlanets()
18+
19+
# Moving sphere for shadow testing
20+
sphere = self.base.loader.loadModel("assets/models/icosphere")
21+
sphere.reparentTo(self.base.render)
22+
sphere.setScale(100)
23+
startInterval = LerpPosInterval(sphere, 1, (0, -200, 600), (0, 200, 600), blendType='easeInOut')
24+
endInterval = LerpPosInterval(sphere, 1, (0, 200, 600), (0, -200, 600), blendType='easeInOut')
25+
Sequence(startInterval, endInterval).loop()
26+
27+
def SetupPlanets(self):
28+
planetGen: PlanetGenerator = PlanetGenerator(self.winCreator, 128, 500)
29+
planetGen.cubeformer.mouseTime.setData(PTAFloat([10, 0, 0, 1]))
30+
self.base.accept("a", planetGen.RegenPlanet)
31+
32+
def SetupLighting(self):
33+
# Add ambient lighting
34+
alight = AmbientLight('alight')
35+
alight.setColor((0.1, 0.1, 0.1, 1))
36+
alnp = self.base.render.attachNewNode(alight)
37+
self.base.render.setLight(alnp)
38+
39+
# Make the sun and place it
40+
sun = DirectionalLight('TheSun')
41+
sunNodePath = self.base.render.attachNewNode(sun)
42+
sunNodePath.setPos(0, 1000, 1000)
43+
sunNodePath.lookAt(0, 0, 0)
44+
self.base.render.setLight(sunNodePath)
45+
46+
# Enable shadow mapping on sun
47+
lens = sun.get_lens(0)
48+
lens.set_film_size((1024, 1024))
49+
lens.set_near_far(0, 10000)
50+
sun.setShadowCaster(True, 2048, 2048)
51+
52+
# Setup back lighting - faking GI
53+
dlight2 = DirectionalLight('my dlight2')
54+
dlight2.setColor((0.05, 0.05, 0.05, 1))
55+
dlnp2 = self.base.render.attachNewNode(dlight2)
56+
dlnp2.setPos(0, -1000, -1000)
57+
dlnp2.lookAt(0, 0, 0)
58+
self.base.render.setLight(dlnp2)

assets/shaders/compute/alphaNoiseSphere.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void main() {
4545

4646
// point.w = (snoise(polarCoord.yz/(mouseX*10))*radius - r);
4747

48-
float noiseOuter = 1-abs(fractalNoise(normalize(movedPoint)*1)+1)*mouseTime.w*60;
48+
float noiseOuter = 1-abs(fractalNoise(normalize(movedPoint)*1)+1)*mouseTime.w*100;
4949
float planetRadius = radius+noiseOuter;
5050
point.w = smoothstep(0, 1, (planetRadius - lengthFromCenter)/10);
5151

assets/shaders/planets/planet.frag

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void main() {
9393
lightDir = normalize(-lightDir);
9494

9595
float lambertian = max(dot(lightDir, normal), 0.0);
96-
lambertian = texture(p3d_Texture1, vec2(lambertian, 0.5)).x;
96+
//lambertian = texture(p3d_Texture1, vec2(lambertian, 0.5)).x;
9797

9898
float specular = 0.0;
9999

@@ -104,15 +104,15 @@ void main() {
104104
vec3 halfDir = normalize(lightDir + viewDir);
105105
float specAngle = max(dot(halfDir, normal), 0.0);
106106
specular = pow(specAngle, p3d_Material.shininess);
107-
specular = texture(p3d_Texture1, vec2(specular, 0.5)).x;
107+
//specular = texture(p3d_Texture1, vec2(specular, 0.5)).x;
108108
}
109109
vec3 illumDiffuse = diffuseColor * lambertian * p3d_LightSource[i].color.xyz / (distance);
110110
vec3 illumSpecular = diffuseColor * specStrength * specular * p3d_LightSource[i].color.xyz / (distance);
111111
illumLightSum += (illumDiffuse+illumSpecular)*shadowScale;
112112
}
113113

114114
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;
115+
//colorGammaCorrected = texture(p3d_Texture1, vec2(length(colorGammaCorrected.xyz), 0.5), 0).x*colorGammaCorrected;
116116

117117
// use the gamma corrected color in the fragment0
118118
outputColor = vec4(colorGammaCorrected, 1);
0 Bytes
Loading
59 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)