Skip to content
Permalink
Browse files

Added support for deferred transparency

Added setting to change g-buffer and lightbuffer bitdepth
Prepared pipeline for PBR
Fixed bug in specular lighting equation
Fixed tons of bugs
  • Loading branch information...
bohhavoc@googlemail.com
bohhavoc@googlemail.com committed Dec 9, 2013
1 parent 93b70b0 commit 6635072aaadc5240a10e89e5422119503c9f17d6
Showing with 1,530 additions and 164 deletions.
  1. +2 −0 examples/01.c
  2. +3 −4 examples/02.c
  3. BIN examples/02.wmb
  4. BIN examples/02.wmp
  5. +3 −1 examples/03.c
  6. +1 −0 examples/04.c
  7. +5 −2 examples/05.c
  8. +166 −0 examples/06.c
  9. BIN examples/assets/vloga/vloga.mdl
  10. BIN examples/assets/vloga/vloga_car_N.tga
  11. BIN examples/assets/vloga/vloga_noWindows.mdl
  12. BIN examples/assets/vloga/vloga_szyby_N.tga
  13. BIN examples/assets/vloga/vloga_windowsOnly.mdl
  14. +17 −1 examples/common.h
  15. +319 −44 examples/default.fx
  16. +29 −0 examples/fx/06_transparent.fx
  17. +52 −6 examples/shadec/fx/sc_deferred_finalize.fx
  18. +1 −1 examples/shadec/fx/sc_ssdo.fx
  19. +237 −0 examples/shadec/fx/sc_ssdoLOW.fx
  20. +8 −5 examples/shadec/sc_core.c
  21. +4 −0 examples/shadec/sc_core.h
  22. +2 −2 examples/shadec/sc_deferredLighting.c
  23. +3 −1 examples/shadec/sc_lights.c
  24. +21 −14 examples/shadec/sc_materials.c
  25. +2 −2 examples/shadec/sc_ssao.c
  26. +1 −1 examples/shadec/sc_ssao.h
  27. +2 −2 examples/shadec/sc_wrapper.c
  28. BIN examples/shadec/tex/litsphere/litsphere01.tga
  29. BIN examples/shadec/tex/litsphere/sc_brdf_metal.tga
  30. BIN examples/shadec/tex/litsphere/sc_brdf_phong.tga
  31. BIN examples/shadec/tex/litsphere/sc_brdf_satin.tga
  32. BIN examples/shadec/tex/sc_BFNormals.dds
  33. BIN examples/shadec/tex/sc_BFNormals_512.dds
  34. BIN examples/shadec/tex/sc_deferredLighting_LUT.dds
  35. BIN examples/shadec/tex/sc_random4x4.tga
  36. BIN examples/shadec/tex/sc_stipplingMask.tga
  37. +319 −44 src/default.fx
  38. +52 −6 src/shadec/fx/sc_deferred_finalize.fx
  39. +1 −1 src/shadec/fx/sc_ssdo.fx
  40. +237 −0 src/shadec/fx/sc_ssdoLOW.fx
  41. +8 −5 src/shadec/sc_core.c
  42. +4 −0 src/shadec/sc_core.h
  43. +2 −2 src/shadec/sc_deferredLighting.c
  44. +3 −1 src/shadec/sc_lights.c
  45. +21 −14 src/shadec/sc_materials.c
  46. +2 −2 src/shadec/sc_ssao.c
  47. +1 −1 src/shadec/sc_ssao.h
  48. +2 −2 src/shadec/sc_wrapper.c
  49. BIN src/shadec/tex/litsphere/litsphere01.tga
  50. BIN src/shadec/tex/litsphere/sc_brdf_metal.tga
  51. BIN src/shadec/tex/litsphere/sc_brdf_phong.tga
  52. BIN src/shadec/tex/litsphere/sc_brdf_satin.tga
  53. BIN src/shadec/tex/sc_BFNormals.dds
  54. BIN src/shadec/tex/sc_BFNormals_512.dds
  55. BIN src/shadec/tex/sc_deferredLighting_LUT.dds
  56. BIN src/shadec/tex/sc_random4x4.tga
  57. BIN src/shadec/tex/sc_stipplingMask.tga
  58. BIN tools/lightfunctions/Blinn-Phong.dds
  59. BIN tools/lightfunctions/CarPaint.dds
  60. BIN tools/lightfunctions/Cook-Torrance.dds
  61. BIN tools/lightfunctions/Oren-Nayar.dds
  62. BIN tools/lightfunctions/christbaumkugel.dds
