Skip to content

Commit 48798d6

Browse files
committed
Planet shader performance boost, plus new CubeMarch Material system meaning COOL planets ;)
1 parent e85f013 commit 48798d6

15 files changed

Lines changed: 55 additions & 64 deletions

File tree

Blobtory/Scripts/Main.py

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ def __init__(self):
4646
stageToonLight.setSort(1)
4747
sphere.setTexture(stageToonLight, myToonLightTex)
4848

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)
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)
6363

6464
self.accept("v", self.bufferViewer.toggleEnable)
6565

@@ -69,43 +69,36 @@ def __init__(self):
6969
self.render.setLight(alnp)
7070

7171
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.)
72+
sun.setShadowCaster(True, 2048, 2048)
7773

78-
sun.show_frustum()
74+
#sun.show_frustum()
7975
sun.set_color((1, 1, 1, 1))
8076
sunNodePath = self.render.attachNewNode(sun)
8177
sunNodePath.setPos(0, 200, 600)
8278
sunNodePath.lookAt(0,0,0)
8379
self.render.setLight(sunNodePath)
8480

85-
bmin, bmax = self.render.get_tight_bounds(sunNodePath)
8681
size=512
87-
bmin, bmax = LPoint3f(-size,0, -size), LPoint3f(size, size,size)
82+
bmin, bmax = LPoint3f(-size,0, -size), LPoint3f(size, 10*size,size)
8883
print(bmin,bmax)
8984
lens = sun.get_lens(0)
9085
lens.set_film_offset((bmin.xz + bmax.xz) * 0.5)
9186
lens.set_film_size(bmax.xz - bmin.xz)
9287
lens.set_near_far(bmin.y, bmax.y)
9388

94-
i = LerpPosInterval(sphere,
95-
2,
96-
(0,-100,600),(0,100,600))
97-
i.loop()
89+
# i = LerpPosInterval(sphere, 2, (0,-100,600),(0,100,600))
90+
# i.loop()
9891

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)
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)
10598

10699

107-
loadPrcFileData('', 'framebuffer-multisample 1')
108-
loadPrcFileData('', 'multisamples 0')
100+
loadPrcFileData('', 'framebuffer-multisample 0')
101+
loadPrcFileData('', 'multisamples 1')
109102
loadPrcFileData('', 'sync-video false')
110103
loadPrcFile("config/Config.prc")
111104
blobtoryBase = Main()

Blobtory/Scripts/planet_former/MarchingCubes.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,16 @@ def GenerateMesh(self):
132132

133133
myMaterial = Material()
134134
myMaterial.setShininess(0.8) # Make this material shiny
135-
myMaterial.setDiffuse(LColor(0.99, 0.16, 0.06, 1)*0.1)
136-
myMaterial.setSpecular((1.1, 1.1, 1.1, 1))
137135
self.geomPath.setMaterial(myMaterial)
138136

139-
myDiffTex = self.winCreator.base.loader.loadTexture(
140-
"assets/textures/ramps/rampTerrainDiffuse.png",
141-
"assets/textures/ramps/rampTerrainSpecular.png")
142-
myDiffTex.setWrapU(Texture.WM_clamp)
143-
myDiffTex.setWrapV(Texture.WM_clamp)
137+
myMarchCubeMatsTex = self.winCreator.base.loader.loadTexture(
138+
"assets/textures/ramps/rampMarchCubeMat.png")
139+
myMarchCubeMatsTex.setWrapU(Texture.WM_clamp)
140+
myMarchCubeMatsTex.setWrapV(Texture.WM_clamp)
144141

145-
stageDiff = TextureStage("Diffuse")
142+
stageDiff = TextureStage("March Cube Mat")
146143
stageDiff.setSort(1)
147-
self.geomPath.setTexture(stageDiff, myDiffTex)
144+
self.geomPath.setTexture(stageDiff, myMarchCubeMatsTex)
148145
#self.geomPath.setTransparency(TransparencyAttrib.MAlpha)
149146

