Skip to content

Commit

Permalink
S12 (lighting) : display ok, but no lights for the moment
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangit committed Sep 20, 2020
1 parent 7d4f164 commit 4c189d3
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 1 deletion.
2 changes: 1 addition & 1 deletion official_samples/S11_spawner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
See tutorial S09_scrolling.nim for the world of parallax.
See tutorial S10_locale.nim for speaking another language than you-know-what.
For details about Orx side , please refer to the scrolling tutorial (official C++ sample):
For details about Orx side , please refer to the spawner tutorial:
https://wiki.orx-project.org/en/tutorials/spawners/spawner
This tutorial shows how to create and use spawners for particle effects.
Expand Down
271 changes: 271 additions & 0 deletions official_samples/S12_lighting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
; orx - Tutorial config file
; Should be used with orx v.1.4+

; this is an include for customizing this ini file
; for the Nim adaptation of the official sample.
@S_commons.ini@

[Display]
; we use the same size for the screen display than our camera's frustum so as to obtain a 1:1 ratio
ScreenWidth = @Camera.FrustumWidth
ScreenHeight = @Camera.FrustumHeight
Title = Lighting/Shader Tutorial

[Resource]
Texture = data/object

[Lighting]
Radius = 0.3 ~ 0.7
Color = (1.0, 0.0, 0.0) # (0.0, 1.0, 0.0) # (0.0, 0.0, 1.0) # (1.0, 1.0, 0.0) # (1.0, 0.0, 1.0) # (0.0, 1.0, 1.0) # (1.0, 1.0, 1.0)

[Input]
SetList = MainInput

[MainInput]
KEY_ESCAPE = Quit

MOUSE_LEFT = CreateLight
MOUSE_RIGHT = ClearLights
MOUSE_WHEEL_UP = IncreaseRadius
MOUSE_WHEEL_DOWN = DecreaseRadius
KEY_SPACE = ToggleAlpha

[Scene]
ChildList = Background # Logo # RegularGenerator # BumpGenerator

[Viewport]
Camera = Camera

[Camera]
FrustumWidth = 800
FrustumHeight = 600
FrustumFar = 2.0
Position = (0.0, 0.0, -1.0)

[Physics]
Gravity = (0.0, 9.81)

[BackgroundGraphic]
Texture = pixel
Pivot = center

[LogoGraphic]
Texture = orx.png
Pivot = center

[DemoiselleGraphic]
Texture = demoiselle.png
Pivot = center

[FujiGraphic]
Texture = fuji.png
Pivot = center

[Boat1Graphic]
Texture = boat1.png
Pivot = center

[Boat2Graphic]
Texture = boat2.png
Pivot = center

[Lit]
ShaderList = LightShader

[Background]
Graphic = BackgroundGraphic
Smoothing = false
Position = (0, 0, 1.0)
ParentCamera = Camera
Scale = 1
Color = (120, 20, 20) # (120, 120, 20) # (120, 220, 20)
ShaderList = BackgroundShader

[ColorSwitch]
SlotList = Color
Loop = true

[Color]
Type = color
StartTime = 0
EndTime = 5
Curve = sine
StartValue= (0, 0, 0)
EndValue = (0, 200, 0)

[Logo@Lit]
Graphic = LogoGraphic
FXList = LoopFX
Smoothing = true

[Regular@Lit]
Graphic = DemoiselleGraphic # FujiGraphic # Boat1Graphic # Boat2Graphic
Smoothing = false
LifeTime = 20

[Bump@Regular]
UseBumpMap = true

[RegularGenerator]
Spawner = RegularSpawner
Position = (600, -150, 0)
Scale = (-1, 1, 1)

[BumpGenerator]
Spawner = BumpSpawner
Position = (-600, 150, 0)

[RegularSpawner]
Object = Regular
WaveSize = 1
WaveDelay = 2.5
ObjectSpeed = (-100, 0, 0)

[BumpSpawner@RegularSpawner]
Object = Bump
ObjectSpeed = (100, 0, 0)

[LoopFX]
SlotList = Flip # Rot
Loop = true

[Flip]
Type = scale
Curve = sine
StartTime = 0.0
EndTime = 10.0
Period = 2.0
StartValue = (1.0, 1.0)
EndValue = (1.0, -1.0)

[Rot@Flip]
Type = rotation
Curve = linear
Period = 3.0
StartValue = 0
EndValue = 360 # -360

[LightShader]
Code = "
vec2 GetLightVector(int _iIndex)
{
// Done!
return vec2((avLightPos[_iIndex].x - gl_FragCoord.x) / vScreenSize.y, 1.0 - (avLightPos[_iIndex].y + gl_FragCoord.y) / vScreenSize.y);
}
vec3 GetNormal()
{
vec3 vNormal;
const vec3 vHalf = vec3(0.5);
// Gets raw normal
vNormal = texture2D(NormalMap, gl_TexCoord[0].xy).rgb;
// Normalizes it
vNormal = 2.0 * (vNormal - vHalf);
// Done!
return vNormal;
}
vec4 GetLightValue(int _iIndex, vec3 _vNormal)
{
float fIntensity, fBump;
vec4 vValue;
// Gets vector from point to light
vec2 vLight = GetLightVector(_iIndex);
// Gets its intensity
fIntensity = clamp(1.0 - (1.0 / (afLightRadius[_iIndex] * afLightRadius[_iIndex])) * length(vLight), 0.0, 1.0);
// Uses bump map? */
if(UseBumpMap != 0.0)
{
// Gets bump coef
fBump = dot(normalize(vec3(vLight, 0.1)), _vNormal);
}
else
{
// No bump
fBump = 1.0;
}
// Gets colored light value
vValue = fIntensity * vec4(fBump * avLightColor[_iIndex], afLightAlpha[_iIndex]);
// Done!
return vValue;
}
void main()
{
vec4 vColor, vPixel;
vec3 vNormal;
int i;
const int iLightNumber = 10;
// Clears color
vColor = vec4(0.0, 0.0, 0.0, 0.0);
// Gets current pixel value
vPixel = texture2D(Texture, gl_TexCoord[0].xy);
// Uses bump map?
if(UseBumpMap != 0.0)
{
// Gets normal
vNormal = GetNormal();
}
else
{
// Clears normal
vNormal = vec3(0.0);
}
// For all lights
for(i = 0; i < iLightNumber; i++)
{
// Adds its contribution
vColor += GetLightValue(i, vNormal);
}
// Adds ambient
vColor.rgb += vAmbient;
// Updates output
gl_FragColor.rgb = vPixel.rgb * vColor.rgb;
gl_FragColor.a = vPixel.a - vColor.a;
}
"
ParamList = Texture # NormalMap # vScreenSize # vAmbient # avLightPos # afLightRadius # avLightColor # afLightAlpha # UseBumpMap
UseCustomParam = true
vScreenSize = @Display.FramebufferSize
vAmbient = (0.05, 0.05, 0.05)
avLightPos = (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0) # (0, 0)
afLightRadius = 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0
avLightColor = (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0) # (0, 0, 0)
afLightAlpha = 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0 # 0
UseBumpMap = 1

[BackgroundShader]
Code = "
void main()
{
const vec3 vNormalizer = vec3(1.0 / (256.0 * 255.0));
int iX, iY;
// Gets denormalized coordinates
iX = int(256.0 * gl_TexCoord[0].x);
iY = int(256.0 * gl_TexCoord[0].y);
// Gets color
#if GL_EXT_gpu_shader4
gl_FragColor = vec4(vec3(float(iX ^ iY)) * vNormalizer * vColor, 1.0);
#else // GL_EXT_gpu_shader4
gl_FragColor = vec4(vec3(float(iX - iY / 8)) * vNormalizer * vColor, 1.0);
#endif // GL_EXT_gpu_shader4
}
"
ParamList = vColor
vColor = @Background.Color
Loading

0 comments on commit 4c189d3

Please sign in to comment.