Browse Source

Merge branch 'Music-Player_fix' of shuvit/shuvit into dev

shuvit 5 years ago
parent
commit
1bb7b5f851
6 changed files with 486 additions and 211 deletions
  1. 172
    0
      MusicPlayer.py
  2. 2
    2
      README.md
  3. 12
    0
      active_camera_loc.py
  4. 209
    209
      ai_manager.py
  5. 19
    0
      curves.osl
  6. 72
    0
      lensflare01.osl

+ 172
- 0
MusicPlayer.py View File

@@ -0,0 +1,172 @@
1
+import bge
2
+import os
3
+import aud
4
+import random
5
+import glob
6
+from DList import DoubleList
7
+from collections import OrderedDict
8
+from tinytag import TinyTag
9
+
10
+""" This is the Music Player as a component """
11
+class MusicPlayer(bge.types.KX_PythonComponent):
12
+
13
+    args = OrderedDict([])    
14
+
15
+    def start(self, args):
16
+        # dictionary
17
+        self.dictionary = bge.logic.globalDict
18
+        
19
+        # get mp3 files from the disk and create a list
20
+        self.directory = bge.logic.expandPath('//Music')
21
+        file_name = self.directory + '\\*.mp3'
22
+        file_list =  glob.glob(file_name)
23
+        
24
+        # use the mp3 list to make a playlist of nodes
25
+        self.playlist = DoubleList()
26
+        for name in file_list:
27
+            self.playlist.append(name)
28
+        
29
+        # previously played list of nodes
30
+        self.alreadyPlayed = DoubleList()
31
+        
32
+        # get a random song from the playlist, 
33
+        # remove it from the playlist
34
+        # add it to the alreadyPlayed list
35
+        # NOTICE: currentNode is a reference to a NODE in a list, if you want to play the song inside the node, use .data
36
+        self.currentNode = self.playlist.get(random.randint(0, self.playlist.getLength()))
37
+        self.nowPlaying = self.currentNode.getData()
38
+        self.playlist.remove(self.currentNode)
39
+        self.alreadyPlayed.append(self.nowPlaying)
40
+        print("Now Playing: " + self.nowPlaying)
41
+        self.setTag()
42
+        self.isPlaying = False
43
+
44
+        # create audio devices
45
+        self.device = aud.device()
46
+        self.factory = aud.Factory(self.nowPlaying)
47
+        self.handle = None        
48
+    
49
+    """ Update is called once every frame, and this is where
50
+        any input handling should go
51
+        
52
+        Controller Buttons: 
53
+        Y-Button - Play/Pause
54
+        LB       - Previous Track
55
+        RB       - Next Track
56
+        
57
+        TODO: Keyboard Buttons if these aren't alright
58
+        P        - Play/Pause
59
+        Pad Plus - Next Track
60
+        Pad Minus- Prev Track
61
+    """
62
+    def update(self):
63
+        keyboard = bge.logic.keyboard.events
64
+        up_dict = bge.logic.globalDict
65
+        #print(dictionary)
66
+        pKey = keyboard[bge.events.PKEY]
67
+        pPlus = keyboard[bge.events.PADPLUSKEY]
68
+        pMinus = keyboard[bge.events.PADMINUS]
69
+        lb = up_dict['lBump']
70
+        last_lb = up_dict['last_lBump']
71
+        rb = up_dict['rBump']
72
+        last_rb = up_dict['last_rBump']
73
+        y = up_dict['yBut']
74
+        last_y = up_dict['last_yBut']
75
+        JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
76
+        
77
+
78
+        #Run player on startup
79
+        if up_dict['music_start'] == True:
80
+            if self.isPlaying:
81
+                self.stopMusic()
82
+            else:
83
+                self.playMusic()                 
84
+            up_dict['music_start'] = False               
85
+
86
+        # Music controls only during pause/replay
87
+        if (up_dict['npause'] == True or up_dict['playback'] == True) or up_dict['music_start'] == True:
88
+            #stop/play
89
+            if (y == False and last_y == True) or pKey == JUST_ACTIVATED:
90
+                if self.isPlaying:
91
+                    self.stopMusic()
92
+                    up_dict['music_player'] = 0
93
+                else:
94
+                    self.playMusic()
95
+                    up_dict['music_player'] = 1
96
+            # Prev/Next
97
+            if self.isPlaying and self.handle.status:
98
+                if pMinus == JUST_ACTIVATED or (lb == False and last_lb == True):
99
+                    self.prevSong()
100
+                
101
+                if pPlus == JUST_ACTIVATED or (rb == False and last_rb == True):
102
+                    self.nextSong()
103
+        # if song ends, play next song
104
+        if self.isPlaying and not self.handle.status:
105
+            self.nextSong()
106
+
107
+    """ get info about song using TinyTag, then print to console """
108
+    def setTag(self):                
109
+        self.currTrackPath = os.path.join(self.directory, self.nowPlaying)
110
+        tag = TinyTag.get(self.currTrackPath)
111
+        self.currArtist = tag.artist
112
+        self.currTrackTitle = tag.title
113
+        self.dictionary['mu_artist'] = self.currArtist
114
+        self.dictionary['mu_title'] = self.currTrackTitle
115
+                
116
+        print('Artist: %s' % self.currArtist, 
117
+                ' Track: %s' % self.currTrackTitle)
118
+
119
+    def playMusic(self):
120
+        print('Play Music')
121
+        self.setTag()
122
+        self.handle = self.device.play(self.factory)
123
+        self.isPlaying = True
124
+        
125
+    def stopMusic(self):
126
+        print('Stop Music')
127
+        self.handle.stop()
128
+        self.isPlaying = False
129
+        
130
+    def nextSong(self):
131
+        print('Next Song')
132
+        # stop the current song
133
+        self.handle.stop()
134
+        
135
+        # get a song from the playlist
136
+        self.currentNode = self.playlist.get(random.randint(0, self.playlist.getLength()))
137
+        self.nowPlaying = self.currentNode.getData()
138
+        self.playlist.remove(self.currentNode)
139
+                
140
+        # add the song to the already played list
141
+        self.alreadyPlayed.append(self.nowPlaying)  
142
+        
143
+        # start the song
144
+        self.factory = aud.Factory(self.nowPlaying)
145
+        self.handle = self.device.play(self.factory)
146
+        self.setTag()
147
+        
148
+        # If playlist is empty, re-fill it
149
+        if self.playlist.getLength() == 0:
150
+            file_name = self.directory + '\\*.mp3'
151
+            file_list =  glob.glob(file_name)
152
+            for name in file_list:
153
+                self.playlist.append(name)
154
+        
155
+    """ Note on first call of this method, the current node will be equal to the tail of the already played list, 
156
+        however, it will be a node from a different list. We need to set current node equal to the tail node
157
+        of the already played list so that we can iterate through that list, instead of the other list """
158
+    def prevSong(self):
159
+        print('Prev Song')
160
+        # stop the current song
161
+        self.handle.stop()        
162
+        
163
+        if self.currentNode.getData() == self.alreadyPlayed.getTail().getData():
164
+            self.currentNode = self.alreadyPlayed.getTail()
165
+            
166
+        self.currentNode = self.currentNode.getPrev()
167
+        self.nowPlaying = self.currentNode.getData()
168
+        
169
+        # start the song
170
+        self.factory = aud.Factory(self.nowPlaying)
171
+        self.handle = self.device.play(self.factory)
172
+        self.setTag()

