January 15, 2021, 06:26:01 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Misc
»
[bb] color of shaded triangles depending on ambientlight color and thing color by RemiD [ 9 months ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] color of shaded triangles depending on ambientlight color and thing color by RemiD [ 9 months ago ] (Read 1367 times)
BlitzBot
Jr. Member
Posts: 1
[bb] color of shaded triangles depending on ambientlight color and thing color by RemiD [ 9 months ago ]
«
on:
June 29, 2017, 12:28:43 AM »
Title :
color of shaded triangles depending on ambientlight color and thing color
Author :
RemiD
Posted :
9 months ago
Description :
this allows you to calculate the color of the shaded (not lighted) triangles depending on the color of the ambient light and the color of the thing
Code :
Code: BlitzBasic
Graphics3D
(
1000
,
625
,
32
,
2
)
SeedRnd
(
MilliSecs
(
)
)
;Camera
Global
Camera =
CreateCamera
(
)
CameraViewport
(
Camera,
0
,
0
,
GraphicsWidth
(
)
,
GraphicsHeight
(
)
)
CameraRange
(
Camera,
0.1
,
100
)
CameraClsColor
(
Camera,000,000,000
)
;Origine
Origine =
CreateCube
(
)
ScaleMesh
(
Origine,
0.01
,
0.01
,
0.01
)
EntityColor
(
Origine,
255
,000,
255
)
EntityFX
(
Origine,
1
)
;Center
Global
Center =
CreatePivot
(
)
PositionEntity
(
Center,
50
,
0
,
50
,
True
)
;DLight
Global
DLight =
CreateLight
(
1
)
LightColor
(
DLight,
192
,
192
,
192
)
PositionEntity
(
DLight,
50
,
1000
,-
1000
,
True
)
RotateEntity
(
DLight,
45
,
0
,
0
,
True
)
AmbientLight
(
038,038,038
)
;Cube lighted/shaded normally (with directx7 lighting/shading)
Global
CubeRenderer =
CreateCube
(
)
ScaleMesh
(
CubeRenderer,
1.0
/
2
,
1.0
/
2
,
1.0
/
2
)
PositionMesh
(
CubeRenderer,
0
,
1.0
/
2
,
0
)
R% =
Rand
(
025,
255
)
: G% =
Rand
(
025,
255
)
: B% =
Rand
(
025,
255
)
EntityColor
(
CubeRenderer,R,G,B
)
PositionEntity
(
CubeRenderer,
0
,
0
,
0
,
True
)
;Quad fullbright and has the same color than the shaded (not lighted) triangles of the cube
Global
QuadRenderer =
CreateMesh
(
)
Surface =
CreateSurface
(
QuadRenderer
)
AddVertex
(
Surface,
0.5
,
0.5
,
0.0
)
AddVertex
(
Surface, -
0.5
,
0.5
,
0.0
)
AddVertex
(
Surface,
0.5
, -
0.5
,
0.0
)
AddVertex
(
Surface, -
0.5
, -
0.5
,
0.0
)
AddTriangle
(
Surface,
0
,
1
,
2
)
AddTriangle
(
Surface,
2
,
1
,
3
)
UpdateNormals
(
QuadRenderer
)
EntityColor
(
QuadRenderer,
038.0
/
255
*R,
038.0
/
255
*G,
038.0
/
255
*B
)
;this is the secret formula ! (AmbientR/255*ThingR,AmbientG/255*ThingG,AmbientB/255*ThingB)
EntityFX
(
QuadRenderer,
1
)
PositionEntity
(
QuadRenderer,
0
,
1.5
,
0
,
True
)
PositionEntity
(
Camera,
3
,
1.65
,
3
,
True
)
RotateEntity
(
Camera,
0
,
135
,
0
,
True
)
Global
MainLoopTimer =
CreateTimer
(
30
)
Main
(
)
End
(
)
Function
Main
(
)
Repeat
If
(
KeyHit
(
57
)
=
1
)
R% =
Rand
(
025,
255
)
: G% =
Rand
(
025,
255
)
: B% =
Rand
(
025,
255
)
EntityColor
(
CubeRenderer,R,G,B
)
EntityColor
(
QuadRenderer,
038.0
/
255
*R,
038.0
/
255
*G,
038.0
/
255
*B
)
EndIf
If
(
KeyHit
(
28
)
=
1
)
PositionEntity
(
DLight,
Rnd
(
-
1000
,
1000
)
,
Rnd
(
0
,
1000
)
,-
1000
,
True
)
PointEntity
(
DLight,Center
)
EndIf
WireFrame
(
False
)
If
(
KeyDown
(
2
)
=
1
)
WireFrame
(
True
)
EndIf
SetBuffer
(
BackBuffer
(
)
)
RenderWorld
(
)
Color
(
255
,
255
,
255
)
Text
(
0
,
0
,
"press space to change the color of the thing"
)
Text
(
0
,
15
,
"press enter to change the light position"
)
Text
(
0
,
30
,
"the cube is lighted/shaded normally (with directx7 lighting/shading)"
)
Text
(
0
,
45
,
"the quad is fullbright and has the same color than the shaded (not lighted) triangles of the cube"
)
;Flip(1)
WaitTimer
(
MainLoopTimer
)
VWait
(
)
:
Flip
(
False
)
Until
(
KeyDown
(
1
)
=
1
)
End Function
Comments :
Rick Nasher(Posted 9 months ago)
Nice demonstration of how to do this.Dunno if intentional but code of download differs from the code displayed above.
RemiD(Posted 9 months ago)
Maybe, i added a longer version at first, but i simplified it to keep only the essentials.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Misc
»
[bb] color of shaded triangles depending on ambientlight color and thing color by RemiD [ 9 months ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal