Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Passing vectors from Vertex to Fragment  (Read 805 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-05-23 01:24:15 »

I'm trying to find a way to implement ray-casing completely by GLSL, and I was thinking of maybe getting the vertices from the vertex shader into the fragment shader. Then using some kind of algorithm for calculating a shadow.

Heres my shaders;

light.fs;
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
#version 150

uniform vec2 lightLocation;
uniform vec3 lightColor;
uniform vec3 ambientLight;

vec3 baseColor = vec3(1.0, 1.0, 1.0);

void main() {
   vec4 light = vec4(ambientLight, 1);
   vec4 color = vec4(baseColor,1);

   float distance = length(lightLocation - gl_FragCoord.xy);
   float attenuation = 1.0 / distance;
   vec4 lColor = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3.0)) * vec4(lightColor, 1);
   color += lColor;

   gl_FragColor = color * light;
}


light.vs
1  
2  
3  
4  
5  
#version 150

void main(){
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2014-05-23 06:38:14 »

old: varying
new: in & out
alltime: google

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Spacebeans
« Reply #2 - Posted 2014-05-23 19:20:30 »

Thanks!, but is there a good example of this somewhere? Because everywhere I look I find some complicated-C++ stuff.

Also: Sorry for the wrong thread, really. My bad!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2014-05-23 22:31:27 »

The C++ code isn't relevant, just look at GLSL examples?

Myomyomyo.
Offline Spacebeans
« Reply #4 - Posted 2014-05-23 22:49:54 »

Alright, will do!
Offline jmguillemette
« Reply #5 - Posted 2014-05-26 13:32:07 »

here is a bit of an example...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
#version 410


uniform mat4    in_projectionMatrix;
uniform mat4    in_cameraMatrix;
uniform mat4    in_modelMatrix;
layout(location = 0) in vec3 vp;
layout(location = 1) in vec3 np;

out vec3 pass_normal;
out mat4 pass_cameraMatrix;

void main () {
    vec4 vertex = vec4(vp, 1.0);
    gl_Position =    in_projectionMatrix * in_cameraMatrix * in_modelMatrix * vertex;
    pass_normal = np;
    pass_cameraMatrix = in_cameraMatrix;
   
   
}



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
#version 410

in  vec3 pass_normal;
in  mat4 pass_cameraMatrix;
out vec4 frag_colour;







void main(){
   //frag_colour = vec4(0.5, 0.0, 0.5, 1.0);
  vec4 colour = vec4(pass_normal, 1) * pass_cameraMatrix;
   //frag_colour = vec4(0.1,0.1,0.1,1) * colour;
  frag_colour = colour;
   
}

-=Like a post.. give the author a medal!=-
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (20 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!