+ 2
- 2
README.md View File

@@ -1,2 +1,2 @@
1
-# shuvit
2
-Open source skateboarding game made with UPBGE / Blender.
1
+# shuvit
2
+Open source skateboarding game made with UPBGE / Blender.

+ 12
- 0
active_camera_loc.py View File

@@ -0,0 +1,12 @@
1
+import bge
2
+
3
+
4
+def set(cont):
5
+    own = cont.owner
6
+
7
+    #own.getWorldPosition
8
+    scene = bge.logic.getCurrentScene()
9
+    cam = scene.active_camera
10
+    own.worldPosition = cam.worldPosition
11
+
12
+# dont call main(bge.logic.getCurrentController()), the py controller will

+ 209
- 209
ai_manager.py View File

@@ -1,210 +1,210 @@
1
-def printplaying(skater,deck):
2
-    splaying_layers = "S: "
3
-    playing_layers = "D: "
4
-    tplaying_layers = "T: "
5
-    for x in range(9999):
6
-        if skater.isPlayingAction(x):
7
-        #if trucks.isPlayingAction(x):
8
-        #if skater.isPlayingAction(x):                        
9
-            splaying_layers += str(x)
10
-            splaying_layers += " "        
11
-        if deck.isPlayingAction(x):
12
-        #if trucks.isPlayingAction(x):
13
-        #if skater.isPlayingAction(x):                        
14
-            playing_layers += str(x)
15
-            playing_layers += " "
16
-          
17
-    print(splaying_layers, playing_layers)
18
-
19
-def main():
20
-
21
-    frame_rate = 60    #Set this to the framerate of your game.
22
-    optimization = 1    #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
23
-    #recording_cutoff = 6974#7300 #3600   #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
24
-    
25
-    recorder_state = 1   #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
26
-    allow_playback_break = True   #Allow the player to resume playing from the position in the recording.
27
-
28
-    from bge import logic
29
-    import aiRecord
30
-    import aiSortData
31
-    import npcChangeAnim
32
-    from mathutils import Vector
33
-    import math
34
-    
35
-    debugg = True
36
-
37
-    cont = logic.getCurrentController()
38
-    own = cont.owner
39
-    scene = logic.getCurrentScene()
40
-    dict = logic.globalDict
41
-    own['valueIndex'] = own['valueIndex'] + 2
42
-    #dict['recorder_on'] = recorder_on
43
-    npc_index = own['npc_index']
44
-    skater = dict['spawned_npcs'][npc_index]
45
-    recorder_on = dict.get('recorder_on')
46
-    own['recorder_on'] = recorder_on
47
-    #print("recorder on: ", recorder_on) 
48
-    own["playback"] = True
49
-    recording_cutoff = own['replay_length']
50
-    idle_timer = own['idle_timer']
51
-    npc_playback = own['npc_playback']
52
-    
53
-    
54
-    
55
-    if 'data_loaded' not in own:
56
-        #own['data_loaded'] = 1
57
-        aiRecord.loadData(cont, own)
58
-        if debugg: print('ai_loadData')
59
-        
60
-    if npc_playback == True:
61
-        cube = own
62
-        aiRecord.loadData(cont, own)   
63
-        #own['move'] = False          
64
-        #....................
65
-
66
-        valueIndex = own['valueIndex']
67
-        n = (valueIndex / recording_cutoff) * 1000
68
-        n = int(round(n))
69
-        #print(own['valueIndex'])
70
-        if own['objIndex'] < (recording_cutoff-3):
71
-            own['objIndex'] = own['objIndex'] + 2
72
-        else:
73
-            own['objIndex'] = 4   
74
-            print('replay end')    
75
-            npcChangeAnim.main(cont)
76
-            #own['npc_replay_name'] = '30secA.dat'
77
-            own['inited'] = False
78
-            own['rotate_in'] = True
79
-            own['move_to'] = True
80
-            own['rotate_out'] = True 
81
-            aiRecord.loadData(cont, own)
82
-    else:
83
-        if idle_timer < 5:
84
-            idle_timer += 1
85
-            #print('idling', idle_timer)
86
-        else:
87
-            idle_timer = 0
88
-            own['npc_rotate'] = True                 
89
-            
90
-    if own['move'] == True:
91
-        speed = .15
92
-        target = own['rpStartLoc']
93
-        my_vector = Vector([target[0], target[1], target[2]])
94
-        length = (own.worldPosition - my_vector).length
95
-        obj = own['target_object_name']
96
-        vect = own.getVectTo(obj)   
97
-        if length < .1:
98
-            own['move'] = False
99
-            obj = own['target_object_name']
100
-    own['idle_timer'] = idle_timer   
101
-    
102
-    try:
103
-        obj = own['target_object_name']
104
-        #print(obj.worldPosition)
105
-    except:
106
-        pass    
107
-    
108
-    
109
-    #11111111
110
-    if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
111
-        own['npc_playback'] = True
112
-        #obj = own['target_object_name']
113
-        #obj.endObject()
114
-        #print('ending target')    
115
-    if own['rotate_in'] == True:
116
-        tActu = cont.actuators['npcTracking']
117
-        tActu.object = own['target_object_name']
118
-        try:
119
-            own['rotate_in_timer'] = own['rotate_in_timer'] + 1
120
-        except:
121
-            own['rotate_in_timer'] = 0
122
-        if own['rotate_in_timer'] < 120:    
123
-            cont.activate(tActu)
124
-            skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)  
125
-        else:
126
-            cont.deactivate(tActu) 
127
-            own['rotate_in'] = False
128
-            own['rotate_in_timer'] = 0
129
-            skater.stopAction(2)
130
-
131
-    elif own['move_to'] == True:
132
-        target = own['rpStartLoc']
133
-        #print(target, 'target', own.worldPosition, '++++++')
134
-        my_vector = Vector([target[0], target[1], target[2]])
135
-        length = (own.worldPosition - my_vector).length
136
-        sActu = cont.actuators['npcSteering']
137
-        sActu.target = own['target_object_name']
138
-        #length = round(length, 7)
139
-        if length > .1:
140
-            #print(length, 'length < .1')
141
-            #pass
142
-            cont.activate(sActu)
143
-            skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
144
-        else:
145
-            cont.deactivate(sActu)
146
-            own['move_to'] = False
147
-            print(length, 'length met')
148
-            skater.stopAction(2)
149
-
150
-    elif own['rotate_out'] == True:    
151
-        #own['rpStartZ'] = 180
152
-        #print(own['rpStartZ'], 'start')
153
-        xyz = own.localOrientation.to_euler()
154
-        #print(xyz[2], 'non euler')
155
-        rotz = math.degrees(xyz[2])
156
-        xyz[2] = xyz[2] + 1.57
157
-        rotz_b = rotz + 180
158
-        if rotz_b > 360:
159
-            rotz_b -= 360
160
-        srotz_b = own['rpStartZ'] + 180
161
-        if srotz_b > 360:
162
-            srotz_b -= 360
163
-        #print (rotz_b, srotz_b, '---rotations')        
164
-        #print (rotz, own['rpStartZ'], '---rotations')
165
-        num = rotz - (own['rpStartZ'])
166
-        amt = .03
167
-        amt2 = 1
168
-        
169
-        
170
-        local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition) 
171
-
172
-        if local.x >0:
173
-            #target is in front
174
-            #print('in front')
175
-            pass
176
-        else:
177
-            #target is behind
178
-            #print('behind')
179
-            pass
180
-        if local.y > 0:
181
-                 #object on right
182
-            #print('on right')
183
-            rot = 'right'
184
-        else:
185
-                 #object is on left 
186
-            #print('on left')
187
-            rot = 'left'       
188
-        
189
-        
190
-        
191
-        skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
192
-        if abs(num) < amt2:
193
-            own['npc_playback'] = True
194
-            own['npc_rotate'] = False
195
-            print('----starting replay', num)
196
-            own['rotate_out'] = False
197
-            obj = own['target_object_name']
198
-            obj.endObject()
199
-            print('ending target') 
200
-            skater.stopAction(2)            
201
-        #elif rotz > own['rpStartZ']:
202
-        elif rot == 'right':    
203
-            own.applyRotation([0,0,amt], True)
204
-            own.worldPosition = own['rpStartLoc']
205
-        #elif rotz < own['rpStartZ']:
206
-        elif rot == 'left':    
207
-            own.applyRotation([0,0,-amt], True) 
208
-            own.worldPosition = own['rpStartLoc']                
209
-    #print(own['rotate_in'], own['move_to'], own['rotate_out'])                          
1
+def printplaying(skater,deck):
2
+    splaying_layers = "S: "
3
+    playing_layers = "D: "
4
+    tplaying_layers = "T: "
5
+    for x in range(9999):
6
+        if skater.isPlayingAction(x):
7
+        #if trucks.isPlayingAction(x):
8
+        #if skater.isPlayingAction(x):                        
9
+            splaying_layers += str(x)
10
+            splaying_layers += " "        
11
+        if deck.isPlayingAction(x):
12
+        #if trucks.isPlayingAction(x):
13
+        #if skater.isPlayingAction(x):                        
14
+            playing_layers += str(x)
15
+            playing_layers += " "
16
+          
17
+    print(splaying_layers, playing_layers)
18
+
19
+def main():
20
+
21
+    frame_rate = 60    #Set this to the framerate of your game.
22
+    optimization = 1    #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
23
+    #recording_cutoff = 6974#7300 #3600   #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
24
+    
25
+    recorder_state = 1   #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
26
+    allow_playback_break = True   #Allow the player to resume playing from the position in the recording.
27
+
28
+    from bge import logic
29
+    import aiRecord
30
+    import aiSortData
31
+    import npcChangeAnim
32
+    from mathutils import Vector
33
+    import math
34
+    
35
+    debugg = True
36
+
37
+    cont = logic.getCurrentController()
38
+    own = cont.owner
39
+    scene = logic.getCurrentScene()
40
+    dict = logic.globalDict
41
+    own['valueIndex'] = own['valueIndex'] + 2
42
+    #dict['recorder_on'] = recorder_on
43
+    npc_index = own['npc_index']
44
+    skater = dict['spawned_npcs'][npc_index]
45
+    recorder_on = dict.get('recorder_on')
46
+    own['recorder_on'] = recorder_on
47
+    #print("recorder on: ", recorder_on) 
48
+    own["playback"] = True
49
+    recording_cutoff = own['replay_length']
50
+    idle_timer = own['idle_timer']
51
+    npc_playback = own['npc_playback']
52
+    
53
+    
54
+    
55
+    if 'data_loaded' not in own:
56
+        #own['data_loaded'] = 1
57
+        aiRecord.loadData(cont, own)
58
+        if debugg: print('ai_loadData')
59
+        
60
+    if npc_playback == True:
61
+        cube = own
62
+        aiRecord.loadData(cont, own)   
63
+        #own['move'] = False          
64
+        #....................
65
+
66
+        valueIndex = own['valueIndex']
67
+        n = (valueIndex / recording_cutoff) * 1000
68
+        n = int(round(n))
69
+        #print(own['valueIndex'])
70
+        if own['objIndex'] < (recording_cutoff-3):
71
+            own['objIndex'] = own['objIndex'] + 2
72
+        else:
73
+            own['objIndex'] = 4   
74
+            print('replay end')    
75
+            npcChangeAnim.main(cont)
76
+            #own['npc_replay_name'] = '30secA.dat'
77
+            own['inited'] = False
78
+            own['rotate_in'] = True
79
+            own['move_to'] = True
80
+            own['rotate_out'] = True 
81
+            aiRecord.loadData(cont, own)
82
+    else:
83
+        if idle_timer < 5:
84
+            idle_timer += 1
85
+            #print('idling', idle_timer)
86
+        else:
87
+            idle_timer = 0
88
+            own['npc_rotate'] = True                 
89
+            
90
+    if own['move'] == True:
91
+        speed = .15
92
+        target = own['rpStartLoc']
93
+        my_vector = Vector([target[0], target[1], target[2]])
94
+        length = (own.worldPosition - my_vector).length
95
+        obj = own['target_object_name']
96
+        vect = own.getVectTo(obj)   
97
+        if length < .1:
98
+            own['move'] = False
99
+            obj = own['target_object_name']
100
+    own['idle_timer'] = idle_timer   
101
+    
102
+    try:
103
+        obj = own['target_object_name']
104
+        #print(obj.worldPosition)
105
+    except:
106
+        pass    
107
+    
108
+    
109
+    #11111111
110
+    if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
111
+        own['npc_playback'] = True
112
+        #obj = own['target_object_name']
113
+        #obj.endObject()
114
+        #print('ending target')    
115
+    if own['rotate_in'] == True:
116
+        tActu = cont.actuators['npcTracking']
117
+        tActu.object = own['target_object_name']
118
+        try:
119
+            own['rotate_in_timer'] = own['rotate_in_timer'] + 1
120
+        except:
121
+            own['rotate_in_timer'] = 0
122
+        if own['rotate_in_timer'] < 120:    
123
+            cont.activate(tActu)
124
+            skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)  
125
+        else:
126
+            cont.deactivate(tActu) 
127
+            own['rotate_in'] = False
128
+            own['rotate_in_timer'] = 0
129
+            skater.stopAction(2)
130
+
131
+    elif own['move_to'] == True:
132
+        target = own['rpStartLoc']
133
+        #print(target, 'target', own.worldPosition, '++++++')
134
+        my_vector = Vector([target[0], target[1], target[2]])
135
+        length = (own.worldPosition - my_vector).length
136
+        sActu = cont.actuators['npcSteering']
137
+        sActu.target = own['target_object_name']
138
+        #length = round(length, 7)
139
+        if length > .1:
140
+            #print(length, 'length < .1')
141
+            #pass
142
+            cont.activate(sActu)
143
+            skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
144
+        else:
145
+            cont.deactivate(sActu)
146
+            own['move_to'] = False
147
+            print(length, 'length met')
148
+            skater.stopAction(2)
149
+
150
+    elif own['rotate_out'] == True:    
151
+        #own['rpStartZ'] = 180
152
+        #print(own['rpStartZ'], 'start')
153
+        xyz = own.localOrientation.to_euler()
154
+        #print(xyz[2], 'non euler')
155
+        rotz = math.degrees(xyz[2])
156
+        xyz[2] = xyz[2] + 1.57
157
+        rotz_b = rotz + 180
158
+        if rotz_b > 360:
159
+            rotz_b -= 360
160
+        srotz_b = own['rpStartZ'] + 180
161
+        if srotz_b > 360:
162
+            srotz_b -= 360
163
+        #print (rotz_b, srotz_b, '---rotations')        
164
+        #print (rotz, own['rpStartZ'], '---rotations')
165
+        num = rotz - (own['rpStartZ'])
166
+        amt = .03
167
+        amt2 = 1
168
+        
169
+        
170
+        local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition) 
171
+
172
+        if local.x >0:
173
+            #target is in front
174
+            #print('in front')
175
+            pass
176
+        else:
177
+            #target is behind
178
+            #print('behind')
179
+            pass
180
+        if local.y > 0:
181
+                 #object on right
182
+            #print('on right')
183
+            rot = 'right'
184
+        else:
185
+                 #object is on left 
186
+            #print('on left')
187
+            rot = 'left'       
188
+        
189
+        
190
+        
191
+        skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
192
+        if abs(num) < amt2:
193
+            own['npc_playback'] = True
194
+            own['npc_rotate'] = False
195
+            print('----starting replay', num)
196
+            own['rotate_out'] = False
197
+            obj = own['target_object_name']
198
+            obj.endObject()
199
+            print('ending target') 
200
+            skater.stopAction(2)            
201
+        #elif rotz > own['rpStartZ']:
202
+        elif rot == 'right':    
203
+            own.applyRotation([0,0,amt], True)
204
+            own.worldPosition = own['rpStartLoc']
205
+        #elif rotz < own['rpStartZ']:
206
+        elif rot == 'left':    
207
+            own.applyRotation([0,0,-amt], True) 
208
+            own.worldPosition = own['rpStartLoc']                
209
+    #print(own['rotate_in'], own['move_to'], own['rotate_out'])                          
210 210
 main()

