OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Shader Model 2 Stone
View page
Source of version: 4
(current)
Shader Model 2 Stone Shader !!Description This shader is exported from rendermonkey 1.61 with one change to one line of code in the .material file as noted below. It should work with gpu's that support shader model 2 and above. A live Openspace scene (that uses Ogre for 3d, Newton for physics, OpenAL for sound) is posted to: [http://ifam.net/openspace/moon2/web/]. You need win os or linux running wine and the scol voyager plugin (from http://scolring.org/index.php/logiciels ) to view the scene. If the plugin is not installed on your system you will be prompted for an install. Openspace like Ogre is opensource. The upside to this shader like any of the rendermonkey shaders is that you can fool around with the variables in rendermonkey and preview them instantly in that app. I think there is a bug in the rendermonkey exporter. With some help of one of the developers of openspace, I found that you should change the line: {CODE(wrap="1", colors="c++")} param_named_auto 0 world_viewProj viewproj_matrix {CODE} to {CODE(wrap="1", colors="c++")} param_indexed_auto 0 worldviewproj_matrix {CODE} otherwise if you transform the object that is painted with the shader, the shader won't move or scale along with the node that holds the entity on which the shader is painted. colleagues: feel free to remove my commented out code, -h Here is a screenshot. This variation that I exported from rendermonkey is good for moonlike terrain methinks: {IMG(src="http://www.scolring.org/files/divers/forum/Capture-h_moon1.png")}{IMG} !!Usage Just add the material __terrain_material__ to your object.I have not modified it to work with hardware skinnig. Anyone who wants to do that go ahead and edit this page an add the hardware skinning version below mine. !!Material file {CODE(wrap="1", colors="c++")} //DirectX 9.0 HLSL Vertex Shader vs_1_1 vertex_program HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Vertex_Shader hlsl { source HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Vertex_Shader.program.cg target vs_1_1 entry_point main } //DirectX 9.0 HLSL Pixel Shader ps_2_0 fragment_program HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Pixel_Shader hlsl { source HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Pixel_Shader.program.cg target ps_2_0 entry_point hlsl_granite } //Effect: terrain_material material terrain_material { technique { //Rendering Pass: Elephant Body (pass index: #0 ) pass { //DirectX 9.0 HLSL Pixel Shader ps_2_0 fragment_program_ref HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Pixel_Shader { //Shader Constant: Ka param_indexed 3 float4 0.433333 0.433333 0.433333 1.000000 //Shader Constant: Kd param_indexed 0 float4 0.833333 0.833333 0.833333 0.5 //Shader Constant: granite_color param_indexed 1 float4 0.500000 1.000000 1.000000 1.000000 //Shader Constant: light_color param_indexed 2 float4 1.30000 1.000000 1.000000 1.000000 //Shader Constant: light_pos param_indexed 4 float4 5.600000 100.000000 2.600000 1.000000 } //DirectX 9.0 HLSL Vertex Shader vs_1_1 vertex_program_ref HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Vertex_Shader { //Shader Constant: noise_frequency param_indexed 8 float4 1.50000 0.5 0.2 0.2 //Shader Constant: view_matrix param_indexed_auto 4 view_matrix //Shader Constant: view_proj_matrix param_indexed_auto 0 worldviewproj_matrix } //Texture Stage 0 //Noise: "..MediaTexturesNoiseVolume.dds" //State: D3DSAMP_MAGFILTER, Value : D3DTEXF_LINEAR //State: D3DSAMP_MINFILTER, Value : D3DTEXF_LINEAR //State: D3DSAMP_MIPFILTER, Value : D3DTEXF_LINEAR texture_unit { texture NoiseVolume.dds 3d filtering linear linear linear } } } } {CODE} This is the vertex shader source file. I know it has the .cg extension and it is declared as hlsl, but ogre doesn't seem to care. !!HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Vertex_Shader.program.cg {CODE(wrap="1", colors="c++")} float4x4 view_proj_matrix; float noise_frequency; float4x4 view_matrix; struct VS_OUTPUT { float4 Pos : POSITION; float3 P : TEXCOORD0; float3 Peye : TEXCOORD1; float3 Neye : TEXCOORD2; }; VS_OUTPUT main (float4 vPosition: POSITION, float3 vNormal: NORMAL) { VS_OUTPUT Out = (VS_OUTPUT) 0; Out.Pos = mul (view_proj_matrix, vPosition); // Just output model coordinates for this so marble doesn't swim all over Out.P = vPosition * noise_frequency; // Put position and normal in eye space Out.Peye = mul (view_matrix, vPosition); Out.Neye = mul (view_matrix, vNormal); return Out; } {CODE} This is the pixel shader source file. I know it has the .cg extension and it is declared as hlsl, but ogre doesn't seem to care. !!HLSL_Stone_Effects.Stones_Effect_Group.terrain_material.Elephant_Body.Pixel_Shader.program.cg {CODE(wrap="1", colors="c++")} float4 Kd; float4 global_ambient; float4 granite_color; float4 light_color; float4 Ka; float4 light_pos; sampler noise_volume; float4 noise (float3 x) { return tex3D (noise_volume, x); } float4 diffuse(float3 Neye, float3 Peye) { // Compute normalized vector from vertex to light in eye space (Leye) float3 Leye = (light_pos - Peye) / length(light_pos - Peye); return dot(Neye, Leye); // N.L } // // Based on granite.sl on page 354 of The RenderMan Companion // float4 hlsl_granite (float3 P : TEXCOORD0, float3 Peye : TEXCOORD1, float3 Neye : TEXCOORD2) : COLOR { return abs(0.8-noise(P)) * granite_color * light_color * (Ka + Kd * diffuse(normalize(Neye), Peye)); } {CODE} --- Alias: (alias(Shader Model 2 Stone))
Search by Tags
Search Wiki by Freetags
Latest Changes
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
...more
Search
Find
Advanced
Search Help
Online Users
129 online users