Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/SampleFieldVS.glsl @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

File size: 2.5 KB
Line 
1#version 150
2
3// Ogre port of Nvidia's IsoSurf.cg file
4// Modified code follows. See http://developer.download.nvidia.com/SDK/10/opengl/samples.html for original
5//
6// Cg port of Yury Uralsky's metaball FX shader
7//
8// Authors: Simon Green and Yury Urlasky
9// Email: sdkfeedback@nvidia.com
10//
11// Copyright (c) NVIDIA Corporation. All rights reserved.
12////////////////////////////////////////////////////////////////////////////////////////////////////
13
14uniform float IsoValue = 1.0;
15uniform mat4 WorldViewProj;
16uniform mat4 origWorldViewIT;
17
18// Size of the sampling grid
19const ivec3 SizeMask = ivec3( 63, 63, 63 );
20const ivec3 SizeShift = ivec3( 0, 6, 12 );
21uniform vec4 Metaballs[2] = vec4[](vec4( -0.5, 0, 0, 0.2 ), vec4( 0.6, 0, 0, 0.1 ));
22
23in vec4 vertex;
24
25out VertexData {
26    vec3 N;
27    vec2 Field;
28} VertexOut;
29
30// Metaball function
31// Returns metaball function value in .w and its gradient in .xyz
32
33vec4 Metaball(vec3 Pos, vec3 Center, float RadiusSq)
34{
35        const float epsilon = 0.001;
36
37        vec3 Dist = Pos - Center;
38        float InvDistSq = 1 / (dot(Dist, Dist) + epsilon);
39
40        vec4 o;
41        o.xyz = -2 * RadiusSq * InvDistSq * InvDistSq * Dist;
42        o.w = RadiusSq * InvDistSq;
43        return o;
44}
45
46void main()
47{
48        // Sum up contributions from all metaballs
49/*      vec4 Field;
50        for (int i = 0; i<2; i++)
51        {
52                Field += Metaball(vertex.xyz, Metaballs[i].xyz, Metaballs[i].w);
53        }
54       
55        mat3 WorldViewIT = mat3(origWorldViewIT[0].xyz, origWorldViewIT[1].xyz, origWorldViewIT[2].xyz);
56       
57        // Transform position and normals
58        gl_Position = WorldViewProj * vertex;
59        VertexOut.N = WorldViewIT * Field.xyz;  // we want normals in world space
60        VertexOut.Field.x = Field.w;
61       
62        // Generate in-out flags
63        VertexOut.Field.y = (Field.w < 1.0) ? 1 : 0;
64*/
65        vec3 Pos;
66
67        // Generate sampling point position based on its index
68        Pos.x = float((gl_VertexID >> SizeShift.x) & SizeMask.x) / (SizeMask.x + 1);
69        Pos.y = float((gl_VertexID >> SizeShift.y) & SizeMask.y) / (SizeMask.y + 1);
70        Pos.z = float((gl_VertexID >> SizeShift.z) & SizeMask.z) / (SizeMask.z + 1);
71        Pos = Pos*2 - 1;
72
73        // Sum up contributions from all metaballs
74        vec4 Field;
75        for (int i = 0; i<2; i++)
76                Field += Metaball(Pos, Metaballs[i].xyz, Metaballs[i].w);
77
78        // Transform position and normals
79        gl_Position = WorldViewProj * vec4(Pos, 1);
80        VertexOut.N = mat3(origWorldViewIT) * Field.xyz;        // we want normals in world space
81        VertexOut.Field.x = Field.w;
82
83        // Generate in-out flags
84        VertexOut.Field.y = (Field.w < IsoValue) ? 1 : 0;
85
86//      o.Color = (Field*0.5+0.5) * (Field.w / 10.0);
87}
Note: See TracBrowser for help on using the repository browser.