+ 19
- 0
curves.osl View File

@@ -0,0 +1,19 @@
1
+
2
+
3
+uniform sampler2D bgl_RenderedTexture;
4
+
5
+uniform float BC_BRIGHTNESS = 2;
6
+uniform float BC_CONTRAST = 1;
7
+
8
+//const float BC_CONTRAST = 1.3;    //1 is no contrast.
9
+//const float BC_BRIGHTNESS = 1.15;    //1 is no brightness 1.15 is good
10
+
11
+void main()
12
+{
13
+    vec4 color = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
14
+    
15
+    color = ((color-1)*max(BC_CONTRAST,0));
16
+    color = color+BC_BRIGHTNESS;
17
+     
18
+    gl_FragColor = color; 
19
+}

+ 72
- 0
lensflare01.osl View File

@@ -0,0 +1,72 @@
1
+
2
+uniform sampler2D bgl_RenderedTexture;
3
+uniform float bgl_RenderedTextureWidth;
4
+uniform float bgl_RenderedTextureHeight;
5
+uniform float sunX;
6
+uniform float sunY;
7
+uniform float timer;
8
+uniform float sundirect;
9
+uniform float sunScale; 
10
+
11
+float noise( float n )
12
+{
13
+     return fract(sin(n+timer/2.0));
14
+}
15
+
16
+//float noise2(vec2 co){
17
+    //return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
18
+//}
19
+
20
+vec3 lensflare(vec2 uv,vec2 pos,float sunscale)
21
+{
22
+	vec2 main = uv-pos;
23
+	vec2 uvd = uv*(length(uv));
24
+	
25
+	float ang = atan(main.y, main.x);
26
+	float dist=length(main); dist = pow(dist,.1);
27
+	float n = noise1(vec2((ang-timer/9.0)*16.0,dist*32.0));
28
+	
29
+	float f0 = 1.0/(length(uv-pos)/sunscale+1.0);
30
+	
31
+	f0 = f0+f0*(sin((ang+timer/18.0 + noise1(abs(ang)+n/2.0)*2.0)*12.0)*.1+dist*.1+.8);
32
+
33
+	float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25;
34
+	float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23;
35
+	float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),.0)*00.21;
36
+	
37
+	vec2 uvx = mix(uv,uvd,-0.5);
38
+	
39
+	float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),.0)*6.0;
40
+	float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),.0)*5.0;
41
+	float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),.0)*3.0;
42
+	
43
+	uvx = mix(uv,uvd,-.4);
44
+	
45
+	float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0;
46
+	float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),.0)*2.0;
47
+	float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),.0)*2.0;
48
+	
49
+	uvx = mix(uv,uvd,-0.5);
50
+	
51
+	float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),.0)*6.0;
52
+	float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),.0)*3.0;
53
+	float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),.0)*5.0;
54
+	
55
+	vec3 c = vec3(.0);
56
+	
57
+	c.r+=f2+f4+f5+f6; c.g+=f22+f42+f52+f62; c.b+=f23+f43+f53+f63;
58
+	c+=vec3(f0);
59
+	
60
+	return c;
61
+}
62
+
63
+void main()
64
+{
65
+    vec4 renderedTex = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
66
+    float xconv = bgl_RenderedTextureWidth / bgl_RenderedTextureHeight;
67
+    vec2 sunPos = vec2((sunX - 0.5) * xconv, sunY - 0.5);
68
+    vec2 uv = vec2((gl_TexCoord[0].s - 0.5) * xconv, gl_TexCoord[0].t - 0.5);
69
+    vec3 lens = lensflare(uv, sunPos, sunScale);
70
+    renderedTex.rgb += lens * sundirect;
71
+    gl_FragColor = renderedTex;
72
+}

Loading…
Cancel
Save