Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wave shaders for vulkan #3

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Usage:
```
git clone https://github.com/gazebosim/harmonic_demo

cd harmonic_demo

export GZ_SIM_RESOURCE_PATH=`pwd`/harmonic_demo:$GZ_SIM_RESOURCE_PATH

gz sim -v 4 "harmonic_demo/harmonic.sdf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,56 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#version 330
#version ogre_glsl_ver_330

////////// Input parameters //////////
// Textures
uniform samplerCube cubeMap;
uniform sampler2D bumpMap;
vulkan_layout( ogre_t0 ) uniform texture2D bumpMap;
vulkan_layout( ogre_t1 ) uniform textureCube cubeMap;

vulkan( layout( ogre_s0 ) uniform sampler texSampler0 );
vulkan( layout( ogre_s1 ) uniform sampler texSampler1 );

// Colors
uniform vec4 deepColor;
uniform vec4 shallowColor;
uniform float fresnelPower;
uniform float hdrMultiplier;
vulkan( layout( ogre_P0 ) uniform Params { )
uniform vec4 deepColor;
uniform vec4 shallowColor;
uniform float fresnelPower;
uniform float hdrMultiplier;
vulkan( }; )

////////// Input computed in vertex shader //////////
vulkan_layout( location = 0 )
in block
{
mat3 rotMatrix;
vec3 eyeVec;
vec2 bumpCoord;
} inPs;

vulkan_layout( location = 0 )
out vec4 fragColor;

void main()
{
// Apply bump mapping to normal vector to make waves look more detailed:
vec4 bump = texture(bumpMap, inPs.bumpCoord)*2.0 - 1.0;
vec4 bump = texture(vkSampler2D(bumpMap, texSampler0),
inPs.bumpCoord)*2.0 - 1.0;
vec3 N = normalize(inPs.rotMatrix * bump.xyz);

// Reflected ray:
vec3 E = normalize(inPs.eyeVec);
vec3 R = reflect(E, N);

// negate z for use with the skybox texture that comes with ign-rendering
// negate z for use with the skybox texture that comes with gz-rendering
R = vec3(R.x, R.y, -R.z);

// uncomment this line if using other textures that are Y up
// Gazebo requires rotated cube map lookup.
// R = vec3(R.x, R.z, R.y);

// Get environment color of reflected ray:
vec4 envColor = texture(cubeMap, R, 0.0);
vec4 envColor = texture(vkSamplerCube(cubeMap, texSampler1), R, 0.0);

// Cheap hdr effect:
envColor.rgb *= (envColor.r+envColor.g+envColor.b)*hdrMultiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,40 @@
//
// The derivative terms (Tangent, Binormal, Normal) have been
// updated to be consistent with this convention.
//

#version 330

in vec4 vertex;
in vec4 uv0;
uniform mat4 worldviewproj_matrix;

/////////// Input parameters //////////
// Waves
uniform int Nwaves;
uniform vec3 camera_position_object_space;
uniform float rescale;
uniform vec2 bumpScale;
uniform vec2 bumpSpeed;
uniform float t;
uniform vec3 amplitude;
uniform vec3 wavenumber;
uniform vec3 omega;
uniform vec3 steepness;
uniform vec2 dir0;
uniform vec2 dir1;
uniform vec2 dir2;
uniform float tau;

// original concept:
// https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models


#version ogre_glsl_ver_330

vulkan_layout( OGRE_POSITION ) in vec4 vertex;
vulkan_layout( OGRE_TEXCOORD0 ) in vec4 uv0;

vulkan( layout( ogre_P0 ) uniform Params { )
uniform mat4 worldviewproj_matrix;

/////////// Input parameters //////////
// Waves
uniform int Nwaves;
uniform vec3 camera_position_object_space;
uniform float rescale;
uniform vec2 bumpScale;
uniform vec2 bumpSpeed;
uniform float t;
uniform vec3 amplitude;
uniform vec3 wavenumber;
uniform vec3 omega;
uniform vec3 steepness;
uniform vec2 dir0;
uniform vec2 dir1;
uniform vec2 dir2;
uniform float tau;
vulkan( }; )

/////////// Output variables to fragment shader //////////
vulkan_layout( location = 0 )
out block
{
mat3 rotMatrix;
Expand All @@ -78,8 +86,6 @@ struct WaveParameters {
float q; // steepness for Gerstner wave (q=0: rolling sine waves)
};



out gl_PerVertex
{
vec4 gl_Position;
Expand Down
68 changes: 59 additions & 9 deletions harmonic_demo/harmonic.sdf
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
<sdf version="1.6">
<world name="ModelTest">
<gravity>0 0 0</gravity>
<world name="harmonic">

<physics name="1ms" type="ignored">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin
filename="gz-sim-physics-system"
name="gz::sim::systems::Physics">
</plugin>
<plugin
filename="gz-sim-sensors-system"
name="gz::sim::systems::Sensors">
<render_engine>ogre2</render_engine>
</plugin>
<plugin
filename="gz-sim-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>
<plugin
filename="gz-sim-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>

<gravity>0 0 -9.8</gravity>
<scene>
<ambient>1 1 1</ambient>
<grid>false</grid>
<sky></sky>
</scene>
<light type="directional" name="point_01">
<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<pose>0 0 20 -1.3 0 0.5</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.1 0.1 0.1 1</specular>
<intensity>2</intensity>
<attenuation>
<range>600</range>
<constant>0</constant>
<linear>1</linear>
<quadratic>0.001</quadratic>
</attenuation>
</light>
<include>
<name>Lake House</name>
Expand Down Expand Up @@ -102,6 +119,39 @@
<name>Vanity</name>
<uri>Vanity</uri>
</include>


<model name="camera">
<static>true</static>
<pose>-9 -7.5 15 0.0, 0.4, 1.38</pose>
<link name="link">
<pose>0.05 0.05 0.05 0 0 0</pose>
<visual name="visual">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</visual>
<sensor name="camera" type="camera">
<camera>
<horizontal_fov>1.57</horizontal_fov>
<image>
<width>320</width>
<height>240</height>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>true</visualize>
</sensor>
</link>
</model>

</world>
</sdf>