@@ -44,6 +44,7 @@ void v_camera()

void main()
{
d3d_triplebuffer = 1; //don't let the gpu wait for data
level_load(NULL);
wait(3);

@@ -76,6 +77,7 @@ void main()
sc_screen_default.settings.hdr.lensflare.enabled = 1; //enable for a nice lensflare effect in combination with HDR/Bloom
sc_screen_default.settings.dof.enabled = 0; //enable Depth of Field Effect
sc_screen_default.settings.ssao.enabled = 0; //enable to activate SSAO
sc_screen_default.settings.bitdepth = 32; //8 bit g-buffer & lighting (default). change to 12222 or 14444 for 16bit/32bit g-buffer and lighting buffer which results in nicer lighting at the cost of performance

//initialize shade-c, use default screen object
sc_setup(sc_screen_default);
@@ -47,9 +47,7 @@ void v_camera()

void main()
{



d3d_triplebuffer = 1; //don't let the gpu wait for data
shadow_stencil = -1; //turn off all engine intern shadow calculations. THIS IS IMPORTANT!
level_load("02.wmb");
wait(5); //wait for level load
@@ -99,7 +97,8 @@ void main()
sc_screen_default.settings.lights.sunShadowRange = 5000; //manually set the shadow range...we don't need realtime shadows in the far distant! If set to 0 (default) shadow range will be set to camera.clip_far
sc_screen_default.settings.lights.sunShadowBias = 0.001; //set the shadow bias
sc_screen_default.settings.antialiasing.enabled = 1; //enable antialiasing

sc_screen_default.settings.bitdepth = 32; //8 bit g-buffer & lighting (default). change to 12222 or 14444 for 16bit/32bit g-buffer and lighting buffer which results in nicer lighting at the cost of performance

//initialize shade-c, use default screen object
sc_setup(sc_screen_default);

BIN +376 Bytes (100%) examples/02.wmb
Binary file not shown.
BIN +481 Bytes (100%) examples/02.wmp
Binary file not shown.
@@ -48,6 +48,7 @@ void v_camera()

void main()
{
d3d_triplebuffer = 1; //don't let the gpu wait for data
shadow_stencil = -1; //turn off all engine intern shadow calculations. THIS IS IMPORTANT!
level_load("");
wait(5); //wait for level load
@@ -99,9 +100,10 @@ void main()
sc_screen_default.settings.lights.sunShadowResolution = 256; //reduce shadow resolution as we are blurring the shadowmap and therefore can get away with low res shadows
sc_screen_default.settings.lights.sunPssmBlurSplits = 2; //blur the first two pssm splits
sc_screen_default.settings.lights.sunPssmSplitWeight = 0.7; //high res near splits, low res far splits
sc_screen_default.settings.bitdepth = 32; //8 bit g-buffer & lighting (default). change to 12222 or 14444 for 16bit/32bit g-buffer and lighting buffer which results in nicer lighting at the cost of performance


//initialize shade-c, use default screen object
//initialize shade-c, use default screen object and 8 bit g-buffer & lighting. change 32 to 12222 or 14444 for 16bit/32bit g-buffer and lighting
sc_setup(sc_screen_default);
//wait(3); //wait for Shade-C

@@ -47,6 +47,7 @@ void v_camera()

void main()
{
d3d_triplebuffer = 1; //don't let the gpu wait for data
shadow_stencil = -1; //turn off all engine intern shadow calculations. THIS IS IMPORTANT!
level_load("02.wmb");
wait(5); //wait for level load
@@ -1,6 +1,6 @@
/***************************************************************************
Basic Example on how to use write and use custom materials/shaders
Basic Example on how to write and use custom materials/shaders
***************************************************************************/

@@ -115,7 +115,7 @@ void v_camera()
}

void main()
{
{
shadow_stencil = -1; //turn off all engine intern shadow calculations. THIS IS IMPORTANT!
level_load("05.wmb");
wait(3); //wait for level load
@@ -132,6 +132,7 @@ void main()
you = ent_create(NULL, vector(-800,0, 200), v_camera);
you.tilt = -10;
camera.clip_far = 5000; //set this as low as possible to increase performance AND visuals!
camera.arc = 75;

//set resolution before calling sc_setup
//if you want to change resolution again, simple call sc_setup() again after you changed the resolution
@@ -148,6 +149,7 @@ void main()
//If you want to change these during runtime, simply call sc_setup() again after you enabled/disabled an effect
// -> more info in sc_core.h, in struct SC_SETTINGS
sc_screen_default.settings.hdr.enabled = 1; //enable Bloom/HDR
sc_screen_default.settings.hdr.lensflare.enabled = 1; //enable for a nice lensflare effect in combination with HDR/Bloom

//initialize shade-c, use default screen object
sc_setup(sc_screen_default);
@@ -158,6 +160,7 @@ void main()
sc_screen_default.settings.hdr.intensity = 2;
sc_screen_default.settings.hdr.lensflare.brightpass = 0.0;
sc_screen_default.settings.hdr.lensflare.intensity = 0.25;
sc_screen_default.settings.bitdepth = 32; //8 bit g-buffer & lighting (default). change to 12222 or 14444 for 16bit/32bit g-buffer and lighting buffer which results in nicer lighting at the cost of performance

//Add objects and apply custom materials
//Texture Movement
@@ -0,0 +1,166 @@
/***************************************************************************
Basic Example on how to setup and use transparent materials/objects
***************************************************************************/

#include <litec.h>
#include <acknex.h>
#include <default.c>

//include Shade-C
#define PRAGMA_PATH "shadec"
#include "shade-c.h"

#include "common.h"


ENTITY* skycube =
{
type = "plain_abraham+6.tga";
flags2 = SKY | CUBE | SHOW;
red = 130;
green = 130;
blue = 130;
}

//simple camera script...
void v_camera()
{
set(my,INVISIBLE);
set(my,PASSABLE);
while(1)
{
c_move(my,vector(key_force.y*25*time_step,-key_force.x*25*time_step,0),nullvector,IGNORE_PASSABLE);
my.pan -= mickey.x;
my.tilt -= mickey.y;

vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);

wait(1);
}
}

//this is attached to the car's windows in 06.wmb
//have a look at 06_transparent.fx to see how transparency is done
MATERIAL* mtl_carWindow =
{
effect = "06_transparent.fx";
flags = ENABLE_RENDER;
event = sc_materials_event;

power = 200;
}


void main()
{
shadow_stencil = -1; //turn off all engine intern shadow calculations. THIS IS IMPORTANT!
level_load("02.wmb");
wait(5); //wait for level load
//set suncolor to zero (setting sun_color in WED to zero does NOTHING! This is a bug in gamestudio)
//if suncolor == 0, sun will not be rendered. Set this for pure indoor scenes to boost performance!
//vec_set(sun_color, vector(0,0,0));
vec_set(sun_color, vector(255,240,230));
//set ambient color to zero as we want a dark level with nice shadows ;)
//vec_set(ambient_color, vector(0,0,0));
vec_set(ambient_color, vector(90,90,90));
//vec_set(ambient_color, vector(180,180,180));

//create a camera object so we can move around the scene
you = ent_create(NULL, vector(168,-478, 212), v_camera);
you.pan = 123;
you.tilt = -18;
camera.arc = 75;
camera.clip_far = 5000; //set this as low as possible to increase performance AND visuals!

//set resolution before calling sc_setup
//if you want to change resolution again, simple call sc_setup() again after you changed the resolution
//video_set(1280, 720, 0, 2);
video_set(800, 600, 0, 2);

//setup skies
sc_sky(skycube);

//set camera as main view of sc_screen_default
sc_screen_default = sc_screen_create(camera);

//enable/disable Shade-C effects. You have to set these before calling sc_setup()
//If you want to change these during runtime, simply call sc_setup() again after you enabled/disabled an effect
// -> more info in sc_core.h, in struct SC_SETTINGS

sc_screen_default.settings.forward.enabled = 0; //enable if you need particles or custom materials which can't be rendered in the deferred pipeline
sc_screen_default.settings.refract.enabled = 0; //enable for refractive effects such as heat haze and glass
sc_screen_default.settings.hdr.enabled = 1; //enable Bloom/HDR
sc_screen_default.settings.hdr.lensflare.enabled = 1; //enable for a nice lensflare effect in combination with HDR/Bloom
sc_screen_default.settings.dof.enabled = 0; //enable Depth of Field Effect
sc_screen_default.settings.ssao.quality = SC_MEDIUM; //set ssao quality. SC_LOW, SC_MEDIUM, SC_HIGH, SC_ULTRA
sc_screen_default.settings.ssao.enabled = 1; //enable to activate SSAO
sc_screen_default.settings.lights.sunShadows = 1; //enable shadows for the sun
sc_screen_default.settings.lights.sunShadowResolution = 512; //reduce shadow resolution as we are manually setting the shadow range to 5000 and can therefor get away with a small shadowmap
sc_screen_default.settings.lights.sunPssmSplitWeight = 0.7; //high res near splits, low res far splits
sc_screen_default.settings.lights.sunShadowRange = 5000; //manually set the shadow range...we don't need realtime shadows in the far distant! If set to 0 (default) shadow range will be set to camera.clip_far
sc_screen_default.settings.lights.sunShadowBias = 0.001; //set the shadow bias
sc_screen_default.settings.antialiasing.enabled = 1; //enable antialiasing
sc_screen_default.settings.bitdepth = 32; //8 bit g-buffer & lighting (default). change to 12222 or 14444 for 16bit/32bit g-buffer and lighting buffer which results in nicer lighting at the cost of performance

//initialize shade-c, use default screen object
sc_setup(sc_screen_default);

//tweak effect parameters anytime you want
// -> more info in sc_core.h, in struct SC_SETTINGS
sc_screen_default.settings.hdr.brightpass = 0.85;
sc_screen_default.settings.hdr.intensity = 1;
sc_screen_default.settings.hdr.lensflare.brightpass = 0.0;
sc_screen_default.settings.hdr.lensflare.intensity = 0.25;
sc_screen_default.settings.dof.focalPos = 300;
sc_screen_default.settings.dof.focalWidth = 600;
sc_screen_default.settings.ssao.radius = 30;
sc_screen_default.settings.ssao.intensity = 4;
sc_screen_default.settings.ssao.selfOcclusion = 0.0004; //we want a bit of self occlusion... lower values result in even more self occlusion
sc_screen_default.settings.ssao.brightOcclusion = 0.25; //low value: ssao will only be visible in shadows and dark areas. high value: ssao will always be visible. Range: 0-1

you = ent_create(SPHERE_MDL, vector(150,-360,58), NULL);
you.material = mtl_car;
vec_scale(you.scale_x, 10);
set(you, SHADOW);





//create a spotlight which we will rotate later
//please note that the light's red color value is above 255, which automatically makes this an hdr light
ENTITY* spotlight = sc_light_create(vector(-86,-82,322), 1000, vector(1024,512,0), SC_LIGHT_SPOT | SC_LIGHT_SHADOW);
//set initial rotation
spotlight.pan = 188;
spotlight.tilt = -43;
//update the spotlight as we changed its rotation
sc_light_update(spotlight);

while(1)
{

// //move the sun around the scene
// sun_angle.pan += time_frame;
// sun_angle.pan %= 360;
// sun_angle.tilt = fsin(sun_angle.pan, 45) + 45;
// //set the sunlight brightness
// sun_light = sun_angle.tilt;



//rotate the spotlight
spotlight.pan += time_step*5;
//update the spotlight
sc_light_update(spotlight);


//DEBUG_BMAP(sc_screen_default.renderTargets.gBuffer[0],0,1);

wait(1);
}

}
BIN +4.14 KB (100%) examples/assets/vloga/vloga.mdl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -22,6 +22,7 @@ MATERIAL* mtl_car =

power = 200;
}

MATERIAL* mtl_metal2 = //mtl_metal2 because mtl_metal is already taken by gamestudio!
{
effect = "metal2.fx";
@@ -72,4 +73,19 @@ MATERIAL* mtl_terrain01 =
flags = ENABLE_RENDER;

event = sc_materials_event;
}
}


//DONT USE! Will be kicked out in a future release and be replaced with a PBR model for much better lighting!
//this will set the lightfunction for an entity.
//currently these lightfunctions are supported
// 0 = blinn-phong with default smoothness and wrap (default)
// 1 = Cook-torrance with default smoothness and wrap
// 2 = Oren Nayar with default smoothness and wrap
// 3 = Car Paint
// 51 = Oren Nayar with high smoothness and high wrap
//custom lightfunctions can also be added, which is needed for setting diffuse smoothness and diffuse wrap to non default values
//action setLightfunction()
//{
// sc_skill(me, SC_OBJECT_MATERIAL_ID , my.skill1);
//}

0 comments on commit 6635072

Please sign in to comment.
You can’t perform that action at this time.