150147
myToonLightTex = self.winCreator.base.loader.loadTexture(

assets/shaders/compute/alphaNoiseSphere.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uniform float radius;
88
uniform float offset;
99
uniform vec3 midPoint;
1010
uniform vec4 mouseTime;
11-
const int craterCount = 20;
11+
const int craterCount = 30;
1212

1313
layout(rgba32f, binding = 0) uniform image3D vertexBufferWAlpha;
1414

@@ -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*50;
48+
float noiseOuter = 1-abs(fractalNoise(normalize(movedPoint)*1)+1)*mouseTime.w*60;
4949
float planetRadius = radius+noiseOuter;
5050
point.w = smoothstep(0, 1, (planetRadius - lengthFromCenter)/10);
5151

@@ -57,7 +57,7 @@ void main() {
5757
float theta = rand((offset+i))*2*PI;
5858
float phi = rand((offset+i+200))*2*PI;
5959

60-
float cometSize = rand((offset+i))*150+50;
60+
float cometSize = rand((offset+i))*200+50;
6161

6262
vec3 cartCraterNormal = vec3(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta));
6363
vec3 cartCraterPosCenter = (planetRadius*cometOffset-cometDiff+cometSize*sizeMatters)*cartCraterNormal;

assets/shaders/compute/cubemarcher.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void main() {
7070

7171
vec3 normal = normalize(cross(v2-v0, v1-v0));
7272
//vec3 normal = normalize(v2+v0+v1);
73-
int type = int(distance(vec3(512), v1)/60);
74-
if(type > 6) if(dot(normalize(vec3(512)-v1), normal)<0.8) type = 5;
73+
int type = int(distance(vec3(512), v1)/55);
74+
//if(type > 6) if(dot(normalize(vec3(512)-v1), normal)<0.8) type = 5;
7575
imageStore(normalBuffer, int(triangleIDIndex/3), vec4(normal, type));
7676

7777
i+=3;

assets/shaders/planets/planet.frag

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ uniform sampler2D p3d_Texture1;
77

88
// Input from vertex shader
99
in vec3 viewspacePos;
10-
in vec4 fragPos;
1110
in vec3 vertexNormal;
1211
in vec3 primNormal;
1312
in float num;
@@ -16,7 +15,7 @@ in vec3 diffuseColor;
1615
in float specStrength;
1716

1817
in vec3 cam_pos;
19-
in vec3 cam_dir;
18+
//in vec3 cam_dir;
2019

2120
in vec4[4] shadow_uv;
2221

@@ -81,8 +80,13 @@ void main() {
8180
//specStrength = p3d_Material.specular.x;
8281

8382
for (int i = 0; i < p3d_LightSource.length(); i++) {
83+
float shadowScale = 1;
84+
shadowScale = textureProj(p3d_LightSource[i].shadowMap, shadow_uv[i]);
85+
//shadowScale = textureProjSoft(p3d_LightSource[i].shadowMap, shadow_uv[i], 0.0001, 0.001);
8486
vec3 lightDir = p3d_LightSource[i].position.xyz;
85-
if (p3d_LightSource[i].position.w != 0) lightDir -= viewspacePos;
87+
if (p3d_LightSource[i].position.w != 0) {
88+
lightDir -= viewspacePos;
89+
}
8690

8791
float distance = length(lightDir);
8892
distance = distance * distance;
@@ -104,12 +108,11 @@ void main() {
104108
}
105109
vec3 illumDiffuse = diffuseColor * lambertian * p3d_LightSource[i].color.xyz / (distance);
106110
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]);
111+
illumLightSum += (illumDiffuse+illumSpecular)*shadowScale;
109112
}
110113

111114
vec3 colorGammaCorrected = pow(p3d_LightModel.ambient.xyz*diffuseColor+illumLightSum, vec3(0.49504950495));
112-
colorGammaCorrected = texture(p3d_Texture1, vec2(length(colorGammaCorrected.xyz), 0), 0).x*colorGammaCorrected;
115+
colorGammaCorrected = texture(p3d_Texture1, vec2(length(colorGammaCorrected.xyz), 0.5), 0).x*colorGammaCorrected;
113116

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

assets/shaders/planets/planet.vert

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ out vec2 texcoord;
2323
out vec3 vertexNormal;
2424
out vec3 primNormal;
2525
out float num;
26-
out vec4 fragPos;
2726
out vec3 viewspacePos;
2827

2928
out vec3 diffuseColor;
@@ -36,8 +35,8 @@ out vec4[4] shadow_uv;
3635
void main() {
3736
ivec3 vertexIndex = imageLoad(triangleBuffer, gl_VertexID).xyz;
3837
vec4 vertex = vec4(imageLoad(vertexBufferEdge, vertexIndex).xyz, 1);
38+
3939
gl_Position = p3d_ModelViewProjectionMatrix*vertex;
40-
fragPos = gl_Position;
4140

4241
vec4 viewspacePos4 = p3d_ModelViewMatrix * vertex;
4342
viewspacePos = vec3(viewspacePos4) / viewspacePos4.w;
@@ -51,13 +50,12 @@ void main() {
5150
texcoord = p3d_MultiTexCoord0;
5251
num = primNormalWVal.w;
5352

54-
vec4 getColor = texelFetch(p3d_Texture0, ivec2(8-num, 8-num), 0);
55-
diffuseColor = getColor.xyz;
56-
diffuseColor = diffuseColor*diffuseColor;
57-
specStrength = getColor.w;
53+
diffuseColor = texelFetch(p3d_Texture0, ivec2(num, 3), 0).xyz;
54+
diffuseColor = pow(diffuseColor, vec3(5));
55+
specStrength = texelFetch(p3d_Texture0, ivec2(num, 2), 0).x;
5856

5957
cam_pos = p3d_ViewMatrixInverse[3].xyz;
60-
cam_dir = -p3d_ViewMatrixInverse[2].xyz;
58+
//cam_dir = -p3d_ViewMatrixInverse[2].xyz;
6159

6260
for (int i = 0; i < p3d_LightSource.length(); i++) {
6361
shadow_uv[i] = p3d_LightSource[i].shadowViewMatrix * (p3d_ModelViewMatrix * vertex);

assets/shaders/utils/p3d_light_sources.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ uniform struct p3d_LightSourceParameters {
2525

2626
// Transforms view-space coordinates to shadow map coordinates
2727
mat4 shadowViewMatrix;
28-
} p3d_LightSource[4];
28+
} p3d_LightSource[3];
2929

3030
// The sum of all active ambient light colors.
3131
uniform struct {
141 Bytes
Loading
1.39 KB
Binary file not shown.
-8 Bytes
Loading

0 commit comments

Comments
 (0)