Skip to content

Commit

Permalink
Add an example of passing packed struct arrays to WebGL
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Mar 23, 2013
1 parent 3f308d2 commit 3d598e5
Show file tree
Hide file tree
Showing 10 changed files with 913 additions and 0 deletions.
480 changes: 480 additions & 0 deletions Examples/WebGL_Vertex_Structs/Page.cs

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions Examples/WebGL_Vertex_Structs/WebGL_Vertex_Structs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E2DB486A-BB4C-4627-934A-DC1910F5E66E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebGL</RootNamespace>
<AssemblyName>WebGL_Vertex_Structs</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="JSIL.Meta">
<HintPath>..\..\bin\JSIL.Meta.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Page.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="crate.fs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="crate.vs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="crate.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="glMatrix-0.9.5.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="webgl-utils.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Don't edit this build event by hand! The condition ensures that when VS kicks off a JSILc build, JSILc won't then kick off another JSILc build recursively, forever... -->
<PropertyGroup Condition="$(JSIL) != 'building'">
<PostBuildEvent>
del $(SolutionDir)..\..\jsil.org\demos\WebGL_Vertex_Structs\*.js
copy $(SolutionDir)Page.cs $(SolutionDir)..\..\jsil.org\demos\WebGL_Vertex_Structs\Page.cs
$(SolutionDir)..\..\bin\JSILc.exe $(SolutionPath)
</PostBuildEvent>
</PropertyGroup>
</Project>
17 changes: 17 additions & 0 deletions Examples/WebGL_Vertex_Structs/WebGL_Vertex_Structs.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebGL_Vertex_Structs", "WebGL_Vertex_Structs.csproj", "{E2DB486A-BB4C-4627-934A-DC1910F5E66E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2DB486A-BB4C-4627-934A-DC1910F5E66E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2DB486A-BB4C-4627-934A-DC1910F5E66E}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions Examples/WebGL_Vertex_Structs/WebGL_Vertex_Structs.sln.jsilconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"FrameworkVersion": 4.0,
"OutputDirectory": "%configdirectory%/../../jsil.org/demos/WebGL_Vertex_Structs",
"Assemblies": {
"Ignored": [
"System.Dynamic,",
"System.Core,",
"System.Configuration,",
"System.Numerics,",
"Microsoft.CSharp,",
"System.Xml,"
]
}
}
11 changes: 11 additions & 0 deletions Examples/WebGL_Vertex_Structs/crate.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
precision mediump float;

varying vec2 vTextureCoord;
varying vec3 vLightWeighting;

uniform sampler2D uSampler;

void main(void) {
vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
gl_FragColor = vec4(textureColor.rgb * vLightWeighting, textureColor.a);
}
Binary file added Examples/WebGL_Vertex_Structs/crate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Examples/WebGL_Vertex_Structs/crate.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;

uniform vec3 uAmbientColor;

uniform vec3 uLightingDirection;
uniform vec3 uDirectionalColor;

uniform bool uUseLighting;

varying vec2 vTextureCoord;
varying vec3 vLightWeighting;

void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;

if (!uUseLighting) {
vLightWeighting = vec3(1.0, 1.0, 1.0);
} else {
vec3 transformedNormal = uNMatrix * aVertexNormal;
float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
vLightWeighting = uAmbientColor + uDirectionalColor * directionalLightWeighting;
}
}
32 changes: 32 additions & 0 deletions Examples/WebGL_Vertex_Structs/glMatrix-0.9.5.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d598e5

Please sign in to comment.